Skip to content

Commit 6fe4a71

Browse files
Merge pull request #1188 from petr-muller/ota-1531-03-load-metadata-earlyy
OTA-1531: [3/x] cvo: read version from release metadata on startup
2 parents 5d71fb4 + a6cf93c commit 6fe4a71

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

pkg/payload/payload.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,19 +308,20 @@ func loadPayloadMetadata(releaseDir, releaseImage string) (*Update, error) {
308308
if err != nil {
309309
return nil, err
310310
}
311-
release.Image = releaseImage
312-
313-
imageRef, err := loadImageReferences(releaseDir)
314-
if err != nil {
315-
return nil, err
316-
}
317311

318312
arch := string(release.Architecture)
319313
if arch == "" {
320314
arch = runtime.GOARCH
321315
klog.V(2).Infof("Architecture from %s (%s) retrieved from runtime: %q", cincinnatiJSONFile, release.Version, arch)
322316
}
323317

318+
release.Image = releaseImage
319+
320+
imageRef, err := loadImageReferences(releaseDir)
321+
if err != nil {
322+
return nil, err
323+
}
324+
324325
if imageRef.Name != release.Version {
325326
return nil, fmt.Errorf("Version from %s (%s) differs from %s (%s)", imageReferencesFile, imageRef.Name, cincinnatiJSONFile, release.Version)
326327
}
@@ -358,6 +359,17 @@ func loadPayloadTasks(releaseDir, cvoDir, releaseImage, clusterProfile string) [
358359
}}
359360
}
360361

362+
// RootPath represents a path to the directory containing the payload
363+
type RootPath string
364+
365+
const DefaultRootPath = RootPath(DefaultPayloadDir)
366+
367+
// LoadReleaseMetadata loads the release metadata from the appropriate location inside the payload directory
368+
func (p RootPath) LoadReleaseMetadata() (configv1.Release, error) {
369+
releaseDir := filepath.Join(string(p), ReleaseManifestDir)
370+
return loadReleaseMetadata(releaseDir)
371+
}
372+
361373
func loadReleaseMetadata(releaseDir string) (configv1.Release, error) {
362374
var release configv1.Release
363375
path := filepath.Join(releaseDir, cincinnatiJSONFile)

pkg/start/start.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,31 @@ func (o *Options) Run(ctx context.Context) error {
189189
return err
190190
}
191191

192+
payloadRoot := payload.DefaultRootPath
193+
if o.PayloadOverride != "" {
194+
payloadRoot = payload.RootPath(o.PayloadOverride)
195+
}
196+
197+
cvoOcpVersion := "0.0.1-snapshot"
198+
// Peek at the local release metadata to determine the version of OCP this CVO belongs to. This assumes the CVO is
199+
// executing in a container from the payload image. Full payload content is only read later once leader lease is
200+
// acquired, and here we should only read as little data as possible to determine the version so we can establish
201+
// enabled feature gate checker for all following code.
202+
//
203+
// We cannot refuse to start CVO if for some reason we cannot determine the OCP version on startup from the local
204+
// release metadata. The only consequence is we fail to determine enabled/disabled feature gates and will have to use
205+
// some defaults.
206+
releaseMetadata, err := payloadRoot.LoadReleaseMetadata()
207+
switch {
208+
case err != nil:
209+
klog.Warningf("Failed to read release metadata to determine OCP version for this CVO (will use placeholder version %q): %v", cvoOcpVersion, err)
210+
case releaseMetadata.Version == "":
211+
klog.Warningf("Version missing from release metadata, cannot determine OCP version for this CVO (will use placeholder version %q): %v", cvoOcpVersion, err)
212+
default:
213+
cvoOcpVersion = releaseMetadata.Version
214+
klog.Infof("Determined OCP version for this CVO: %q", cvoOcpVersion)
215+
}
216+
192217
// initialize the controllers and attempt to load the payload information
193218
controllerCtx, err := o.NewControllerContext(cb)
194219
if err != nil {

0 commit comments

Comments
 (0)