Skip to content
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

OCPBUGS-35199: daemon: skip imageInspect during checkOS for PinnedImages #4402

Closed
wants to merge 1 commit into from
Closed
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
52 changes: 44 additions & 8 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"k8s.io/client-go/util/workqueue"

configv1 "github.com/openshift/api/config/v1"
features "github.com/openshift/api/features"
mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
mcfgalphav1 "github.com/openshift/api/machineconfiguration/v1alpha1"
mcfginformersv1 "github.com/openshift/client-go/machineconfiguration/informers/externalversions/machineconfiguration/v1"
Expand Down Expand Up @@ -2594,21 +2595,56 @@ func (dn *Daemon) checkOS(osImageURL string) bool {
return true
}

// TODO(jkyros): the header for this functions says "if the digests match"
// so I'm wondering if at one point this used to work this way....
inspection, _, err := imageInspect(osImageURL)
isPinnedImagesEnabled, err := dn.isFeatureGateEnabled(features.FeatureGatePinnedImages)
if err != nil {
klog.Warningf("Unable to check manifest for matching hash: %s", err)
} else if ostreeCommit, ok := inspection.Labels["ostree.commit"]; ok {
if ostreeCommit == dn.bootedOSCommit {
klog.Infof("We are technically in the right image even if the URL doesn't match (%s == %s)", ostreeCommit, osImageURL)
return true
klog.Warning(err)
}

isOsImagePresent := false
if isPinnedImagesEnabled {
isOsImagePresent, err = isImagePresent(osImageURL)
if err != nil {
klog.Warning(err)
}
}

// See https://github.com/openshift/machine-config-operator/pull/3821 for
// why we can rely on rpm-ostree directly. In the future the inspection
// code below could be removed based on the success of pinned images
// validation.
if !isOsImagePresent {
// TODO(jkyros): the header for this functions says "if the digests match"
// so I'm wondering if at one point this used to work this way....
inspection, _, err := imageInspect(osImageURL)
if err != nil {
klog.Warningf("Unable to check manifest for matching hash: %s", err)
} else if ostreeCommit, ok := inspection.Labels["ostree.commit"]; ok {
if ostreeCommit == dn.bootedOSCommit {
klog.Infof("We are technically in the right image even if the URL doesn't match (%s == %s)", ostreeCommit, osImageURL)
return true
}
}
}

return dn.bootedOSImageURL == osImageURL
}

func (dn *Daemon) isFeatureGateEnabled(name configv1.FeatureGateName) (bool, error) {
// not set during firstboot
if dn.featureGatesAccessor != nil {
fg, err := dn.featureGatesAccessor.CurrentFeatureGates()
if err != nil {
return false, fmt.Errorf("failed to get feature gates: %w", err)
}

if fg.Enabled(name) {
return true, nil
}
}

return false, nil
}

// Close closes all the connections the node agent has open for it's lifetime
func (dn *Daemon) Close() {
}
Expand Down
16 changes: 6 additions & 10 deletions pkg/daemon/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2583,20 +2583,16 @@ func (dn *Daemon) updateLayeredOSToPullspec(newURL string) error {
}

isOsImagePresent := false
isPinnedImagesEnabled, err := dn.isFeatureGateEnabled(features.FeatureGatePinnedImages)
if err != nil {
return err
}

// not set during firstboot
if dn.featureGatesAccessor != nil {
fg, err := dn.featureGatesAccessor.CurrentFeatureGates()
if isPinnedImagesEnabled {
isOsImagePresent, err = isImagePresent(newURL)
if err != nil {
return err
}

if fg.Enabled(features.FeatureGatePinnedImages) {
isOsImagePresent, err = isImagePresent(newURL)
if err != nil {
return err
}
}
}

if isOsImagePresent {
Expand Down