Skip to content

Commit 659bac3

Browse files
Merge pull request #90 from awgreene/bz-1950047
Bug 1950047: Fix Template Annotations on Webhooks/API Service CSVs
2 parents 59934e5 + d19ffb3 commit 659bac3

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

staging/operator-lifecycle-manager/pkg/controller/install/certresources.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,11 +505,18 @@ func (i *StrategyDeploymentInstaller) installCertRequirementsForDeployment(deplo
505505

506506
// Setting the olm hash label forces a rollout and ensures that the new secret
507507
// is used by the apiserver if not hot reloading.
508-
depSpec.Template.ObjectMeta.SetAnnotations(map[string]string{OLMCAHashAnnotationKey: caHash})
509-
508+
SetCAAnnotation(&depSpec, caHash)
510509
return &depSpec, caPEM, nil
511510
}
512511

512+
func SetCAAnnotation(depSpec *appsv1.DeploymentSpec, caHash string) {
513+
if len(depSpec.Template.ObjectMeta.GetAnnotations()) == 0 {
514+
depSpec.Template.ObjectMeta.SetAnnotations(map[string]string{OLMCAHashAnnotationKey: caHash})
515+
} else {
516+
depSpec.Template.Annotations[OLMCAHashAnnotationKey] = caHash
517+
}
518+
}
519+
513520
// AddDefaultCertVolumeAndVolumeMounts mounts the CA Cert generated by OLM to the location that OLM expects
514521
// APIService certs to be as well as the location that the Operator-SDK and Kubebuilder expect webhook
515522
// certs to be.

staging/operator-lifecycle-manager/pkg/controller/install/certresources_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,21 @@ func TestInstallCertRequirementsForDeployment(t *testing.T) {
310310
Spec: corev1.PodSpec{
311311
ServiceAccountName: "test-sa",
312312
},
313+
ObjectMeta: metav1.ObjectMeta{
314+
Annotations: map[string]string{
315+
"foo": "bar",
316+
},
317+
},
313318
},
314319
},
315320
},
316321
want: &appsv1.DeploymentSpec{
317322
Selector: selector(t, "test=label"),
318323
Template: corev1.PodTemplateSpec{
319324
ObjectMeta: metav1.ObjectMeta{
320-
Annotations: map[string]string{OLMCAHashAnnotationKey: caHash},
325+
Annotations: map[string]string{
326+
"foo": "bar",
327+
OLMCAHashAnnotationKey: caHash},
321328
},
322329
Spec: corev1.PodSpec{
323330
ServiceAccountName: "test-sa",

staging/operator-lifecycle-manager/pkg/controller/operators/olm/apiservices.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ func (a *Operator) updateDeploymentSpecsWithApiServiceData(csv *v1alpha1.Cluster
349349
}
350350

351351
install.AddDefaultCertVolumeAndVolumeMounts(&depSpec, secret.GetName())
352-
depSpec.Template.ObjectMeta.SetAnnotations(map[string]string{install.OLMCAHashAnnotationKey: caHash})
352+
install.SetCAAnnotation(&depSpec, caHash)
353353
depSpecs[desc.DeploymentName] = depSpec
354354
}
355355

@@ -376,7 +376,7 @@ func (a *Operator) updateDeploymentSpecsWithApiServiceData(csv *v1alpha1.Cluster
376376
}
377377
install.AddDefaultCertVolumeAndVolumeMounts(&depSpec, secret.GetName())
378378

379-
depSpec.Template.ObjectMeta.SetAnnotations(map[string]string{install.OLMCAHashAnnotationKey: caHash})
379+
install.SetCAAnnotation(&depSpec, caHash)
380380
depSpecs[desc.DeploymentName] = depSpec
381381
}
382382

vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install/certresources.go

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm/apiservices.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)