Skip to content

Commit 7056f53

Browse files
committed
NO-JIRA: Include the target version in the logging
Before this full, the logging was only for the case that `findClusterIncludeConfigFromInstallConfig` is called, i.e., the path from an install-config file is provided. This pull extends it to the case where the configuration is taken from the current cluster. Another change from the pull is that the logging messages include the target version that is determined by inspecting the release image. The implementation for this is adding a new callback `ImageConfigCallback`.
1 parent ea5c720 commit 7056f53

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

pkg/cli/admin/release/extract.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,28 @@ func (o *ExtractOptions) Run(ctx context.Context) error {
349349
}
350350
}
351351

352+
// versionInImageConfig stores the version from the label of the image
353+
// At the moment it is used later only for the logging purpose and thus is not blocking if failures occur upon getting its value
354+
var versionInImageConfig string
355+
opts.ImageConfigCallback = func(imageConfig *dockerv1client.DockerImageConfig) {
356+
if imageConfig == nil {
357+
// This should never happen
358+
klog.Error("Cannot retrieve the version because no image configuration is provided in the image to extract")
359+
return
360+
}
361+
if imageConfig.Config == nil {
362+
klog.Error("Cannot retrieve the version from image configuration in the image to extract because it has no configuration")
363+
return
364+
}
365+
v, ok := imageConfig.Config.Labels["io.openshift.release"]
366+
if !ok {
367+
klog.Error("Cannot retrieve the version from image configuration in the image to extract because it does not have the required label 'io.openshift.release'")
368+
return
369+
}
370+
klog.V(2).Infof("Retrieved the version from image configuration in the image to extract: %s", v)
371+
versionInImageConfig = v
372+
}
373+
352374
var manifestErrs []error
353375
// o.ExtractManifests implies o.File == ""
354376
if o.ExtractManifests {
@@ -359,9 +381,9 @@ func (o *ExtractOptions) Run(ctx context.Context) error {
359381
context := "connected cluster"
360382
inclusionConfig := manifestInclusionConfiguration{}
361383
if o.InstallConfig == "" {
362-
inclusionConfig, err = findClusterIncludeConfig(ctx, o.RESTConfig)
384+
inclusionConfig, err = findClusterIncludeConfig(ctx, o.RESTConfig, versionInImageConfig)
363385
} else {
364-
inclusionConfig, err = findClusterIncludeConfigFromInstallConfig(ctx, o.InstallConfig)
386+
inclusionConfig, err = findClusterIncludeConfigFromInstallConfig(ctx, o.InstallConfig, versionInImageConfig)
365387
context = o.InstallConfig
366388
}
367389
if err != nil {

pkg/cli/admin/release/extract_tools.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,16 +1167,29 @@ func copyAndReplace(errorOutput io.Writer, w io.Writer, r io.Reader, bufferSize
11671167

11681168
}
11691169

1170-
func findClusterIncludeConfigFromInstallConfig(ctx context.Context, installConfigPath string) (manifestInclusionConfiguration, error) {
1171-
config := manifestInclusionConfiguration{}
1172-
1170+
// logCapabilitySetMayDiffer logs the messages if the oc-cli version is not the same as the target version
1171+
// * the enabled capability set may differ if the baseline is vCurrent, and
1172+
// * the known capability set may differ
1173+
// It raises an error if it fails to determine the oc-cli version.
1174+
func logCapabilitySetMayDiffer(capabilitiesSpec *configv1.ClusterVersionCapabilitiesSpec, targetVersion string) error {
11731175
clientVersion, reportedVersion, err := version.ExtractVersion()
11741176
if err != nil {
1175-
return config, err
1177+
return fmt.Errorf("failed to determine the version of 'oc': %w", err)
11761178
}
11771179
if reportedVersion == "" {
11781180
reportedVersion = clientVersion.String()
11791181
}
1182+
if reportedVersion != targetVersion {
1183+
if capabilitiesSpec != nil && capabilitiesSpec.BaselineCapabilitySet == configv1.ClusterVersionCapabilitySetCurrent {
1184+
klog.Infof("The eventual cluster %s will not be the same minor version as this %s 'oc', the actual %s capability set may differ.", targetVersion, reportedVersion, capabilitiesSpec.BaselineCapabilitySet)
1185+
}
1186+
klog.Infof("The eventual cluster %s will not be the same minor version as this %s 'oc', the known capability set may differ.", targetVersion, reportedVersion)
1187+
}
1188+
return nil
1189+
}
1190+
1191+
func findClusterIncludeConfigFromInstallConfig(ctx context.Context, installConfigPath string, versionInImageConfig string) (manifestInclusionConfiguration, error) {
1192+
config := manifestInclusionConfiguration{}
11801193

11811194
installConfigBytes, err := os.ReadFile(installConfigPath)
11821195
if err != nil {
@@ -1204,21 +1217,19 @@ func findClusterIncludeConfigFromInstallConfig(ctx context.Context, installConfi
12041217
if enabled, ok := configv1.ClusterVersionCapabilitySets[data.Capabilities.BaselineCapabilitySet]; !ok {
12051218
return config, fmt.Errorf("unrecognized baselineCapabilitySet %q", data.Capabilities.BaselineCapabilitySet)
12061219
} else {
1207-
if data.Capabilities.BaselineCapabilitySet == configv1.ClusterVersionCapabilitySetCurrent {
1208-
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)
1220+
if err := logCapabilitySetMayDiffer(data.Capabilities, versionInImageConfig); err != nil {
1221+
return config, err
12091222
}
12101223
config.Capabilities.EnabledCapabilities = append(config.Capabilities.EnabledCapabilities, enabled...)
12111224
}
12121225
config.Capabilities.EnabledCapabilities = append(config.Capabilities.EnabledCapabilities, data.Capabilities.AdditionalEnabledCapabilities...)
1213-
1214-
klog.Infof("If the eventual cluster will not be the same minor version as this %s 'oc', the known capability sets may differ.", reportedVersion)
12151226
config.Capabilities.KnownCapabilities = configv1.KnownClusterVersionCapabilities
12161227
}
12171228

12181229
return config, nil
12191230
}
12201231

1221-
func findClusterIncludeConfig(ctx context.Context, restConfig *rest.Config) (manifestInclusionConfiguration, error) {
1232+
func findClusterIncludeConfig(ctx context.Context, restConfig *rest.Config, versionInImageConfig string) (manifestInclusionConfiguration, error) {
12221233
config := manifestInclusionConfiguration{}
12231234

12241235
client, err := configv1client.NewForConfig(restConfig)
@@ -1250,6 +1261,10 @@ func findClusterIncludeConfig(ctx context.Context, restConfig *rest.Config) (man
12501261
config.Capabilities.EnabledCapabilities = append(config.Capabilities.EnabledCapabilities, configv1.ClusterVersionCapabilityMachineAPI, build, deploymentConfig, imageRegistry)
12511262
config.Capabilities.KnownCapabilities = append(config.Capabilities.KnownCapabilities, configv1.ClusterVersionCapabilityMachineAPI, build, deploymentConfig, imageRegistry)
12521263
}
1264+
1265+
if err := logCapabilitySetMayDiffer(clusterVersion.Spec.Capabilities, versionInImageConfig); err != nil {
1266+
return config, err
1267+
}
12531268
}
12541269

12551270
if infrastructure, err := client.Infrastructures().Get(ctx, "cluster", metav1.GetOptions{}); err != nil {

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
if err != nil {
422424
return fmt.Errorf("unable to parse image %s: %v", from, err)
423425
}
426+
if o.ImageConfigCallback != nil {
427+
o.ImageConfigCallback(imageConfig)
428+
}
424429

425430
if mapping.ConditionFn != nil {
426431
ok, err := mapping.ConditionFn(&mapping, location.Manifest, imageConfig)

0 commit comments

Comments
 (0)