Skip to content

Do not modify object from the lister cache #2562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/controller/bundle/bundle_unpacker.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ func (c *ConfigMapUnpacker) ensureRole(cmRef *corev1.ObjectReference) (role *rba
return
}
}
role = role.DeepCopy()
role.Rules = append(role.Rules, rule)

role, err = c.client.RbacV1().Roles(role.GetNamespace()).Update(context.TODO(), role, metav1.UpdateOptions{})
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/install/apiservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (i *StrategyDeploymentInstaller) createOrUpdateAPIService(caPEM []byte, des
}
apiService.SetName(apiServiceName)
} else {
apiService = apiService.DeepCopy()
csv, ok := i.owner.(*v1alpha1.ClusterServiceVersion)
if !ok {
return fmt.Errorf("failed to typecast the APIService owner: APIServices require a CSV owner")
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/install/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (i *StrategyDeploymentInstaller) createOrUpdateMutatingWebhook(ogNamespacel
}
}
for _, webhook := range existingWebhooks.Items {
webhook = *webhook.DeepCopy()
// Update the list of webhooks
webhook.Webhooks = []admissionregistrationv1.MutatingWebhook{
desc.GetMutatingWebhook(i.owner.GetNamespace(), ogNamespacelabelSelector, caPEM),
Expand Down Expand Up @@ -154,6 +155,7 @@ func (i *StrategyDeploymentInstaller) createOrUpdateValidatingWebhook(ogNamespac
return nil
}
for _, webhook := range existingWebhooks.Items {
webhook = *webhook.DeepCopy()
// Update the list of webhooks
webhook.Webhooks = []admissionregistrationv1.ValidatingWebhook{
desc.GetValidatingWebhook(i.owner.GetNamespace(), ogNamespacelabelSelector, caPEM),
Expand Down
9 changes: 5 additions & 4 deletions pkg/controller/operators/olm/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ func (a *Operator) syncObject(obj interface{}) (syncError error) {
if related {
csvList := a.csvSet(metaObj.GetNamespace(), v1alpha1.CSVPhaseFailed)
for _, csv := range csvList {
csv = csv.DeepCopy()
if csv.Status.Reason != v1alpha1.CSVReasonComponentFailedNoRetry {
continue
}
Expand Down Expand Up @@ -1238,7 +1239,7 @@ func (a *Operator) allNamespaceOperatorGroups() ([]*v1.OperatorGroup, error) {
result := []*v1.OperatorGroup{}
for _, operatorGroup := range operatorGroups {
if NewNamespaceSet(operatorGroup.Status.Namespaces).IsAllNamespaces() {
result = append(result, operatorGroup)
result = append(result, operatorGroup.DeepCopy())
}
}
return result, nil
Expand Down Expand Up @@ -1477,7 +1478,7 @@ func (a *Operator) getCopiedCSVDisabledEventsForCSV(csv *v1alpha1.ClusterService
event.InvolvedObject.Name == csv.GetName() &&
event.InvolvedObject.UID == csv.GetUID() &&
event.Reason == v1.DisabledCopiedCSVsConditionType {
result = append(result, event)
result = append(result, *event.DeepCopy())
}
}

Expand Down Expand Up @@ -1586,7 +1587,7 @@ func (a *Operator) operatorGroupFromAnnotations(logger *logrus.Entry, csv *v1alp
return nil
}

return operatorGroup
return operatorGroup.DeepCopy()
}

func (a *Operator) operatorGroupForCSV(csv *v1alpha1.ClusterServiceVersion, logger *logrus.Entry) (*v1.OperatorGroup, error) {
Expand Down Expand Up @@ -1627,7 +1628,7 @@ func (a *Operator) operatorGroupForCSV(csv *v1alpha1.ClusterServiceVersion, logg
return nil, nil
}
logger.Debug("csv in operatorgroup")
return operatorGroup, nil
return operatorGroup.DeepCopy(), nil
default:
err = fmt.Errorf("csv created in namespace with multiple operatorgroups, can't pick one automatically")
logger.WithError(err).Warn("csv failed to become an operatorgroup member")
Expand Down
10 changes: 6 additions & 4 deletions pkg/controller/operators/olm/operatorgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (a *Operator) syncOperatorGroups(obj interface{}) error {

// Check if there is a stale multiple OG condition and clear it if existed.
if len(groups) == 1 {
og := groups[0]
og := groups[0].DeepCopy()
if c := meta.FindStatusCondition(og.Status.Conditions, v1.MutlipleOperatorGroupCondition); c != nil {
meta.RemoveStatusCondition(&og.Status.Conditions, v1.MutlipleOperatorGroupCondition)
if og.GetName() == op.GetName() {
Expand All @@ -93,7 +93,8 @@ func (a *Operator) syncOperatorGroups(obj interface{}) error {
Reason: v1.MultipleOperatorGroupsReason,
Message: "Multiple OperatorGroup found in the same namespace",
}
for _, og := range groups {
for i := range groups {
og := groups[i].DeepCopy()
if c := meta.FindStatusCondition(og.Status.Conditions, v1.MutlipleOperatorGroupCondition); c != nil {
continue
}
Expand All @@ -115,11 +116,12 @@ func (a *Operator) syncOperatorGroups(obj interface{}) error {
return err
}
if op.Status.ServiceAccountRef != previousRef {
crdList, err := a.lister.OperatorsV1alpha1().ClusterServiceVersionLister().List(labels.Everything())
csvList, err := a.lister.OperatorsV1alpha1().ClusterServiceVersionLister().List(labels.Everything())
if err != nil {
return err
}
for _, csv := range crdList {
for i := range csvList {
csv := csvList[i].DeepCopy()
if group, ok := csv.GetAnnotations()[v1.OperatorGroupAnnotationKey]; !ok || group != op.GetName() {
continue
}
Expand Down