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 ac86f27f4e5fb6fe50019577ed9fc7c93f5d4b4a 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 | 24 ++++++++++++++-------- 5 files changed, 49 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 cd53c2a12..524fc6f95 100644 --- a/deploy/kubernetes/operator/api/uniffle/v1alpha1/remoteshuffleservice_types.go +++ b/deploy/kubernetes/operator/api/uniffle/v1alpha1/remoteshuffleservice_types.go @@ -286,6 +286,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 8d4d40def..cdfdf415c 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 314304cd5..7a52b249d 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 a96c0eba0..a08652639 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, }, @@ -198,6 +190,22 @@ func GenerateSts(kubeClient kubernetes.Interface, rss *unifflev1alpha1.RemoteShu sts.Spec.Template.Spec.RuntimeClassName = rss.Spec.ShuffleServer.RuntimeClassName } + // 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 + } + } + // 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)}
