Skip to content

Commit 8c7611d

Browse files
committed
[CARRY] Fix panic issue when annotations map is nil
In some cases, secrets do not have any annotations and the annotations map are nil. The annotations map needs to be initialized to avoid panic error. Signed-off-by: Vu Dinh <[email protected]>
1 parent d74f6fe commit 8c7611d

File tree

2 files changed

+42
-22
lines changed
  • staging/operator-lifecycle-manager/pkg/controller/operators/olm
  • vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm

2 files changed

+42
-22
lines changed

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,19 +2907,29 @@ func (a *Operator) EnsureSecretOwnershipAnnotations() error {
29072907
if err != nil {
29082908
return err
29092909
}
2910+
29102911
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
2912+
logger := a.logger.WithFields(logrus.Fields{
2913+
"name": secret.GetName(),
2914+
"namespace": secret.GetNamespace(),
2915+
"self": secret.GetSelfLink(),
2916+
})
2917+
logger.Debug("ensuring ownership annotations existed in the secret")
2918+
2919+
if secret.Annotations != nil {
2920+
if secret.Annotations[install.OpenShiftComponent] == "" {
2921+
secret.Annotations[install.OpenShiftComponent] = install.OLMOwnershipAnnotation
2922+
} else {
2923+
continue
29222924
}
2925+
} else {
2926+
secret.Annotations = map[string]string{}
2927+
secret.Annotations[install.OpenShiftComponent] = install.OLMOwnershipAnnotation
2928+
}
2929+
logger.Debug("injecting ownership annotations to existing secret")
2930+
if _, updateErr := a.opClient.UpdateSecret(secret); updateErr != nil {
2931+
logger.WithError(err).Warn("error adding ownership annotations to existing secret")
2932+
return err
29232933
}
29242934
}
29252935
return nil

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

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

0 commit comments

Comments
 (0)