This is an automated email from the ASF dual-hosted git repository. roryqi pushed a commit to branch support-annotations in repository https://gitbox.apache.org/repos/asf/incubator-uniffle.git
commit 86268b5eb5dcb37ed69d4978cd5d7a0722e050c9 Author: Rory <[email protected]> AuthorDate: Fri Jun 21 10:27:05 2024 +0800 [#289] feat(operator): support annotations --- .../uniffle/v1alpha1/remoteshuffleservice_types.go | 5 +++++ .../api/uniffle/v1alpha1/zz_generated.deepcopy.go | 7 ++++++ .../uniffle.apache.org_remoteshuffleservices.yaml | 14 ++++++++++++ .../pkg/controller/sync/coordinator/coordinator.go | 7 ++++++ .../controller/sync/shuffleserver/shuffleserver.go | 25 +++++++++++++++------- 5 files changed, 50 insertions(+), 8 deletions(-) diff --git a/deploy/kubernetes/operator/api/uniffle/v1alpha1/remoteshuffleservice_types.go b/deploy/kubernetes/operator/api/uniffle/v1alpha1/remoteshuffleservice_types.go index 978695343..2903f0932 100644 --- a/deploy/kubernetes/operator/api/uniffle/v1alpha1/remoteshuffleservice_types.go +++ b/deploy/kubernetes/operator/api/uniffle/v1alpha1/remoteshuffleservice_types.go @@ -309,6 +309,11 @@ type RSSPodSpec struct { // Affinity is a group of affinity scheduling rules. // +optional Affinity *corev1.Affinity `json:"affinity,omitempty"` + + // Annotations is an unstructured key value map stored with a resource that may be + // set by external tools to store and retrieve arbitrary metadata. + // +optional + Annotations map[string]string `json:"annotations,omitempty"` } // MainContainer stores information of the main container of coordinators or shuffle servers, diff --git a/deploy/kubernetes/operator/api/uniffle/v1alpha1/zz_generated.deepcopy.go b/deploy/kubernetes/operator/api/uniffle/v1alpha1/zz_generated.deepcopy.go index 0c7389f29..c9e15d7a5 100644 --- a/deploy/kubernetes/operator/api/uniffle/v1alpha1/zz_generated.deepcopy.go +++ b/deploy/kubernetes/operator/api/uniffle/v1alpha1/zz_generated.deepcopy.go @@ -274,6 +274,13 @@ func (in *RSSPodSpec) DeepCopyInto(out *RSSPodSpec) { *out = new(v1.Affinity) (*in).DeepCopyInto(*out) } + if in.Annotations != nil { + in, out := &in.Annotations, &out.Annotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RSSPodSpec. diff --git a/deploy/kubernetes/operator/config/crd/bases/uniffle.apache.org_remoteshuffleservices.yaml b/deploy/kubernetes/operator/config/crd/bases/uniffle.apache.org_remoteshuffleservices.yaml index 9dca5b422..46e3e23b8 100644 --- a/deploy/kubernetes/operator/config/crd/bases/uniffle.apache.org_remoteshuffleservices.yaml +++ b/deploy/kubernetes/operator/config/crd/bases/uniffle.apache.org_remoteshuffleservices.yaml @@ -937,6 +937,13 @@ spec: type: array type: object type: object + annotations: + additionalProperties: + type: string + description: Annotations is an unstructured key value map stored + with a resource that may be set by external tools to store and + retrieve arbitrary metadata. + type: object args: description: Args represents args used by coordinators or shuffle servers. @@ -5899,6 +5906,13 @@ spec: type: array type: object type: object + annotations: + additionalProperties: + type: string + description: Annotations is an unstructured key value map stored + with a resource that may be set by external tools to store and + retrieve arbitrary metadata. + type: object args: description: Args represents args used by coordinators or shuffle servers. diff --git a/deploy/kubernetes/operator/pkg/controller/sync/coordinator/coordinator.go b/deploy/kubernetes/operator/pkg/controller/sync/coordinator/coordinator.go index dad46ed5a..f1b62b8b4 100644 --- a/deploy/kubernetes/operator/pkg/controller/sync/coordinator/coordinator.go +++ b/deploy/kubernetes/operator/pkg/controller/sync/coordinator/coordinator.go @@ -235,6 +235,13 @@ func GenerateDeploy(rss *unifflev1alpha1.RemoteShuffleService, index int) *appsv deploy.Spec.Template.Spec.RuntimeClassName = rss.Spec.Coordinator.RuntimeClassName } + // add custom annotations + annotations := map[string]string{} + for key, value := range rss.Spec.ShuffleServer.Annotations { + annotations[key] = value + } + deploy.Spec.Template.Annotations = annotations + // add init containers, the main container and other containers. deploy.Spec.Template.Spec.InitContainers = util.GenerateInitContainers(rss.Spec.Coordinator.RSSPodSpec) containers := []corev1.Container{*generateMainContainer(rss)} diff --git a/deploy/kubernetes/operator/pkg/controller/sync/shuffleserver/shuffleserver.go b/deploy/kubernetes/operator/pkg/controller/sync/shuffleserver/shuffleserver.go index 867a40386..9c4f14f70 100644 --- a/deploy/kubernetes/operator/pkg/controller/sync/shuffleserver/shuffleserver.go +++ b/deploy/kubernetes/operator/pkg/controller/sync/shuffleserver/shuffleserver.go @@ -173,14 +173,6 @@ func GenerateSts(kubeClient kubernetes.Interface, rss *unifflev1alpha1.RemoteShu Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: make(map[string]string), - Annotations: map[string]string{ - constants.AnnotationRssName: rss.Name, - constants.AnnotationRssUID: string(rss.UID), - constants.AnnotationMetricsServerPort: fmt.Sprintf("%v", - *rss.Spec.ShuffleServer.HTTPPort), - constants.AnnotationShuffleServerPort: fmt.Sprintf("%v", - *rss.Spec.ShuffleServer.RPCPort), - }, }, Spec: podSpec, }, @@ -209,6 +201,23 @@ func GenerateSts(kubeClient kubernetes.Interface, rss *unifflev1alpha1.RemoteShu }) } + // add custom annotation, and default annotation used by rss + annotations := map[string]string{ + constants.AnnotationRssName: rss.Name, + constants.AnnotationRssUID: string(rss.UID), + constants.AnnotationMetricsServerPort: fmt.Sprintf("%v", + *rss.Spec.ShuffleServer.HTTPPort), + constants.AnnotationShuffleServerPort: fmt.Sprintf("%v", + *rss.Spec.ShuffleServer.RPCPort), + } + + for key, value := range rss.Spec.ShuffleServer.Annotations { + if key != constants.AnnotationRssName && key != constants.AnnotationRssUID && key != constants.AnnotationMetricsServerPort && key != constants.AnnotationShuffleServerPort { + annotations[key] = value + } + } + sts.Spec.Template.Annotations = annotations + // add init containers, the main container and other containers. sts.Spec.Template.Spec.InitContainers = util.GenerateInitContainers(rss.Spec.ShuffleServer.RSSPodSpec) containers := []corev1.Container{*generateMainContainer(rss)}
