diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index 18f737f9d0..d25eff22b3 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -1154,6 +1154,11 @@ func compareOSImageURL(current, desired string) (bool, error) { return true, nil } + // If we're not in pivot:// right now, then it must not match. + if current == "" { + return false, nil + } + if current == desired { return true, nil } diff --git a/pkg/daemon/daemon_test.go b/pkg/daemon/daemon_test.go index a09194e70e..9334c604e5 100644 --- a/pkg/daemon/daemon_test.go +++ b/pkg/daemon/daemon_test.go @@ -10,6 +10,7 @@ import ( "time" igntypes "github.com/coreos/ignition/config/v2_2/types" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/vincent-petithory/dataurl" corev1 "k8s.io/api/core/v1" @@ -128,6 +129,9 @@ func TestCompareOSImageURL(t *testing.T) { if m || err == nil { t.Fatalf("Expected err") } + m, err = compareOSImageURL("", refA) + assert.False(t, m) + assert.Nil(t, err) } type fixture struct { diff --git a/pkg/daemon/rpm-ostree.go b/pkg/daemon/rpm-ostree.go index 90c01d30a9..eb8a1c81f5 100644 --- a/pkg/daemon/rpm-ostree.go +++ b/pkg/daemon/rpm-ostree.go @@ -114,14 +114,16 @@ func (r *RpmOstreeClient) GetStatus() (string, error) { } // GetBootedOSImageURL returns the image URL as well as the OSTree version (for logging) +// Returns the empty string if the host doesn't have a custom origin that matches pivot:// +// (This could be the case for e.g. FCOS, or a future RHCOS which comes not-pivoted by default) func (r *RpmOstreeClient) GetBootedOSImageURL() (string, string, error) { bootedDeployment, err := r.getBootedDeployment() if err != nil { return "", "", err } - // the canonical image URL is stored in the custom origin field by the pivot tool - osImageURL := "" + // the canonical image URL is stored in the custom origin field. + osImageURL := "" if len(bootedDeployment.CustomOrigin) > 0 { if strings.HasPrefix(bootedDeployment.CustomOrigin[0], "pivot://") { osImageURL = bootedDeployment.CustomOrigin[0][len("pivot://"):] @@ -150,7 +152,11 @@ func (r *RpmOstreeClient) PullAndRebase(container string, keep bool) (imgid stri if strings.HasPrefix(defaultDeployment.CustomOrigin[0], "pivot://") { previousPivot = defaultDeployment.CustomOrigin[0][len("pivot://"):] glog.Infof("Previous pivot: %s", previousPivot) + } else { + glog.Infof("Previous custom origin: %s", defaultDeployment.CustomOrigin[0]) } + } else { + glog.Info("Current origin is not custom") } var authArgs []string @@ -168,14 +174,16 @@ func (r *RpmOstreeClient) PullAndRebase(container string, keep bool) (imgid stri args = append(args, container) pivotutils.RunExt(false, numRetriesNetCommands, "podman", args...) } else { - var targetMatched bool - targetMatched, err = compareOSImageURL(previousPivot, container) - if err != nil { - return - } - if targetMatched { - changed = false - return + if previousPivot != "" { + var targetMatched bool + targetMatched, err = compareOSImageURL(previousPivot, container) + if err != nil { + return + } + if targetMatched { + changed = false + return + } } // Pull the image