-
Notifications
You must be signed in to change notification settings - Fork 587
fix(olm): fix ConversionWebhook spec.conversion lifecycle during CSV upgrades #3892
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1302,11 +1302,27 @@ func (a *Operator) handleClusterServiceVersionDeletion(obj interface{}) { | |
| // webhook from the CRD definition. | ||
| csvs, err := a.lister.OperatorsV1alpha1().ClusterServiceVersionLister().ClusterServiceVersions(clusterServiceVersion.GetNamespace()).List(labels.Everything()) | ||
| if err != nil { | ||
| logger.Errorf("error listing csvs: %v\n", err) | ||
| // Without a complete CSV list we cannot safely determine which CRDs are still | ||
| // covered by a replacement CSV. Bail out to avoid incorrectly clearing | ||
| // spec.conversion on CRDs that a replacement still owns. | ||
| logger.Errorf("error listing csvs, skipping conversion webhook cleanup: %v\n", err) | ||
| return | ||
| } | ||
|
|
||
| // Build the set of CRDs whose ConversionWebhook is still covered by the replacement CSV. | ||
| // If the replacement dropped the ConversionWebhook for a given CRD, spec.conversion on | ||
| // that CRD must be reset — otherwise it keeps pointing at the now-deleted service and | ||
| // all CR requests against that CRD will fail. | ||
| coveredCRDs := map[string]bool{} | ||
| for _, csv := range csvs { | ||
| if csv.Spec.Replaces == clusterServiceVersion.GetName() { | ||
| return | ||
| for _, desc := range csv.Spec.WebhookDefinitions { | ||
| if desc.Type == v1alpha1.ConversionWebhook { | ||
| for _, crdName := range desc.ConversionCRDs { | ||
| coveredCRDs[crdName] = true | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1316,18 +1332,26 @@ func (a *Operator) handleClusterServiceVersionDeletion(obj interface{}) { | |
| } | ||
|
|
||
| for i, crdName := range desc.ConversionCRDs { | ||
| if coveredCRDs[crdName] { | ||
| // Replacement CSV still has a ConversionWebhook for this CRD; leave | ||
| // spec.conversion intact so in-flight conversion calls keep working. | ||
| continue | ||
| } | ||
|
|
||
| crd, err := a.opClient.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Get(context.TODO(), crdName, metav1.GetOptions{}) | ||
| if err != nil { | ||
| logger.Errorf("error getting CRD %v which was defined in CSVs spec.WebhookDefinition[%d]: %v\n", crdName, i, err) | ||
| continue | ||
| } | ||
|
|
||
| copy := crd.DeepCopy() | ||
| copy.Spec.Conversion.Strategy = apiextensionsv1.NoneConverter | ||
| copy.Spec.Conversion.Webhook = nil | ||
| if copy.Spec.Conversion != nil { | ||
| copy.Spec.Conversion.Strategy = apiextensionsv1.NoneConverter | ||
| copy.Spec.Conversion.Webhook = nil | ||
|
|
||
| if _, err = a.opClient.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Update(context.TODO(), copy, metav1.UpdateOptions{}); err != nil { | ||
| logger.Errorf("error updating conversion strategy for CRD %v: %v\n", crdName, err) | ||
| if _, err = a.opClient.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Update(context.TODO(), copy, metav1.UpdateOptions{}); err != nil { | ||
| logger.Errorf("error updating conversion strategy for CRD %v: %v\n", crdName, err) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -2617,7 +2641,16 @@ func (a *Operator) updateInstallStatus(csv *v1alpha1.ClusterServiceVersion, inst | |
| } | ||
|
|
||
| apiServicesInstalled, apiServiceErr := a.areAPIServicesAvailable(csv) | ||
| webhooksInstalled, webhookErr := a.areWebhooksAvailable(csv) | ||
| // Only attempt to write spec.conversion once the deployment is confirmed ready. | ||
| // areWebhooksAvailable calls EnsureConversionWebhooks, so calling it when | ||
| // strategyInstalled is false would recreate the upgrade race we are fixing. | ||
| // Note: CheckInstalled never returns (true, non-nil error), so strategyInstalled | ||
| // is sufficient — no need to also gate on strategyErr. | ||
| webhooksInstalled := false | ||
| var webhookErr error | ||
| if strategyInstalled { | ||
| webhooksInstalled, webhookErr = a.areWebhooksAvailable(csv, installer) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, the readiness gate was also delaying the cleanup of removed validating and mutating webhook configurations. I split cleanup from availability checks. |
||
| } | ||
|
|
||
| if strategyInstalled && apiServicesInstalled && webhooksInstalled { | ||
| // if there's no error, we're successfully running | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.