diff --git a/charts/karmada-operator/crds/operator.karmada.io_karmadas.yaml b/charts/karmada-operator/crds/operator.karmada.io_karmadas.yaml index 74ef3a965..2b14c43b4 100644 --- a/charts/karmada-operator/crds/operator.karmada.io_karmadas.yaml +++ b/charts/karmada-operator/crds/operator.karmada.io_karmadas.yaml @@ -642,6 +642,12 @@ spec: Requests cannot exceed Limits. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' type: object type: object + serviceAnnotations: + additionalProperties: + type: string + description: 'ServiceAnnotations is an extra set of annotations + for service of karmada apiserver. more info: https://github.com/karmada-io/karmada/issues/4634' + type: object serviceSubnet: description: ServiceSubnet is the subnet used by k8s services. Defaults to "10.96.0.0/12". diff --git a/operator/config/crds/operator.karmada.io_karmadas.yaml b/operator/config/crds/operator.karmada.io_karmadas.yaml index 74ef3a965..2b14c43b4 100644 --- a/operator/config/crds/operator.karmada.io_karmadas.yaml +++ b/operator/config/crds/operator.karmada.io_karmadas.yaml @@ -642,6 +642,12 @@ spec: Requests cannot exceed Limits. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' type: object type: object + serviceAnnotations: + additionalProperties: + type: string + description: 'ServiceAnnotations is an extra set of annotations + for service of karmada apiserver. more info: https://github.com/karmada-io/karmada/issues/4634' + type: object serviceSubnet: description: ServiceSubnet is the subnet used by k8s services. Defaults to "10.96.0.0/12". diff --git a/operator/pkg/apis/operator/v1alpha1/type.go b/operator/pkg/apis/operator/v1alpha1/type.go index 3e66a8e4b..9155fce5f 100644 --- a/operator/pkg/apis/operator/v1alpha1/type.go +++ b/operator/pkg/apis/operator/v1alpha1/type.go @@ -228,6 +228,11 @@ type KarmadaAPIServer struct { // +optional ServiceType corev1.ServiceType `json:"serviceType,omitempty"` + // ServiceAnnotations is an extra set of annotations for service of karmada apiserver. + // more info: https://github.com/karmada-io/karmada/issues/4634 + // +optional + ServiceAnnotations map[string]string `json:"serviceAnnotations,omitempty"` + // ExtraArgs is an extra set of flags to pass to the kube-apiserver component or // override. A key in this map is the flag name as it appears on the command line except // without leading dash(es). diff --git a/operator/pkg/apis/operator/v1alpha1/zz_generated.deepcopy.go b/operator/pkg/apis/operator/v1alpha1/zz_generated.deepcopy.go index 45bca101e..7e0139e61 100644 --- a/operator/pkg/apis/operator/v1alpha1/zz_generated.deepcopy.go +++ b/operator/pkg/apis/operator/v1alpha1/zz_generated.deepcopy.go @@ -221,6 +221,13 @@ func (in *KarmadaAPIServer) DeepCopyInto(out *KarmadaAPIServer) { *out = new(string) **out = **in } + if in.ServiceAnnotations != nil { + in, out := &in.ServiceAnnotations, &out.ServiceAnnotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } if in.ExtraArgs != nil { in, out := &in.ExtraArgs, &out.ExtraArgs *out = make(map[string]string, len(*in)) diff --git a/operator/pkg/controlplane/apiserver/apiserver.go b/operator/pkg/controlplane/apiserver/apiserver.go index 7610b8cb3..b3c2bfb26 100644 --- a/operator/pkg/controlplane/apiserver/apiserver.go +++ b/operator/pkg/controlplane/apiserver/apiserver.go @@ -21,6 +21,7 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/labels" kuberuntime "k8s.io/apimachinery/pkg/runtime" clientset "k8s.io/client-go/kubernetes" clientsetscheme "k8s.io/client-go/kubernetes/scheme" @@ -100,6 +101,9 @@ func createKarmadaAPIServerService(client clientset.Interface, cfg *operatorv1al return fmt.Errorf("error when decoding karmadaApiserver serive: %w", err) } + // merge annotaions with configuration of karmada apiserver. + karmadaApiserverService.Annotations = labels.Merge(karmadaApiserverService.Annotations, cfg.ServiceAnnotations) + if err := apiclient.CreateOrUpdateService(client, karmadaApiserverService); err != nil { return fmt.Errorf("err when creating service for %s, err: %w", karmadaApiserverService.Name, err) }