Skip to content

Commit bd40eab

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 4cd2c52 commit bd40eab

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
manifestReceiver := ManifestReceiver{skipNames: sets.New[string]("image-references", "release-metadata")}
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
@@ -1168,16 +1168,29 @@ func copyAndReplace(errorOutput io.Writer, w io.Writer, r io.Reader, bufferSize
11681168

11691169
}
11701170

1171-
func findClusterIncludeConfigFromInstallConfig(ctx context.Context, installConfigPath string) (manifestInclusionConfiguration, error) {
1172-
config := manifestInclusionConfiguration{}
1173-
1171+
// logCapabilitySetMayDiffer logs the messages if the oc-cli version is not the same as the target version
1172+
// * the enabled capability set may differ if the baseline is vCurrent, and
1173+
// * the known capability set may differ
1174+
// It raises an error if it fails to determine the oc-cli version.
1175+
func logCapabilitySetMayDiffer(capabilitiesSpec *configv1.ClusterVersionCapabilitiesSpec, targetVersion string) error {
11741176
clientVersion, reportedVersion, err := version.ExtractVersion()
11751177
if err != nil {
1176-
return config, err
1178+
return fmt.Errorf("failed to determine the version of 'oc': %w", err)
11771179
}
11781180
if reportedVersion == "" {
11791181
reportedVersion = clientVersion.String()
11801182
}
1183+
if reportedVersion != targetVersion {
1184+
if capabilitiesSpec != nil && capabilitiesSpec.BaselineCapabilitySet == configv1.ClusterVersionCapabilitySetCurrent {
1185+
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)
1186+
}
1187+
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)
1188+
}
1189+
return nil
1190+
}
1191+
1192+
func findClusterIncludeConfigFromInstallConfig(ctx context.Context, installConfigPath string, versionInImageConfig string) (manifestInclusionConfiguration, error) {
1193+
config := manifestInclusionConfiguration{}
11811194

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

12191230
return config, nil
12201231
}
12211232

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

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

12561271
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)