From 2baabe27307e37c5b01027f07252f233ed5389ff Mon Sep 17 00:00:00 2001 From: Suleyman Akbas Date: Thu, 7 Dec 2023 17:48:41 +0100 Subject: [PATCH] fix: apply workload annotations to pod specs Signed-off-by: Suleyman Akbas --- .../lvms-operator.clusterserviceversion.yaml | 1 - config/default/manager_auth_proxy_patch.yaml | 2 -- config/default/manager_config_patch.yaml | 2 -- config/default/manager_custom_env.yaml.in | 2 -- config/default/manager_webhook_patch.yaml | 2 -- config/manager/manager.yaml | 2 -- .../bases/clusterserviceversion.yaml.in | 1 - .../lvms-operator.clusterserviceversion.yaml | 1 - controllers/topolvm_controller.go | 19 ++++++++++++------- controllers/topolvm_node.go | 17 +++++++++++------ controllers/vgmanager.go | 5 +++++ controllers/vgmanager_daemonset.go | 10 +++++----- 12 files changed, 33 insertions(+), 31 deletions(-) diff --git a/bundle/manifests/lvms-operator.clusterserviceversion.yaml b/bundle/manifests/lvms-operator.clusterserviceversion.yaml index f7869de46..8449da512 100644 --- a/bundle/manifests/lvms-operator.clusterserviceversion.yaml +++ b/bundle/manifests/lvms-operator.clusterserviceversion.yaml @@ -65,7 +65,6 @@ metadata: "lvmvolumegroups.lvm.topolvm.io", "lvmvolumegroupnodestatuses.lvm.topolvm.io"]' operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 repository: https://github.com/openshift/lvm-operator - target.workload.openshift.io/management: '{"effect": "PreferredDuringScheduling"}' labels: operatorframework.io/arch.amd64: supported operatorframework.io/arch.arm64: supported diff --git a/config/default/manager_auth_proxy_patch.yaml b/config/default/manager_auth_proxy_patch.yaml index ff3fd11be..e9de6a588 100644 --- a/config/default/manager_auth_proxy_patch.yaml +++ b/config/default/manager_auth_proxy_patch.yaml @@ -5,8 +5,6 @@ kind: Deployment metadata: name: operator namespace: system - annotations: - target.workload.openshift.io/management: '{"effect": "PreferredDuringScheduling"}' spec: template: spec: diff --git a/config/default/manager_config_patch.yaml b/config/default/manager_config_patch.yaml index df18837ec..6c400155c 100644 --- a/config/default/manager_config_patch.yaml +++ b/config/default/manager_config_patch.yaml @@ -3,8 +3,6 @@ kind: Deployment metadata: name: controller-manager namespace: system - annotations: - target.workload.openshift.io/management: '{"effect": "PreferredDuringScheduling"}' spec: template: spec: diff --git a/config/default/manager_custom_env.yaml.in b/config/default/manager_custom_env.yaml.in index 4a016bc5f..69ada8551 100644 --- a/config/default/manager_custom_env.yaml.in +++ b/config/default/manager_custom_env.yaml.in @@ -3,8 +3,6 @@ kind: Deployment metadata: name: operator namespace: system - annotations: - target.workload.openshift.io/management: '{"effect": "PreferredDuringScheduling"}' spec: template: spec: diff --git a/config/default/manager_webhook_patch.yaml b/config/default/manager_webhook_patch.yaml index e965ad71a..9d7eb3fb9 100644 --- a/config/default/manager_webhook_patch.yaml +++ b/config/default/manager_webhook_patch.yaml @@ -3,8 +3,6 @@ kind: Deployment metadata: name: operator namespace: system - annotations: - target.workload.openshift.io/management: '{"effect": "PreferredDuringScheduling"}' spec: template: spec: diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 13360dc51..2ff5f01b7 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -17,8 +17,6 @@ kind: Deployment metadata: name: operator namespace: system - annotations: - target.workload.openshift.io/management: '{"effect": "PreferredDuringScheduling"}' labels: app.kubernetes.io/name: lvms-operator spec: diff --git a/config/manifests/bases/clusterserviceversion.yaml.in b/config/manifests/bases/clusterserviceversion.yaml.in index 22d366ee4..d7fa1710b 100644 --- a/config/manifests/bases/clusterserviceversion.yaml.in +++ b/config/manifests/bases/clusterserviceversion.yaml.in @@ -35,7 +35,6 @@ metadata: operators.openshift.io/infrastructure-features: '["disconnected"]' operators.openshift.io/valid-subscription: '["OpenShift Container Platform", "OpenShift Platform Plus"]' operators.operatorframework.io/internal-objects: '["logicalvolumes.topolvm.io", "lvmvolumegroups.lvm.topolvm.io", "lvmvolumegroupnodestatuses.lvm.topolvm.io"]' - target.workload.openshift.io/management: '{"effect": "PreferredDuringScheduling"}' labels: operatorframework.io/arch.amd64: supported operatorframework.io/arch.arm64: supported diff --git a/config/manifests/bases/lvms-operator.clusterserviceversion.yaml b/config/manifests/bases/lvms-operator.clusterserviceversion.yaml index 6d885dec2..fb2d0c881 100644 --- a/config/manifests/bases/lvms-operator.clusterserviceversion.yaml +++ b/config/manifests/bases/lvms-operator.clusterserviceversion.yaml @@ -35,7 +35,6 @@ metadata: operators.openshift.io/infrastructure-features: '["disconnected"]' operators.openshift.io/valid-subscription: '["OpenShift Container Platform", "OpenShift Platform Plus"]' operators.operatorframework.io/internal-objects: '["logicalvolumes.topolvm.io", "lvmvolumegroups.lvm.topolvm.io", "lvmvolumegroupnodestatuses.lvm.topolvm.io"]' - target.workload.openshift.io/management: '{"effect": "PreferredDuringScheduling"}' labels: operatorframework.io/arch.amd64: supported operatorframework.io/arch.arm64: supported diff --git a/controllers/topolvm_controller.go b/controllers/topolvm_controller.go index 4910b6e28..25e9324f1 100644 --- a/controllers/topolvm_controller.go +++ b/controllers/topolvm_controller.go @@ -124,6 +124,11 @@ func (c topolvmController) setTopolvmControllerDesiredState(existing, desired *a existing.ObjectMeta.Annotations[key] = value } + initMapIfNil(&existing.Spec.Template.Annotations) + for key, value := range desired.Spec.Template.Annotations { + existing.Spec.Template.Annotations[key] = value + } + return nil } @@ -162,10 +167,9 @@ func getControllerDeployment(lvmCluster *lvmv1alpha1.LVMCluster, namespace strin controllerDeployment := &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ - Name: TopolvmControllerDeploymentName, - Namespace: namespace, - Annotations: annotations, - Labels: labels, + Name: TopolvmControllerDeploymentName, + Namespace: namespace, + Labels: labels, }, Spec: appsv1.DeploymentSpec{ Replicas: &replicas, @@ -174,9 +178,10 @@ func getControllerDeployment(lvmCluster *lvmv1alpha1.LVMCluster, namespace strin }, Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ - Name: TopolvmControllerDeploymentName, - Namespace: namespace, - Labels: labels, + Name: TopolvmControllerDeploymentName, + Namespace: namespace, + Annotations: annotations, + Labels: labels, }, Spec: corev1.PodSpec{ InitContainers: initContainers, diff --git a/controllers/topolvm_node.go b/controllers/topolvm_node.go index 8bdbc6beb..d48dca2e3 100644 --- a/controllers/topolvm_node.go +++ b/controllers/topolvm_node.go @@ -87,6 +87,11 @@ func (n topolvmNode) ensureCreated(r *LVMClusterReconciler, ctx context.Context, ds.ObjectMeta.Annotations[key] = value } + initMapIfNil(&ds.Spec.Template.Annotations) + for key, value := range dsTemplate.Spec.Template.Annotations { + ds.Spec.Template.Annotations[key] = value + } + return nil }) @@ -194,10 +199,9 @@ func getNodeDaemonSet(lvmCluster *lvmv1alpha1.LVMCluster, namespace string, init } nodeDaemonSet := &appsv1.DaemonSet{ ObjectMeta: metav1.ObjectMeta{ - Name: TopolvmNodeDaemonsetName, - Namespace: namespace, - Annotations: annotations, - Labels: labels, + Name: TopolvmNodeDaemonsetName, + Namespace: namespace, + Labels: labels, }, Spec: appsv1.DaemonSetSpec{ Selector: &metav1.LabelSelector{MatchLabels: labels}, @@ -206,8 +210,9 @@ func getNodeDaemonSet(lvmCluster *lvmv1alpha1.LVMCluster, namespace string, init }, Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ - Name: lvmCluster.Name, - Labels: labels, + Name: lvmCluster.Name, + Annotations: annotations, + Labels: labels, }, Spec: corev1.PodSpec{ ServiceAccountName: TopolvmNodeServiceAccount, diff --git a/controllers/vgmanager.go b/controllers/vgmanager.go index 35ec59f59..4fca44f65 100644 --- a/controllers/vgmanager.go +++ b/controllers/vgmanager.go @@ -82,6 +82,11 @@ func (v vgManager) ensureCreated(r *LVMClusterReconciler, ctx context.Context, l ds.ObjectMeta.Annotations[key] = value } + initMapIfNil(&ds.Spec.Template.Annotations) + for key, value := range dsTemplate.Spec.Template.Annotations { + ds.Spec.Template.Annotations[key] = value + } + // containers ds.Spec.Template.Spec.Containers = dsTemplate.Spec.Template.Spec.Containers diff --git a/controllers/vgmanager_daemonset.go b/controllers/vgmanager_daemonset.go index d087ed018..f9c3f5208 100644 --- a/controllers/vgmanager_daemonset.go +++ b/controllers/vgmanager_daemonset.go @@ -190,16 +190,16 @@ func newVGManagerDaemonset(lvmCluster *lvmv1alpha1.LVMCluster, namespace string, } ds := appsv1.DaemonSet{ ObjectMeta: metav1.ObjectMeta{ - Name: VGManagerUnit, - Namespace: namespace, - Annotations: annotations, - Labels: labels, + Name: VGManagerUnit, + Namespace: namespace, + Labels: labels, }, Spec: appsv1.DaemonSetSpec{ Selector: &metav1.LabelSelector{MatchLabels: labels}, Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ - Labels: labels, + Annotations: annotations, + Labels: labels, }, Spec: corev1.PodSpec{