From 3731e7096c68a6f53d5354782ea01f8837da2c37 Mon Sep 17 00:00:00 2001 From: njhale Date: Tue, 27 Nov 2018 10:42:31 -0500 Subject: [PATCH] fix(annotations): merge CSV and pod template annotations instead of replacing --- pkg/controller/install/deployment.go | 12 +++++++++++- pkg/controller/install/deployment_test.go | 23 ++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/pkg/controller/install/deployment.go b/pkg/controller/install/deployment.go index ae67b8cf4b0..072533ce505 100644 --- a/pkg/controller/install/deployment.go +++ b/pkg/controller/install/deployment.go @@ -63,7 +63,17 @@ func (i *StrategyDeploymentInstaller) installDeployments(deps []StrategyDeployme dep := &appsv1.Deployment{Spec: d.Spec} dep.SetName(d.Name) dep.SetNamespace(i.owner.GetNamespace()) - dep.Spec.Template.SetAnnotations(i.templateAnnotations) + + // Merge annotations (to avoid losing info from pod template) + annotations := map[string]string{} + for k, v := range i.templateAnnotations { + annotations[k] = v + } + for k, v := range dep.Spec.Template.GetAnnotations() { + annotations[k] = v + } + dep.Spec.Template.SetAnnotations(annotations) + ownerutil.AddNonBlockingOwner(dep, i.owner) if dep.Labels == nil { dep.SetLabels(map[string]string{}) diff --git a/pkg/controller/install/deployment_test.go b/pkg/controller/install/deployment_test.go index 9e777153f9c..597eade90c3 100644 --- a/pkg/controller/install/deployment_test.go +++ b/pkg/controller/install/deployment_test.go @@ -171,6 +171,13 @@ func TestInstallStrategyDeploymentInstallDeployments(t *testing.T) { "olm.owner.namespace": mockOwner.GetNamespace(), }, }, + Spec: appsv1.DeploymentSpec{ + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{}, + }, + }, + }, }, returnError: nil, }, @@ -185,6 +192,13 @@ func TestInstallStrategyDeploymentInstallDeployments(t *testing.T) { "olm.owner.namespace": mockOwner.GetNamespace(), }, }, + Spec: appsv1.DeploymentSpec{ + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{}, + }, + }, + }, }, returnError: nil, }, @@ -199,6 +213,13 @@ func TestInstallStrategyDeploymentInstallDeployments(t *testing.T) { "olm.owner.namespace": mockOwner.GetNamespace(), }, }, + Spec: appsv1.DeploymentSpec{ + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{}, + }, + }, + }, }, returnError: nil, }, @@ -215,7 +236,7 @@ func TestInstallStrategyDeploymentInstallDeployments(t *testing.T) { fakeClient.CreateDeploymentReturns(nil, m.returnError) defer func(i int, expectedDeployment appsv1.Deployment) { dep := fakeClient.CreateOrUpdateDeploymentArgsForCall(i) - require.Equal(t, expectedDeployment, *dep) + assert.Equal(t, expectedDeployment, *dep) }(i, m.expectedDeployment) }