Skip to content

Commit c63310a

Browse files
committed
daemon: Support unpivoted images
Today the RHCOS bootimages come "prepivoted"; they have a custom origin set to the `machine-os-content` that matches. The idea here is to avoid an extra reboot. In practice we're always going to be updating and rebooting today, because we don't have a mechanism to update bootimages: openshift/os#381 I plan to change the RHCOS build system to stop "prepivoting"; the oscontainer will be pushed *after* the bootimages. This breaks a complicated dependency and ensures that the RHCOS "source of truth" is the cosa storage. Also, this allows one to use the MCD when e.g. booting Fedora CoreOS. Closes: openshift#981
1 parent 70405d4 commit c63310a

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

pkg/daemon/daemon.go

+5
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,11 @@ func compareOSImageURL(current, desired string) (bool, error) {
11541154
return true, nil
11551155
}
11561156

1157+
// If we're not in pivot:// right now, then it must not match.
1158+
if current == "" {
1159+
return false, nil
1160+
}
1161+
11571162
if current == desired {
11581163
return true, nil
11591164
}

pkg/daemon/daemon_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
igntypes "github.com/coreos/ignition/config/v2_2/types"
13+
"github.com/stretchr/testify/assert"
1314
"github.com/stretchr/testify/require"
1415
"github.com/vincent-petithory/dataurl"
1516
corev1 "k8s.io/api/core/v1"
@@ -128,6 +129,9 @@ func TestCompareOSImageURL(t *testing.T) {
128129
if m || err == nil {
129130
t.Fatalf("Expected err")
130131
}
132+
m, err = compareOSImageURL("", refA)
133+
assert.False(t, m)
134+
assert.Nil(t, err)
131135
}
132136

133137
type fixture struct {

pkg/daemon/rpm-ostree.go

+18-10
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,16 @@ func (r *RpmOstreeClient) GetStatus() (string, error) {
114114
}
115115

116116
// GetBootedOSImageURL returns the image URL as well as the OSTree version (for logging)
117+
// Returns the empty string if the host doesn't have a custom origin that matches pivot://
118+
// (This could be the case for e.g. FCOS, or a future RHCOS which comes not-pivoted by default)
117119
func (r *RpmOstreeClient) GetBootedOSImageURL() (string, string, error) {
118120
bootedDeployment, err := r.getBootedDeployment()
119121
if err != nil {
120122
return "", "", err
121123
}
122124

123-
// the canonical image URL is stored in the custom origin field by the pivot tool
124-
osImageURL := "<not pivoted>"
125+
// the canonical image URL is stored in the custom origin field.
126+
osImageURL := ""
125127
if len(bootedDeployment.CustomOrigin) > 0 {
126128
if strings.HasPrefix(bootedDeployment.CustomOrigin[0], "pivot://") {
127129
osImageURL = bootedDeployment.CustomOrigin[0][len("pivot://"):]
@@ -150,7 +152,11 @@ func (r *RpmOstreeClient) PullAndRebase(container string, keep bool) (imgid stri
150152
if strings.HasPrefix(defaultDeployment.CustomOrigin[0], "pivot://") {
151153
previousPivot = defaultDeployment.CustomOrigin[0][len("pivot://"):]
152154
glog.Infof("Previous pivot: %s", previousPivot)
155+
} else {
156+
glog.Infof("Previous custom origin: %s", defaultDeployment.CustomOrigin[0])
153157
}
158+
} else {
159+
glog.Info("Current origin is not custom")
154160
}
155161

156162
var authArgs []string
@@ -168,14 +174,16 @@ func (r *RpmOstreeClient) PullAndRebase(container string, keep bool) (imgid stri
168174
args = append(args, container)
169175
pivotutils.RunExt(false, numRetriesNetCommands, "podman", args...)
170176
} else {
171-
var targetMatched bool
172-
targetMatched, err = compareOSImageURL(previousPivot, container)
173-
if err != nil {
174-
return
175-
}
176-
if targetMatched {
177-
changed = false
178-
return
177+
if previousPivot != "" {
178+
var targetMatched bool
179+
targetMatched, err = compareOSImageURL(previousPivot, container)
180+
if err != nil {
181+
return
182+
}
183+
if targetMatched {
184+
changed = false
185+
return
186+
}
179187
}
180188

181189
// Pull the image

0 commit comments

Comments
 (0)