Skip to content

Commit cdf75d4

Browse files
Merge pull request #5048 from openshift-cherrypick-robot/cherry-pick-5041-to-release-4.19
[release-4.19] OCPBUGS-56136: Compare the osImageURLs for OS validation check
2 parents 18f1c3d + ae280cb commit cdf75d4

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

pkg/controller/render/render_controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,10 @@ func generateRenderedMachineConfig(pool *mcfgv1.MachineConfigPool, configs []*mc
644644
// the operator shouldn't stop the rest of the upgrade from progressing/completing.
645645
if merged.Spec.OSImageURL != ctrlcommon.GetDefaultBaseImageContainer(&cconfig.Spec) {
646646
merged.Annotations[ctrlcommon.OSImageURLOverriddenKey] = "true"
647+
// Log a warning if the osImageURL is set using a tag instead of a digest
648+
if !strings.Contains(merged.Spec.OSImageURL, "sha256:") {
649+
klog.Warningf("OSImageURL %q for MachineConfig %s is set using a tag instead of a digest. It is highly recommended to use a digest", merged.Spec.OSImageURL, merged.Name)
650+
}
647651
}
648652

649653
return merged, nil

pkg/daemon/daemon.go

+4-15
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ type Daemon struct {
7777
// bootedOSImageURL is the currently booted URL of the operating system
7878
bootedOSImageURL string
7979

80-
// bootedOScommit is the commit hash of the currently booted operating system
81-
bootedOSCommit string
82-
8380
// previousFinalizationFailure caches a failure of ostree-finalize-staged.service
8481
// we may have seen from the previous boot.
8582
previousFinalizationFailure string
@@ -347,7 +344,6 @@ func New(
347344
os: hostos,
348345
NodeUpdaterClient: nodeUpdaterClient,
349346
bootedOSImageURL: osImageURL,
350-
bootedOSCommit: osCommit,
351347
bootID: bootID,
352348
exitCh: exitCh,
353349
currentConfigPath: currentConfigPath,
@@ -2653,7 +2649,7 @@ func (dn *Daemon) validateOnDiskStateImpl(currentConfig *mcfgv1.MachineConfig, i
26532649
// Be sure we're booted into the OS we expect
26542650
osMatch := dn.checkOS(imageToCheck)
26552651
if !osMatch {
2656-
return fmt.Errorf("expected target osImageURL %q, have %q (%q)", imageToCheck, dn.bootedOSImageURL, dn.bootedOSCommit)
2652+
return fmt.Errorf("expected target osImageURL %q, have %q", imageToCheck, dn.bootedOSImageURL)
26572653
}
26582654

26592655
if dn.os.IsCoreOSVariant() {
@@ -2731,16 +2727,9 @@ func (dn *Daemon) checkOS(osImageURL string) bool {
27312727
return true
27322728
}
27332729

2734-
// TODO(jkyros): the header for this functions says "if the digests match"
2735-
// so I'm wondering if at one point this used to work this way....
2736-
inspection, _, err := ImageInspect(osImageURL, "")
2737-
if err != nil {
2738-
klog.Warningf("Unable to check manifest for matching hash: %s", err)
2739-
} else if ostreeCommit, ok := inspection.Labels["ostree.commit"]; ok {
2740-
if ostreeCommit == dn.bootedOSCommit {
2741-
klog.Infof("We are technically in the right image even if the URL doesn't match (%s == %s)", ostreeCommit, osImageURL)
2742-
return true
2743-
}
2730+
if !strings.Contains(osImageURL, "sha256:") {
2731+
// This is for info gathering purposes
2732+
klog.Warningf("osImageURL %q is not a digest; using a digest is recommended", osImageURL)
27442733
}
27452734

27462735
return dn.bootedOSImageURL == osImageURL

0 commit comments

Comments
 (0)