Skip to content

Commit 050689d

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 050689d

File tree

9 files changed

+87
-9
lines changed

9 files changed

+87
-9
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

scripts/generate_crds_manifests.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ metadata:
346346
include.release.openshift.io/ibm-cloud-managed: "true"
347347
include.release.openshift.io/self-managed-high-availability: "true"
348348
release.openshift.io/create-only: "true"
349+
openshift.io/owning-component: "Operator Framework / operator-lifecycle-manager"
349350
name: pprof-cert
350351
namespace: openshift-operator-lifecycle-manager
351352
type: kubernetes.io/tls
@@ -488,7 +489,7 @@ add_ibm_managed_cloud_annotations "${ROOT_DIR}/manifests"
488489
find "${ROOT_DIR}/manifests" -type f -exec $SED -i "/^#/d" {} \;
489490
find "${ROOT_DIR}/manifests" -type f -exec $SED -i "1{/---/d}" {} \;
490491

491-
# (anik120): uncomment this once https://issues.redhat.com/browse/OLM-2695 is Done.
492+
# (anik120): uncomment this once https://issues.redhat.com/browse/OLM-2695 is Done.
492493
#${YQ} delete --inplace -d'1' manifests/0000_50_olm_00-namespace.yaml 'metadata.labels."pod-security.kubernetes.io/enforce*"'
493494

494495
# Unlike the namespaces shipped in the upstream version, the openshift-operator-lifecycle-manager and openshift-operator
@@ -505,7 +506,7 @@ cp "${ROOT_DIR}"/manifests/* "${ROOT_DIR}/microshift-manifests/"
505506
# There are some differences that we need to take care of:
506507
# - The manifests require a kustomization.yaml file
507508
# - We don't need the specific ibm-cloud-managed manifests
508-
# - We need to adapt some of the manifests to be compatible with microshift as there's no
509+
# - We need to adapt some of the manifests to be compatible with microshift as there's no
509510
# ClusterVersion or ClusterOperator in microshift
510511

511512
# Create the kustomization file
@@ -530,7 +531,7 @@ for file in ${microshift_manifests_files}; do
530531
fi
531532
done
532533
echo " - $(realpath --relative-to "${ROOT_DIR}/microshift-manifests" "${file}")" >> "${ROOT_DIR}/microshift-manifests/kustomization.yaml"
533-
done
534+
done
534535

535536
# Now we need to get rid of these args from the olm-operator deployment:
536537
#
@@ -539,5 +540,4 @@ done
539540
# - --writePackageServerStatusName
540541
# - operator-lifecycle-manager-packageserver
541542
#
542-
${SED} -i '/- --writeStatusName/,+3d' ${ROOT_DIR}/microshift-manifests/0000_50_olm_07-olm-operator.deployment.yaml
543-
543+
${SED} -i '/- --writeStatusName/,+3d' ${ROOT_DIR}/microshift-manifests/0000_50_olm_07-olm-operator.deployment.yaml

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)