-
Notifications
You must be signed in to change notification settings - Fork 462
MCO-1961: Rework MC's OSImageURL merge logic #5488
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
openshift-merge-bot
merged 1 commit into
openshift:main
from
pablintino:rework-osimageurl-merge
Dec 16, 2025
+68
−11
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,11 +6,14 @@ import ( | |
| "crypto/x509" | ||
| "encoding/json" | ||
| "encoding/pem" | ||
| "errors" | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "reflect" | ||
| "sort" | ||
| "strings" | ||
| "sync" | ||
| "time" | ||
|
|
||
| mcfgv1 "github.com/openshift/api/machineconfiguration/v1" | ||
|
|
@@ -26,7 +29,6 @@ import ( | |
| configinformersv1 "github.com/openshift/client-go/config/informers/externalversions/config/v1" | ||
| configlistersv1 "github.com/openshift/client-go/config/listers/config/v1" | ||
| corev1 "k8s.io/api/core/v1" | ||
| "k8s.io/apimachinery/pkg/api/errors" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
| "k8s.io/apimachinery/pkg/util/wait" | ||
|
|
@@ -74,6 +76,8 @@ type Controller struct { | |
| secretsInformerSynced cache.InformerSynced | ||
|
|
||
| queue workqueue.TypedRateLimitingInterface[string] | ||
|
|
||
| urlClearOnce sync.Once | ||
| } | ||
|
|
||
| // New returns a new template controller. | ||
|
|
@@ -588,7 +592,7 @@ func (ctrl *Controller) syncControllerConfig(key string) error { | |
| return err | ||
| } | ||
| controllerconfig, err := ctrl.ccLister.Get(name) | ||
| if errors.IsNotFound(err) { | ||
| if apierrors.IsNotFound(err) { | ||
| klog.V(2).Infof("ControllerConfig %v has been deleted", key) | ||
| return nil | ||
| } | ||
|
|
@@ -633,6 +637,15 @@ func (ctrl *Controller) syncControllerConfig(key string) error { | |
| return ctrl.syncFailingStatus(cfg, err) | ||
| } | ||
|
|
||
| // TODO: To be removed when 4.22 is EOL | ||
| // Since 4.22 templated/generated (non-rendered) MCs no longer set the | ||
| // OS and Extensions URLs and if given, the render controller ignores their | ||
| // values. To improve UX we remove the URLs from existing MCs once. | ||
| if clearErr := ctrl.clearImageURLs(); err == nil && apiServer != nil { | ||
| // Best effort, do not fail | ||
| klog.Warningf("Clearing MCs URLs has failed: %v", clearErr) | ||
| } | ||
|
|
||
| mcs, err := getMachineConfigsForControllerConfig(ctrl.templatesDir, cfg, clusterPullSecretRaw, apiServer) | ||
| if err != nil { | ||
| return ctrl.syncFailingStatus(cfg, err) | ||
|
|
@@ -652,6 +665,39 @@ func (ctrl *Controller) syncControllerConfig(key string) error { | |
| return ctrl.syncCompletedStatus(cfg) | ||
| } | ||
|
|
||
| // clearImageURLs clears OSImageURL and BaseOSExtensionsContainerImage from template-generated | ||
| // MachineConfigs. This is a one-time migration operation to remove these fields from generated | ||
| // MachineConfigs, as they should only be set on rendered or user-provided MachineConfigs. | ||
| // The function uses sync.Once to ensure it runs only once per controller lifecycle. | ||
|
Contributor
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. Controller lifecycle = each time the pod restarts in this case, right?
Contributor
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. Correct! |
||
| func (ctrl *Controller) clearImageURLs() error { | ||
| var err error | ||
| ctrl.urlClearOnce.Do(func() { | ||
| var mcList *mcfgv1.MachineConfigList | ||
| mcList, err = ctrl.client.MachineconfigurationV1().MachineConfigs().List(context.TODO(), metav1.ListOptions{}) | ||
| if err != nil { | ||
| return | ||
| } | ||
| for _, mc := range mcList.Items { | ||
| if mc.Annotations[ctrlcommon.GeneratedByControllerVersionAnnotationKey] == "" || strings.HasPrefix(mc.Name, ctrlcommon.RenderedMachineConfigPrefix) { | ||
| // It's a rendered MC or a user provided one. | ||
| // This update code only works with templated/generated MCs | ||
| continue | ||
| } | ||
|
|
||
| if mc.Spec.OSImageURL != "" || mc.Spec.BaseOSExtensionsContainerImage != "" { | ||
| mc.Spec.OSImageURL = "" | ||
| mc.Spec.BaseOSExtensionsContainerImage = "" | ||
|
|
||
| if _, updateErr := ctrl.client.MachineconfigurationV1().MachineConfigs().Update(context.TODO(), &mc, metav1.UpdateOptions{}); updateErr != nil { | ||
| err = errors.Join(err, updateErr) | ||
| } | ||
| klog.Infof("Removed old imageURLs from MachineConfig %s", mc.Name) | ||
| } | ||
| } | ||
| }) | ||
| return err | ||
| } | ||
|
|
||
| func getMachineConfigsForControllerConfig(templatesDir string, config *mcfgv1.ControllerConfig, clusterPullSecretRaw []byte, apiServer *configv1.APIServer) ([]*mcfgv1.MachineConfig, error) { | ||
| buf := &bytes.Buffer{} | ||
| if err := json.Compact(buf, clusterPullSecretRaw); err != nil { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't we just be able to remove this in 4.23? Or is that what you meant here (4.22 EoL seems to imply the full 3-year(?) cycle)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yuqi-zhang Well, I think this code should be in place till all the legacy supported clusters are migrated or EoL. I mean, if someone with a 4.12 cluster upgrades, I'll want to clear his MCs.
Cause, now thinking, is it mandatory to upgrade versions one by one? If so, yes, if they need to pass through 4.22, we can remove the code in 4.23.