Skip to content

Commit 88d0075

Browse files
committed
extract: figure out the target version from the pullspec
1 parent 6bb3755 commit 88d0075

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

pkg/cli/admin/release/extract.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,22 @@ func (o *ExtractOptions) Run(ctx context.Context) error {
354354
}
355355
}
356356

357+
var versionInImageConfig string
358+
opts.ImageConfigCallback = func(imageConfig *dockerv1client.DockerImageConfig) {
359+
if imageConfig == nil {
360+
klog.Info("Cannot retrieve the version because no image configuration is provided in the image to extract")
361+
return
362+
}
363+
if c := imageConfig.Config; c != nil {
364+
if v, ok := c.Labels["io.openshift.release"]; ok {
365+
klog.V(2).Infof("Retrieved the version from image configuration in the image to extract: %s", v)
366+
versionInImageConfig = v
367+
} else {
368+
klog.Info("Cannot retrieve the version from image configuration in the image to extract")
369+
}
370+
}
371+
}
372+
357373
var manifestsCallbacks []func(string, []manifest.Manifest, io.Reader, []configv1.ClusterVersionCapability) (bool, error)
358374

359375
var needEnabledCapabilities bool
@@ -371,9 +387,9 @@ func (o *ExtractOptions) Run(ctx context.Context) error {
371387
}
372388
if o.InstallConfig == "" {
373389
needEnabledCapabilities = true
374-
inclusionConfig, err = findClusterIncludeConfig(ctx, o.RESTConfig, reportedVersion)
390+
inclusionConfig, err = findClusterIncludeConfig(ctx, o.RESTConfig, reportedVersion, versionInImageConfig)
375391
} else {
376-
inclusionConfig, err = findClusterIncludeConfigFromInstallConfig(ctx, o.InstallConfig, reportedVersion)
392+
inclusionConfig, err = findClusterIncludeConfigFromInstallConfig(ctx, o.InstallConfig, reportedVersion, versionInImageConfig)
377393
context = o.InstallConfig
378394
}
379395
if err != nil {

pkg/cli/admin/release/extract_tools.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ func (mr *ManifestReceiver) TarEntryCallbackDoneCallback() error {
12701270
return nil
12711271
}
12721272

1273-
func findClusterIncludeConfigFromInstallConfig(_ context.Context, installConfigPath, reportedVersion string) (manifestInclusionConfiguration, error) {
1273+
func findClusterIncludeConfigFromInstallConfig(_ context.Context, installConfigPath, reportedVersion, versionInImageConfig string) (manifestInclusionConfiguration, error) {
12741274
config := manifestInclusionConfiguration{}
12751275

12761276
installConfigBytes, err := os.ReadFile(installConfigPath)
@@ -1299,21 +1299,23 @@ func findClusterIncludeConfigFromInstallConfig(_ context.Context, installConfigP
12991299
if enabled, ok := configv1.ClusterVersionCapabilitySets[data.Capabilities.BaselineCapabilitySet]; !ok {
13001300
return config, fmt.Errorf("unrecognized baselineCapabilitySet %q", data.Capabilities.BaselineCapabilitySet)
13011301
} else {
1302-
if data.Capabilities.BaselineCapabilitySet == configv1.ClusterVersionCapabilitySetCurrent {
1303-
klog.Infof("If the eventual cluster will not be the same minor version as this %s 'oc', the actual %s capability set may differ.", reportedVersion, data.Capabilities.BaselineCapabilitySet)
1302+
if reportedVersion != versionInImageConfig {
1303+
if data.Capabilities.BaselineCapabilitySet == configv1.ClusterVersionCapabilitySetCurrent {
1304+
klog.Infof("The eventual cluster %s will not be the same minor version as this %s 'oc', the actual %s capability set may differ.", versionInImageConfig, reportedVersion, data.Capabilities.BaselineCapabilitySet)
1305+
} else {
1306+
klog.Infof("The eventual cluster %s will not be the same minor version as this %s 'oc', the known capability sets may differ.", versionInImageConfig, reportedVersion)
1307+
}
13041308
}
13051309
config.Capabilities.EnabledCapabilities = append(config.Capabilities.EnabledCapabilities, enabled...)
13061310
}
13071311
config.Capabilities.EnabledCapabilities = append(config.Capabilities.EnabledCapabilities, data.Capabilities.AdditionalEnabledCapabilities...)
1308-
1309-
klog.Infof("If the eventual cluster will not be the same minor version as this %s 'oc', the known capability sets may differ.", reportedVersion)
13101312
config.Capabilities.KnownCapabilities = configv1.KnownClusterVersionCapabilities
13111313
}
13121314

13131315
return config, nil
13141316
}
13151317

1316-
func findClusterIncludeConfig(ctx context.Context, restConfig *rest.Config, reportedVersion string) (manifestInclusionConfiguration, error) {
1318+
func findClusterIncludeConfig(ctx context.Context, restConfig *rest.Config, reportedVersion, versionInImageConfig string) (manifestInclusionConfiguration, error) {
13171319
config := manifestInclusionConfiguration{}
13181320

13191321
client, err := configv1client.NewForConfig(restConfig)
@@ -1338,11 +1340,14 @@ func findClusterIncludeConfig(ctx context.Context, restConfig *rest.Config, repo
13381340
capSet = capabilitiesSpec.BaselineCapabilitySet
13391341
}
13401342
deepCopy := clusterVersion.Status.Capabilities.DeepCopy()
1341-
if capSet == configv1.ClusterVersionCapabilitySetCurrent {
1342-
klog.Infof("If the eventual cluster will not be the same minor version as this %s 'oc', the actual %s capability set may differ.", reportedVersion, capSet)
1343+
if reportedVersion != versionInImageConfig {
1344+
if capSet == configv1.ClusterVersionCapabilitySetCurrent {
1345+
klog.Infof("The eventual cluster %s will not be the same minor version as this %s 'oc', the actual %s capability set may differ.", versionInImageConfig, reportedVersion, capSet)
1346+
} else {
1347+
klog.Infof("The eventual cluster %s will not be the same minor version as this %s 'oc', the known capability sets may differ.", versionInImageConfig, reportedVersion)
1348+
}
13431349
}
13441350
deepCopy.EnabledCapabilities = append(deepCopy.EnabledCapabilities, configv1.ClusterVersionCapabilitySets[capSet]...)
1345-
klog.Infof("If the eventual cluster will not be the same minor version as this %s 'oc', the known capability sets may differ.", reportedVersion)
13461351
deepCopy.KnownCapabilities = configv1.KnownClusterVersionCapabilities
13471352
config.Capabilities = deepCopy
13481353
}

pkg/cli/image/extract/extract.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ type ExtractOptions struct {
141141

142142
genericiooptions.IOStreams
143143

144+
// ImageConfigCallback is invoked once image config retrieved
145+
ImageConfigCallback func(imageConfig *dockerv1client.DockerImageConfig)
144146
// ImageMetadataCallback is invoked once per image retrieved, and may be called in parallel if
145147
// MaxPerRegistry is set higher than 1.
146148
ImageMetadataCallback ImageMetadataFunc
@@ -421,6 +423,9 @@ func (o *ExtractOptions) Run() error {
421423
}
422424

423425
imageConfig, layers, err := imagemanifest.ManifestToImageConfig(ctx, srcManifest, repo.Blobs(ctx), location)
426+
if o.ImageConfigCallback != nil {
427+
o.ImageConfigCallback(imageConfig)
428+
}
424429
if err != nil {
425430
return fmt.Errorf("unable to parse image %s: %v", from, err)
426431
}

0 commit comments

Comments
 (0)