-
Notifications
You must be signed in to change notification settings - Fork 461
MCO-1976: [Dev] Fix RHEL9-specific MCD Logic for RHEL10/CentOS10 Compatibility #5415
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
dkhater-redhat:rhel10-compatible
Nov 20, 2025
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
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.
Just my 2 cents, but I don't think continuing with version-specific conditionals is the right direction. This piece of code will need a revisit each time there's a new major, like now.
WDYT about something like this?
diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index e990021ed..01170f701 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -14,7 +14,9 @@ import ( "os/exec" "os/signal" "path/filepath" + "regexp" "slices" + "strconv" "strings" "sync" "syscall" @@ -531,20 +533,34 @@ func ReexecuteForTargetRoot(target string) error { return fmt.Errorf("failed to get target OS: %w", err) } - var sourceBinarySuffix string + sourceBinary := "/usr/bin/machine-config-daemon" if sourceOsVersion.IsLikeRHEL() && targetOsVersion.IsLikeRHEL() { - sourceMajor := sourceOsVersion.BaseVersionMajor() - targetMajor := targetOsVersion.BaseVersionMajor() - if sourceMajor == "9" && targetMajor == "8" { - sourceBinarySuffix = ".rhel8" - klog.Info("container is rhel9, target is rhel8") + sourceVersion, err := strconv.Atoi(sourceOsVersion.BaseVersionMajor()) + if err != nil { + return fmt.Errorf("failed to convert source major version: %w", err) + } + targetVersion, err := strconv.Atoi(targetOsVersion.BaseVersionMajor()) + if err != nil { + return fmt.Errorf("failed to convert target major version: %w", err) + } + if sourceVersion > targetVersion { + suffixes, err := getVersionedBinarySuffixes(sourceBinary + "*") + if err != nil { + return fmt.Errorf("failed to get machine-config-daemon versioned binaries: %w", err) + } + suffix, exists := suffixes[targetVersion] + if exists { + sourceBinary += suffix + } + klog.Infof("container is rhel%d, target is rhel%d", sourceVersion, targetVersion) } else { - klog.Infof("using appropriate binary for source=rhel-%s target=rhel-%s", sourceMajor, targetMajor) + klog.Infof("using appropriate binary for source=rhel-%d target=rhel-%d", sourceVersion, targetVersion) } + } else { klog.Info("assuming we can use container binary chroot() to host") } - sourceBinary := "/usr/bin/machine-config-daemon" + sourceBinarySuffix + src, err := os.Open(sourceBinary) if err != nil { return fmt.Errorf("opening %s: %w", sourceBinary, err) @@ -596,6 +612,33 @@ func ReexecuteForTargetRoot(target string) error { return syscall.Exec(targetBin, newArgv, newEnv) } +var regexDigits = regexp.MustCompile(`(\d)*$`) + +func getVersionedBinarySuffixes(basePath string) (map[int]string, error) { + result := map[int]string{} + matches, err := filepath.Glob(basePath) + if err != nil { + return nil, err + } + for _, match := range matches { + extension := filepath.Ext(match) + if extension != "" { + versionBytes := regexDigits.Find([]byte(extension)) + if versionBytes == nil { + // Skip, is a binary that doesn't have the pattern we are looking for + continue + } + + version, err := strconv.Atoi(string(versionBytes)) + if err != nil { + return nil, err + } + result[version] = extension + } + } + return result, nil +} + // worker runs a worker thread that just dequeues items, processes them, and marks them done. // It enforces that the syncHandler is never invoked concurrently with the same key. func (dn *Daemon) worker() {