Skip to content

Commit e2edeb6

Browse files
committed
cvo: read version from release metadata on startup
CVO is typically executed in a Pod using the release payload image, which means its filesystem contains (among other content) the release metadata which the CVO can use to determine its OCP version, which is helpful to establish the feature gate enablement data to drive gated CVO behaviors. It is useful to establish the feature gate enablement checker early in the CVO execution because it broadens the part of CVO code that can contain gated behavior (until the checker is stablished it is not possible to determine whether a gate is enabled or disabled) Loading the full payload is still quite heavy operation and can only be done later in the execution (after the CVO acquires leader lease). The early metadata peek should read and utilize as few data as is necessary to establish the gate checker.
1 parent 4fe21f6 commit e2edeb6

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

pkg/payload/payload.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,17 @@ func loadPayloadTasks(releaseDir, cvoDir, releaseImage, clusterProfile string) [
358358
}}
359359
}
360360

361+
// RootPath represents a path to the directory containing the payload
362+
type RootPath string
363+
364+
const DefaultRootPath = RootPath(DefaultPayloadDir)
365+
366+
// LoadReleaseMetadata loads the release metadata from the appropriate location inside the payload directory
367+
func (p RootPath) LoadReleaseMetadata() (configv1.Release, error) {
368+
releaseDir := filepath.Join(string(p), ReleaseManifestDir)
369+
return loadReleaseMetadata(releaseDir)
370+
}
371+
361372
func loadReleaseMetadata(releaseDir string) (configv1.Release, error) {
362373
var release configv1.Release
363374
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)