diff --git a/api/v1alpha1/perconaservermysql_types.go b/api/v1alpha1/perconaservermysql_types.go index f2067eaec..789935921 100644 --- a/api/v1alpha1/perconaservermysql_types.go +++ b/api/v1alpha1/perconaservermysql_types.go @@ -57,6 +57,7 @@ const ( // +kubebuilder:validation:XValidation:rule="!(self.mysql.clusterType == 'group-replication' && has(self.mysql.size) && self.mysql.size >= 9) || self.unsafeFlags.mysqlSize",message="Invalid configuration: For 'group replication', scaling MySQL replicas above 9 requires 'unsafeFlags.mysqlSize: true'" // +kubebuilder:validation:XValidation:rule="!(self.mysql.clusterType == 'group-replication' && has(self.mysql.size) && self.mysql.size % 2 == 0) || self.unsafeFlags.mysqlSize",message="Invalid configuration: For 'group replication', using an even number of MySQL replicas requires 'unsafeFlags.mysqlSize: true'" type PerconaServerMySQLSpec struct { + Metadata *Metadata `json:"metadata,omitempty"` CRVersion string `json:"crVersion,omitempty"` Pause bool `json:"pause,omitempty"` VolumeExpansionEnabled bool `json:"enableVolumeExpansion,omitempty"` @@ -197,6 +198,22 @@ type PodSpec struct { ContainerSpec `json:",inline"` } +type Metadata struct { + // Map of string keys and values that can be used to organize and categorize + // (scope and select) objects. May match selectors of replication controllers + // and services. + // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels + // +optional + Labels map[string]string `json:"labels,omitempty" protobuf:"bytes,11,rep,name=labels"` + + // Annotations is an unstructured key value map stored with a resource that may be + // set by external tools to store and retrieve arbitrary metadata. They are not + // queryable and should be preserved when modifying objects. + // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations + // +optional + Annotations map[string]string `json:"annotations,omitempty" protobuf:"bytes,12,rep,name=annotations"` +} + // GetTerminationGracePeriodSeconds returns the configured termination grace period for the Pod. // If not explicitly set, it returns the default grace period. func (s PodSpec) GetTerminationGracePeriodSeconds() *int64 { @@ -594,6 +611,22 @@ func (cr *PerconaServerMySQL) SetVersion() { cr.Spec.CRVersion = version.Version() } +func (cr *PerconaServerMySQL) GlobalLabels() map[string]string { + if cr.Spec.Metadata == nil { + return nil + } + + return cr.Spec.Metadata.Labels +} + +func (cr *PerconaServerMySQL) GlobalAnnotations() map[string]string { + if cr.Spec.Metadata == nil { + return nil + } + + return cr.Spec.Metadata.Annotations +} + func (cr *PerconaServerMySQL) Version() *v.Version { return v.Must(v.NewVersion(cr.Spec.CRVersion)) } diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 06c7984bd..83752f773 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -334,6 +334,35 @@ func (in *HAProxySpec) DeepCopy() *HAProxySpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Metadata) DeepCopyInto(out *Metadata) { + *out = *in + if in.Labels != nil { + in, out := &in.Labels, &out.Labels + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + 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 Metadata. +func (in *Metadata) DeepCopy() *Metadata { + if in == nil { + return nil + } + out := new(Metadata) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MySQLRouterSpec) DeepCopyInto(out *MySQLRouterSpec) { *out = *in @@ -693,6 +722,11 @@ func (in *PerconaServerMySQLRestoreStatus) DeepCopy() *PerconaServerMySQLRestore // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PerconaServerMySQLSpec) DeepCopyInto(out *PerconaServerMySQLSpec) { *out = *in + if in.Metadata != nil { + in, out := &in.Metadata, &out.Metadata + *out = new(Metadata) + (*in).DeepCopyInto(*out) + } out.Unsafe = in.Unsafe if in.IgnoreAnnotations != nil { in, out := &in.IgnoreAnnotations, &out.IgnoreAnnotations diff --git a/config/crd/bases/ps.percona.com_perconaservermysqls.yaml b/config/crd/bases/ps.percona.com_perconaservermysqls.yaml index 38a71a851..6bf16de55 100644 --- a/config/crd/bases/ps.percona.com_perconaservermysqls.yaml +++ b/config/crd/bases/ps.percona.com_perconaservermysqls.yaml @@ -2338,6 +2338,17 @@ spec: type: array initImage: type: string + metadata: + properties: + annotations: + additionalProperties: + type: string + type: object + labels: + additionalProperties: + type: string + type: object + type: object mysql: properties: affinity: diff --git a/deploy/bundle.yaml b/deploy/bundle.yaml index 817a5cd65..f4f0dc487 100644 --- a/deploy/bundle.yaml +++ b/deploy/bundle.yaml @@ -4261,6 +4261,17 @@ spec: type: array initImage: type: string + metadata: + properties: + annotations: + additionalProperties: + type: string + type: object + labels: + additionalProperties: + type: string + type: object + type: object mysql: properties: affinity: diff --git a/deploy/cr.yaml b/deploy/cr.yaml index 78af79a94..aa7dba6c8 100644 --- a/deploy/cr.yaml +++ b/deploy/cr.yaml @@ -7,6 +7,12 @@ metadata: # - percona.com/delete-ssl # - percona.com/delete-mysql-pvc spec: +# metadata: +# annotations: +# service.beta.kubernetes.io/aws-load-balancer-backend-protocol: tcp +# service.beta.kubernetes.io/aws-load-balancer-type: nlb +# labels: +# rack: rack-22 # unsafeFlags: # mysqlSize: false # orchestrator: false diff --git a/deploy/crd.yaml b/deploy/crd.yaml index 11599fa9c..211d949b1 100644 --- a/deploy/crd.yaml +++ b/deploy/crd.yaml @@ -4261,6 +4261,17 @@ spec: type: array initImage: type: string + metadata: + properties: + annotations: + additionalProperties: + type: string + type: object + labels: + additionalProperties: + type: string + type: object + type: object mysql: properties: affinity: diff --git a/deploy/cw-bundle.yaml b/deploy/cw-bundle.yaml index e8659ef47..45f31a83a 100644 --- a/deploy/cw-bundle.yaml +++ b/deploy/cw-bundle.yaml @@ -4261,6 +4261,17 @@ spec: type: array initImage: type: string + metadata: + properties: + annotations: + additionalProperties: + type: string + type: object + labels: + additionalProperties: + type: string + type: object + type: object mysql: properties: affinity: diff --git a/pkg/binlogserver/binlog_server.go b/pkg/binlogserver/binlog_server.go index 1207a2496..11f314caa 100644 --- a/pkg/binlogserver/binlog_server.go +++ b/pkg/binlogserver/binlog_server.go @@ -39,7 +39,7 @@ func ConfigSecretName(cr *apiv1alpha1.PerconaServerMySQL) string { } func MatchLabels(cr *apiv1alpha1.PerconaServerMySQL) map[string]string { - return util.SSMapMerge( + return util.SSMapMerge(cr.GlobalLabels(), cr.MySQLSpec().Labels, cr.Labels(AppName, naming.ComponentPITR), ) @@ -61,9 +61,10 @@ func StatefulSet(cr *apiv1alpha1.PerconaServerMySQL, initImage, configHash strin Kind: "StatefulSet", }, ObjectMeta: metav1.ObjectMeta{ - Name: Name(cr), - Namespace: cr.Namespace, - Labels: labels, + Name: Name(cr), + Namespace: cr.Namespace, + Labels: labels, + Annotations: cr.GlobalAnnotations(), }, Spec: appsv1.StatefulSetSpec{ Replicas: &spec.Size, @@ -73,7 +74,7 @@ func StatefulSet(cr *apiv1alpha1.PerconaServerMySQL, initImage, configHash strin Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: labels, - Annotations: annotations, + Annotations: util.SSMapMerge(cr.GlobalAnnotations(), annotations), }, Spec: corev1.PodSpec{ InitContainers: []corev1.Container{ diff --git a/pkg/controller/ps/tls.go b/pkg/controller/ps/tls.go index ee8c71948..b029e46eb 100644 --- a/pkg/controller/ps/tls.go +++ b/pkg/controller/ps/tls.go @@ -154,8 +154,10 @@ func (r *PerconaServerMySQLReconciler) ensureSSLByCertManager(ctx context.Contex caCert := &cm.Certificate{ ObjectMeta: metav1.ObjectMeta{ - Name: certName, - Namespace: cr.Namespace, + Name: certName, + Namespace: cr.Namespace, + Labels: cr.GlobalLabels(), + Annotations: cr.GlobalAnnotations(), }, Spec: cm.CertificateSpec{ SecretName: secretName, @@ -190,8 +192,10 @@ func (r *PerconaServerMySQLReconciler) ensureSSLByCertManager(ctx context.Contex kubeCert := &cm.Certificate{ ObjectMeta: metav1.ObjectMeta{ - Name: certName, - Namespace: cr.Namespace, + Name: certName, + Namespace: cr.Namespace, + Labels: cr.GlobalLabels(), + Annotations: cr.GlobalAnnotations(), }, Spec: cm.CertificateSpec{ SecretName: cr.Spec.SSLSecretName, @@ -216,8 +220,10 @@ func (r *PerconaServerMySQLReconciler) ensureIssuer(ctx context.Context, cr *api ) error { isr := &cm.Issuer{ ObjectMeta: metav1.ObjectMeta{ - Name: issuerName, - Namespace: cr.Namespace, + Name: issuerName, + Namespace: cr.Namespace, + Labels: cr.GlobalLabels(), + Annotations: cr.GlobalAnnotations(), }, Spec: cm.IssuerSpec{ IssuerConfig: IssuerConf, diff --git a/pkg/haproxy/haproxy.go b/pkg/haproxy/haproxy.go index 052e522e2..6575f86a9 100644 --- a/pkg/haproxy/haproxy.go +++ b/pkg/haproxy/haproxy.go @@ -47,7 +47,7 @@ func ServiceName(cr *apiv1alpha1.PerconaServerMySQL) string { } func MatchLabels(cr *apiv1alpha1.PerconaServerMySQL) map[string]string { - return util.SSMapMerge(cr.MySQLSpec().Labels, + return util.SSMapMerge(cr.GlobalLabels(), cr.Spec.Proxy.HAProxy.Labels, cr.Labels(AppName, naming.ComponentProxy)) } @@ -112,7 +112,7 @@ func Service(cr *apiv1alpha1.PerconaServerMySQL, secret *corev1.Secret) *corev1. Name: ServiceName(cr), Namespace: cr.Namespace, Labels: labels, - Annotations: expose.Annotations, + Annotations: util.SSMapMerge(cr.GlobalAnnotations(), expose.Annotations), }, Spec: corev1.ServiceSpec{ Type: serviceType, @@ -142,9 +142,10 @@ func StatefulSet(cr *apiv1alpha1.PerconaServerMySQL, initImage, configHash, tlsH Kind: "StatefulSet", }, ObjectMeta: metav1.ObjectMeta{ - Name: Name(cr), - Namespace: cr.Namespace, - Labels: labels, + Name: Name(cr), + Namespace: cr.Namespace, + Labels: labels, + Annotations: cr.GlobalAnnotations(), }, Spec: appsv1.StatefulSetSpec{ Replicas: &cr.Spec.Proxy.HAProxy.Size, @@ -156,7 +157,7 @@ func StatefulSet(cr *apiv1alpha1.PerconaServerMySQL, initImage, configHash, tlsH Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: labels, - Annotations: annotations, + Annotations: util.SSMapMerge(cr.GlobalAnnotations(), annotations), }, Spec: corev1.PodSpec{ NodeSelector: cr.Spec.Proxy.HAProxy.NodeSelector, diff --git a/pkg/k8s/pvc.go b/pkg/k8s/pvc.go index c2035d1c2..b55b43f1e 100644 --- a/pkg/k8s/pvc.go +++ b/pkg/k8s/pvc.go @@ -7,10 +7,12 @@ import ( apiv1alpha1 "github.com/percona/percona-server-mysql-operator/api/v1alpha1" ) -func PVC(name string, spec *apiv1alpha1.VolumeSpec) corev1.PersistentVolumeClaim { +func PVC(cr *apiv1alpha1.PerconaServerMySQL, name string, spec *apiv1alpha1.VolumeSpec) corev1.PersistentVolumeClaim { return corev1.PersistentVolumeClaim{ ObjectMeta: metav1.ObjectMeta{ - Name: name, + Name: name, + Labels: cr.GlobalLabels(), + Annotations: cr.GlobalAnnotations(), }, Spec: corev1.PersistentVolumeClaimSpec{ StorageClassName: spec.PersistentVolumeClaim.StorageClassName, diff --git a/pkg/k8s/pvc_test.go b/pkg/k8s/pvc_test.go index 1c21d3d8b..628fb9106 100644 --- a/pkg/k8s/pvc_test.go +++ b/pkg/k8s/pvc_test.go @@ -3,11 +3,11 @@ package k8s import ( "testing" - apiv1alpha1 "github.com/percona/percona-server-mysql-operator/api/v1alpha1" - "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" + + apiv1alpha1 "github.com/percona/percona-server-mysql-operator/api/v1alpha1" ) func TestPVC(t *testing.T) { @@ -29,7 +29,7 @@ func TestPVC(t *testing.T) { pvcName := "pvc-name" - pvc := PVC(pvcName, spec) + pvc := PVC(new(apiv1alpha1.PerconaServerMySQL), pvcName, spec) assert.Equal(t, pvcName, pvc.Name) assert.NotNil(t, pvc.Spec.StorageClassName) diff --git a/pkg/mysql/mysql.go b/pkg/mysql/mysql.go index 51a5412f7..f676f690d 100644 --- a/pkg/mysql/mysql.go +++ b/pkg/mysql/mysql.go @@ -124,7 +124,7 @@ func PodFQDN(cr *apiv1alpha1.PerconaServerMySQL, pod *corev1.Pod) string { } func MatchLabels(cr *apiv1alpha1.PerconaServerMySQL) map[string]string { - return util.SSMapMerge(cr.MySQLSpec().Labels, + return util.SSMapMerge(cr.GlobalLabels(), cr.MySQLSpec().Labels, cr.Labels(AppName, naming.ComponentDatabase)) } @@ -147,9 +147,10 @@ func StatefulSet(cr *apiv1alpha1.PerconaServerMySQL, initImage, configHash, tlsH Kind: "StatefulSet", }, ObjectMeta: metav1.ObjectMeta{ - Name: Name(cr), - Namespace: cr.Namespace, - Labels: labels, + Name: Name(cr), + Namespace: cr.Namespace, + Labels: labels, + Annotations: cr.GlobalAnnotations(), }, Spec: appsv1.StatefulSetSpec{ Replicas: &replicas, @@ -161,7 +162,7 @@ func StatefulSet(cr *apiv1alpha1.PerconaServerMySQL, initImage, configHash, tlsH Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: labels, - Annotations: annotations, + Annotations: util.SSMapMerge(cr.GlobalAnnotations(), annotations), }, Spec: corev1.PodSpec{ InitContainers: []corev1.Container{ @@ -198,7 +199,7 @@ func StatefulSet(cr *apiv1alpha1.PerconaServerMySQL, initImage, configHash, tlsH } if cr.Spec.MySQL.VolumeSpec.PersistentVolumeClaim != nil { - sts.Spec.VolumeClaimTemplates = append(sts.Spec.VolumeClaimTemplates, volumeClaimTemplates(spec)...) + sts.Spec.VolumeClaimTemplates = append(sts.Spec.VolumeClaimTemplates, volumeClaimTemplates(cr, spec)...) return sts } @@ -344,14 +345,14 @@ func updateStrategy(cr *apiv1alpha1.PerconaServerMySQL) appsv1.StatefulSetUpdate } } -func volumeClaimTemplates(spec *apiv1alpha1.MySQLSpec) []corev1.PersistentVolumeClaim { +func volumeClaimTemplates(cr *apiv1alpha1.PerconaServerMySQL, spec *apiv1alpha1.MySQLSpec) []corev1.PersistentVolumeClaim { var pvcs []corev1.PersistentVolumeClaim if spec.VolumeSpec.PersistentVolumeClaim == nil { return pvcs } - pvcs = append(pvcs, k8s.PVC(DataVolumeName, spec.VolumeSpec)) + pvcs = append(pvcs, k8s.PVC(cr, DataVolumeName, spec.VolumeSpec)) for _, p := range spec.SidecarPVCs { pvcs = append(pvcs, corev1.PersistentVolumeClaim{ @@ -422,9 +423,10 @@ func UnreadyService(cr *apiv1alpha1.PerconaServerMySQL) *corev1.Service { Kind: "Service", }, ObjectMeta: metav1.ObjectMeta{ - Name: UnreadyServiceName(cr), - Namespace: cr.Namespace, - Labels: labels, + Name: UnreadyServiceName(cr), + Namespace: cr.Namespace, + Labels: labels, + Annotations: cr.GlobalAnnotations(), }, Spec: corev1.ServiceSpec{ ClusterIP: "None", @@ -443,9 +445,10 @@ func HeadlessService(cr *apiv1alpha1.PerconaServerMySQL) *corev1.Service { Kind: "Service", }, ObjectMeta: metav1.ObjectMeta{ - Name: ServiceName(cr), - Namespace: cr.Namespace, - Labels: labels, + Name: ServiceName(cr), + Namespace: cr.Namespace, + Labels: labels, + Annotations: cr.GlobalAnnotations(), }, Spec: corev1.ServiceSpec{ Type: corev1.ServiceTypeClusterIP, @@ -465,9 +468,10 @@ func ProxyService(cr *apiv1alpha1.PerconaServerMySQL) *corev1.Service { Kind: "Service", }, ObjectMeta: metav1.ObjectMeta{ - Name: ProxyServiceName(cr), - Namespace: cr.Namespace, - Labels: labels, + Name: ProxyServiceName(cr), + Namespace: cr.Namespace, + Labels: labels, + Annotations: cr.GlobalAnnotations(), }, Spec: corev1.ServiceSpec{ Type: corev1.ServiceTypeClusterIP, @@ -509,7 +513,7 @@ func PodService(cr *apiv1alpha1.PerconaServerMySQL, t corev1.ServiceType, podNam Name: podName, Namespace: cr.Namespace, Labels: labels, - Annotations: expose.Annotations, + Annotations: util.SSMapMerge(cr.GlobalAnnotations(), expose.Annotations), }, Spec: corev1.ServiceSpec{ Type: t, @@ -553,7 +557,7 @@ func PrimaryService(cr *apiv1alpha1.PerconaServerMySQL) *corev1.Service { Name: PrimaryServiceName(cr), Namespace: cr.Namespace, Labels: labels, - Annotations: expose.Annotations, + Annotations: util.SSMapMerge(cr.GlobalAnnotations(), expose.Annotations), }, Spec: corev1.ServiceSpec{ Type: expose.Type, diff --git a/pkg/orchestrator/orchestrator.go b/pkg/orchestrator/orchestrator.go index 9b0f81ef3..b692fc2b0 100644 --- a/pkg/orchestrator/orchestrator.go +++ b/pkg/orchestrator/orchestrator.go @@ -103,7 +103,7 @@ func Labels(cr *apiv1alpha1.PerconaServerMySQL) map[string]string { } func MatchLabels(cr *apiv1alpha1.PerconaServerMySQL) map[string]string { - return util.SSMapMerge(Labels(cr), + return util.SSMapMerge(cr.GlobalLabels(), Labels(cr), cr.Labels(AppName, naming.ComponentOrchestrator)) } @@ -123,9 +123,10 @@ func StatefulSet(cr *apiv1alpha1.PerconaServerMySQL, initImage, tlsHash string) Kind: "StatefulSet", }, ObjectMeta: metav1.ObjectMeta{ - Name: Name(cr), - Namespace: cr.Namespace, - Labels: labels, + Name: Name(cr), + Namespace: cr.Namespace, + Labels: labels, + Annotations: cr.GlobalAnnotations(), }, Spec: appsv1.StatefulSetSpec{ Replicas: &Replicas, @@ -137,7 +138,7 @@ func StatefulSet(cr *apiv1alpha1.PerconaServerMySQL, initImage, tlsHash string) Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: labels, - Annotations: annotations, + Annotations: util.SSMapMerge(cr.GlobalAnnotations(), annotations), }, Spec: corev1.PodSpec{ InitContainers: []corev1.Container{ @@ -375,9 +376,10 @@ func Service(cr *apiv1alpha1.PerconaServerMySQL) *corev1.Service { Kind: "Service", }, ObjectMeta: metav1.ObjectMeta{ - Name: ServiceName(cr), - Namespace: cr.Namespace, - Labels: MatchLabels(cr), + Name: ServiceName(cr), + Namespace: cr.Namespace, + Labels: MatchLabels(cr), + Annotations: cr.GlobalAnnotations(), }, Spec: corev1.ServiceSpec{ ClusterIP: "None", @@ -427,7 +429,7 @@ func PodService(cr *apiv1alpha1.PerconaServerMySQL, t corev1.ServiceType, podNam Name: podName, Namespace: cr.Namespace, Labels: labels, - Annotations: expose.Annotations, + Annotations: util.SSMapMerge(cr.GlobalAnnotations(), expose.Annotations), }, Spec: corev1.ServiceSpec{ Type: t, @@ -456,8 +458,10 @@ func ConfigMap(cr *apiv1alpha1.PerconaServerMySQL, data map[string]string) *core Kind: "ConfigMap", }, ObjectMeta: metav1.ObjectMeta{ - Name: ConfigMapName(cr), - Namespace: cr.Namespace, + Name: ConfigMapName(cr), + Namespace: cr.Namespace, + Labels: cr.GlobalLabels(), + Annotations: cr.GlobalAnnotations(), }, Data: data, } @@ -500,8 +504,10 @@ func ConfigMapData(cr *apiv1alpha1.PerconaServerMySQL) (map[string]string, error func RBAC(cr *apiv1alpha1.PerconaServerMySQL) (*rbacv1.Role, *rbacv1.RoleBinding, *corev1.ServiceAccount) { meta := metav1.ObjectMeta{ - Namespace: cr.Namespace, - Name: "percona-server-mysql-operator-orchestrator", + Namespace: cr.Namespace, + Name: "percona-server-mysql-operator-orchestrator", + Labels: cr.GlobalLabels(), + Annotations: cr.GlobalAnnotations(), } account := &corev1.ServiceAccount{ObjectMeta: meta} diff --git a/pkg/router/router.go b/pkg/router/router.go index 46c038872..5a9f7e8e8 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -51,7 +51,7 @@ func ServiceName(cr *apiv1alpha1.PerconaServerMySQL) string { } func MatchLabels(cr *apiv1alpha1.PerconaServerMySQL) map[string]string { - return util.SSMapMerge(cr.MySQLSpec().Labels, + return util.SSMapMerge(cr.GlobalLabels(), cr.MySQLSpec().Labels, cr.Labels(AppName, naming.ComponentProxy)) } @@ -79,7 +79,7 @@ func Service(cr *apiv1alpha1.PerconaServerMySQL) *corev1.Service { Name: ServiceName(cr), Namespace: cr.Namespace, Labels: labels, - Annotations: expose.Annotations, + Annotations: util.SSMapMerge(cr.GlobalAnnotations(), expose.Annotations), }, Spec: corev1.ServiceSpec{ Type: expose.Type, @@ -114,9 +114,10 @@ func Deployment(cr *apiv1alpha1.PerconaServerMySQL, initImage, configHash, tlsHa Kind: "Deployment", }, ObjectMeta: metav1.ObjectMeta{ - Name: Name(cr), - Namespace: cr.Namespace, - Labels: labels, + Name: Name(cr), + Namespace: cr.Namespace, + Labels: labels, + Annotations: cr.GlobalAnnotations(), }, Spec: appsv1.DeploymentSpec{ Replicas: &replicas, @@ -132,7 +133,7 @@ func Deployment(cr *apiv1alpha1.PerconaServerMySQL, initImage, configHash, tlsHa Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: labels, - Annotations: annotations, + Annotations: util.SSMapMerge(cr.GlobalAnnotations(), annotations), }, Spec: corev1.PodSpec{ InitContainers: []corev1.Container{ diff --git a/pkg/secret/secret.go b/pkg/secret/secret.go index 684be0144..42d227e54 100644 --- a/pkg/secret/secret.go +++ b/pkg/secret/secret.go @@ -14,6 +14,7 @@ import ( apiv1alpha1 "github.com/percona/percona-server-mysql-operator/api/v1alpha1" "github.com/percona/percona-server-mysql-operator/pkg/naming" "github.com/percona/percona-server-mysql-operator/pkg/tls" + "github.com/percona/percona-server-mysql-operator/pkg/util" ) func GenerateCertsSecret(ctx context.Context, cr *apiv1alpha1.PerconaServerMySQL) (*corev1.Secret, error) { @@ -24,9 +25,10 @@ func GenerateCertsSecret(ctx context.Context, cr *apiv1alpha1.PerconaServerMySQL secret := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ - Name: cr.Spec.SSLSecretName, - Namespace: cr.Namespace, - Labels: cr.Labels("certificate", naming.ComponentTLS), + Name: cr.Spec.SSLSecretName, + Namespace: cr.Namespace, + Labels: util.SSMapMerge(cr.GlobalLabels(), cr.Labels("certificate", naming.ComponentTLS)), + Annotations: cr.GlobalAnnotations(), }, Data: map[string][]byte{ "ca.crt": ca,