Skip to content

Commit 988598e

Browse files
committed
Add ownership annotations to new and existing olm-managed secrets
As a part of certificates ownership work, all of new and existing secrets that are created with certificate information need to have ownership annotations. New secrets that are created with OLM certresources controller will have new ownership annotations injected at creation/update time. The existing olm-managed secrets that don't have the required annotations will get reconciled at startup when olm operator is restarted/redeployed. This PR only add OpenShift owning component annotation and the description annotation can be added later. Signed-off-by: Vu Dinh <[email protected]>
1 parent 5c00fde commit 988598e

File tree

8 files changed

+82
-4
lines changed

8 files changed

+82
-4
lines changed

manifests/0000_50_olm_00-pprof-secret.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ metadata:
66
include.release.openshift.io/self-managed-high-availability: "true"
77
release.openshift.io/create-only: "true"
88
capability.openshift.io/name: "OperatorLifecycleManager"
9+
openshift.io/owning-component: "Operator Framework / operator-lifecycle-manager"
910
name: pprof-cert
1011
namespace: openshift-operator-lifecycle-manager
1112
type: kubernetes.io/tls

microshift-manifests/0000_50_olm_00-pprof-secret.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ metadata:
66
include.release.openshift.io/self-managed-high-availability: "true"
77
release.openshift.io/create-only: "true"
88
capability.openshift.io/name: "OperatorLifecycleManager"
9+
openshift.io/owning-component: "Operator Framework / operator-lifecycle-manager"
910
name: pprof-cert
1011
namespace: openshift-operator-lifecycle-manager
1112
type: kubernetes.io/tls

staging/operator-lifecycle-manager/cmd/olm/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ func main() {
224224
go monitor.Run(op.Done())
225225
}
226226

227+
// Reconcile all olm-managed secrets to add ownership annotations if not existed
228+
if err = op.EnsureSecretOwnershipAnnotations; err != nil {
229+
logger.WithError(err).Fatal("error injecting ownership annotations to existing olm-managed secrets")
230+
}
231+
227232
// Start the controller manager
228233
if err := mgr.Start(ctx); err != nil {
229234
logger.WithError(err).Fatal("controller manager stopped")

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ const (
4242
// olm managed label
4343
OLMManagedLabelKey = "olm.managed"
4444
OLMManagedLabelValue = "true"
45+
// Use this const for now to avoid openshift/api bump
46+
// TODO: Bump openshift/api and remove this const
47+
OpenShiftComponent = "openshift.io/owning-component"
48+
OLMOwnershipAnnotation = "Operator Framework / operator-lifecycle-manager"
4549
)
4650

4751
type certResource interface {
@@ -300,6 +304,11 @@ func (i *StrategyDeploymentInstaller) installCertRequirementsForDeployment(deplo
300304
}
301305
caHash := certs.PEMSHA256(caPEM)
302306

307+
annotations := map[string]string{
308+
OpenShiftComponent: OLMOwnershipAnnotation,
309+
OLMCAHashAnnotationKey: caHash,
310+
}
311+
303312
secret := &corev1.Secret{
304313
Data: map[string][]byte{
305314
"tls.crt": certPEM,
@@ -310,8 +319,8 @@ func (i *StrategyDeploymentInstaller) installCertRequirementsForDeployment(deplo
310319
}
311320
secret.SetName(SecretName(service.GetName()))
312321
secret.SetNamespace(i.owner.GetNamespace())
313-
secret.SetAnnotations(map[string]string{OLMCAHashAnnotationKey: caHash})
314322
secret.SetLabels(map[string]string{OLMManagedLabelKey: OLMManagedLabelValue})
323+
secret.SetAnnotations(annotations)
315324

316325
existingSecret, err := i.strategyClient.GetOpLister().CoreV1().SecretLister().Secrets(i.owner.GetNamespace()).Get(secret.GetName())
317326
if err == nil {
@@ -322,7 +331,7 @@ func (i *StrategyDeploymentInstaller) installCertRequirementsForDeployment(deplo
322331

323332
// Attempt an update
324333
// TODO: Check that the secret was not modified
325-
if existingCAPEM, ok := existingSecret.Data[OLMCAPEMKey]; ok && !ShouldRotateCerts(i.owner.(*v1alpha1.ClusterServiceVersion)) {
334+
if existingCAPEM, ok := existingSecret.Data[OLMCAPEMKey]; ok && !ShouldRotateCerts(i.owner.(*v1alpha1.ClusterServiceVersion)) && existingSecret.Annotations[OpenShiftComponent] != "" {
326335
logger.Warnf("reusing existing cert %s", secret.GetName())
327336
secret = existingSecret
328337
caPEM = existingCAPEM

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,3 +2900,27 @@ func (a *Operator) ensureLabels(in *v1alpha1.ClusterServiceVersion, labelSets ..
29002900
out, err := a.client.OperatorsV1alpha1().ClusterServiceVersions(out.GetNamespace()).Update(context.TODO(), out, metav1.UpdateOptions{})
29012901
return out, err
29022902
}
2903+
2904+
// syncSecret adds required ownership annotations to olm-managed secrets
2905+
func (a *Operator) EnsureSecretOwnershipAnnotations() error {
2906+
secrets, err := a.lister.CoreV1().SecretLister().List(labels.SelectorFromSet(labels.Set{install.OLMManagedLabelKey: install.OLMManagedLabelValue}))
2907+
if err != nil {
2908+
return err
2909+
}
2910+
for _, secret := range secrets {
2911+
if secret.Annotations[install.OpenShiftComponent] == "" {
2912+
secret.Annotations[install.OpenShiftComponent] = install.OLMOwnershipAnnotation
2913+
logger := a.logger.WithFields(logrus.Fields{
2914+
"name": secret.GetName(),
2915+
"namespace": secret.GetNamespace(),
2916+
"self": secret.GetSelfLink(),
2917+
})
2918+
logger.Debug("injecting ownership annotations to existing secret")
2919+
if _, updateErr := a.opClient.UpdateSecret(secret); updateErr != nil {
2920+
logger.WithError(err).Warn("error adding ownership annotations to existing secret")
2921+
return err
2922+
}
2923+
}
2924+
}
2925+
return nil
2926+
}

vendor/github.com/operator-framework/operator-lifecycle-manager/cmd/olm/main.go

Lines changed: 5 additions & 0 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/install/certresources.go

Lines changed: 11 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/operator.go

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

0 commit comments

Comments
 (0)