Skip to content

Commit 85c579f

Browse files
Merge pull request openshift#626 from dinhxuanvu/cert-annotations
API-1674: Add ownership annotations to new and existing olm-managed secrets
2 parents 42b679b + 98d78fe commit 85c579f

File tree

10 files changed

+90
-11
lines changed

10 files changed

+90
-11
lines changed

manifests/0000_50_olm_00-pprof-secret.yaml

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

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

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

scripts/generate_crds_manifests.sh

Lines changed: 5 additions & 4 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,7 +540,7 @@ 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+
${SED} -i '/- --writeStatusName/,+3d' ${ROOT_DIR}/microshift-manifests/0000_50_olm_07-olm-operator.deployment.yaml
543544

544545
# Replace the namespace openshift, as it doesn't exist on microshift, in the rbac file
545546
${SED} -i 's/ namespace: openshift/ namespace: openshift-operator-lifecycle-manager/g' ${ROOT_DIR}/microshift-manifests/0000_50_olm_15-csv-viewer.rbac.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/install/certresources_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func TestInstallCertRequirementsForDeployment(t *testing.T) {
184184
ObjectMeta: metav1.ObjectMeta{
185185
Name: "test-service-cert",
186186
Namespace: namespace,
187-
Annotations: map[string]string{OLMCAHashAnnotationKey: caHash},
187+
Annotations: map[string]string{OLMCAHashAnnotationKey: caHash, OpenShiftComponent: OLMOwnershipAnnotation},
188188
Labels: map[string]string{OLMManagedLabelKey: OLMManagedLabelValue},
189189
},
190190
Data: map[string][]byte{
@@ -413,7 +413,7 @@ func TestInstallCertRequirementsForDeployment(t *testing.T) {
413413
ObjectMeta: metav1.ObjectMeta{
414414
Name: "test-service-cert",
415415
Namespace: namespace,
416-
Annotations: map[string]string{OLMCAHashAnnotationKey: caHash},
416+
Annotations: map[string]string{OLMCAHashAnnotationKey: caHash, OpenShiftComponent: OLMOwnershipAnnotation},
417417
Labels: map[string]string{OLMManagedLabelKey: OLMManagedLabelValue},
418418
},
419419
Data: map[string][]byte{
@@ -635,7 +635,7 @@ func TestInstallCertRequirementsForDeployment(t *testing.T) {
635635
ObjectMeta: metav1.ObjectMeta{
636636
Name: "test-service-cert",
637637
Namespace: namespace,
638-
Annotations: map[string]string{OLMCAHashAnnotationKey: caHash},
638+
Annotations: map[string]string{OLMCAHashAnnotationKey: caHash, OpenShiftComponent: OLMOwnershipAnnotation},
639639
Labels: map[string]string{OLMManagedLabelKey: OLMManagedLabelValue},
640640
OwnerReferences: []metav1.OwnerReference{
641641
ownerutil.NonBlockingOwner(&v1alpha1.ClusterServiceVersion{}),

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)