@@ -14,7 +14,6 @@ import (
1414 "io"
1515 "os"
1616 "path/filepath"
17- "regexp"
1817 "runtime"
1918 "sort"
2019 "strings"
@@ -43,7 +42,6 @@ import (
4342 "github.com/openshift/oc/pkg/cli/admin/internal/codesign"
4443 "github.com/openshift/oc/pkg/cli/image/extract"
4544 "github.com/openshift/oc/pkg/cli/image/imagesource"
46- "github.com/openshift/oc/pkg/version"
4745)
4846
4947// extractTarget describes how a file in the release image can be extracted to disk.
@@ -1167,17 +1165,9 @@ func copyAndReplace(errorOutput io.Writer, w io.Writer, r io.Reader, bufferSize
11671165
11681166}
11691167
1170- func findClusterIncludeConfigFromInstallConfig (ctx context.Context , installConfigPath string ) (manifestInclusionConfiguration , error ) {
1168+ func findClusterIncludeConfigFromInstallConfig (ctx context.Context , installConfigPath , ocVersion string ) (manifestInclusionConfiguration , error ) {
11711169 config := manifestInclusionConfiguration {}
11721170
1173- clientVersion , reportedVersion , err := version .ExtractVersion ()
1174- if err != nil {
1175- return config , err
1176- }
1177- if reportedVersion == "" {
1178- reportedVersion = clientVersion .String ()
1179- }
1180-
11811171 installConfigBytes , err := os .ReadFile (installConfigPath )
11821172 if err != nil {
11831173 return config , err
@@ -1205,20 +1195,20 @@ func findClusterIncludeConfigFromInstallConfig(ctx context.Context, installConfi
12051195 return config , fmt .Errorf ("unrecognized baselineCapabilitySet %q" , data .Capabilities .BaselineCapabilitySet )
12061196 } else {
12071197 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 )
1198+ klog .Infof ("If the eventual cluster will not be the same minor version as this %s 'oc', the actual %s capability set may differ." , ocVersion , data .Capabilities .BaselineCapabilitySet )
12091199 }
12101200 config .Capabilities .EnabledCapabilities = append (config .Capabilities .EnabledCapabilities , enabled ... )
12111201 }
12121202 config .Capabilities .EnabledCapabilities = append (config .Capabilities .EnabledCapabilities , data .Capabilities .AdditionalEnabledCapabilities ... )
12131203
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 )
1204+ klog .Infof ("If the eventual cluster will not be the same minor version as this %s 'oc', the known capability sets may differ." , ocVersion )
12151205 config .Capabilities .KnownCapabilities = configv1 .KnownClusterVersionCapabilities
12161206 }
12171207
12181208 return config , nil
12191209}
12201210
1221- func findClusterIncludeConfig (ctx context.Context , restConfig * rest.Config ) (manifestInclusionConfiguration , error ) {
1211+ func findClusterIncludeConfig (ctx context.Context , restConfig * rest.Config , ocVersion string ) (manifestInclusionConfiguration , error ) {
12221212 config := manifestInclusionConfiguration {}
12231213
12241214 client , err := configv1client .NewForConfig (restConfig )
@@ -1238,18 +1228,30 @@ func findClusterIncludeConfig(ctx context.Context, restConfig *rest.Config) (man
12381228 config .Overrides = clusterVersion .Spec .Overrides
12391229 config .Capabilities = & clusterVersion .Status .Capabilities
12401230
1241- // FIXME: eventually pull in GetImplicitlyEnabledCapabilities from https://github.com/openshift/cluster-version-operator/blob/86e24d66119a73f50282b66a8d6f2e3518aa0e15/pkg/payload/payload.go#L237-L240 for cases where a minor update would implicitly enable some additional capabilities. For now, 4.13 to 4.14 will always enable MachineAPI, ImageRegistry, etc..
1242- currentVersion := clusterVersion .Status .Desired .Version
1243- matches := regexp .MustCompile (`^(\d+[.]\d+)[.].*` ).FindStringSubmatch (currentVersion )
1244- if len (matches ) < 2 {
1245- return config , fmt .Errorf ("failed to parse major.minor version from ClusterVersion status.desired.version %q" , currentVersion )
1246- } else if matches [1 ] == "4.13" {
1247- build := configv1 .ClusterVersionCapability ("Build" )
1248- deploymentConfig := configv1 .ClusterVersionCapability ("DeploymentConfig" )
1249- imageRegistry := configv1 .ClusterVersionCapability ("ImageRegistry" )
1250- config .Capabilities .EnabledCapabilities = append (config .Capabilities .EnabledCapabilities , configv1 .ClusterVersionCapabilityMachineAPI , build , deploymentConfig , imageRegistry )
1251- config .Capabilities .KnownCapabilities = append (config .Capabilities .KnownCapabilities , configv1 .ClusterVersionCapabilityMachineAPI , build , deploymentConfig , imageRegistry )
1231+ known := sets .New [configv1.ClusterVersionCapability ](configv1 .KnownClusterVersionCapabilities ... )
1232+ previouslyKnown := sets .New [configv1.ClusterVersionCapability ](config .Capabilities .KnownCapabilities ... )
1233+ config .Capabilities .KnownCapabilities = previouslyKnown .Union (known ).UnsortedList ()
1234+
1235+ // refresh BaselineCapabilitySet as more capabilities might be included across versions
1236+ key := configv1 .ClusterVersionCapabilitySetCurrent
1237+ if clusterVersion .Spec .Capabilities != nil && clusterVersion .Spec .Capabilities .BaselineCapabilitySet != "" {
1238+ key = clusterVersion .Spec .Capabilities .BaselineCapabilitySet
1239+ }
1240+ enabled := sets .New [configv1.ClusterVersionCapability ](configv1 .ClusterVersionCapabilitySets [key ]... )
1241+ // The set of the capabilities may grow over time. Without downloading the payload that is running on the cluster,
1242+ // it is hard to project all the enabled capabilities after upgrading to the incoming release.
1243+ // As an approximation, all newly introduced capabilities are considered enabled to check if a manifest from the
1244+ // release should be included while some of them might not be actually enabled on the cluster.
1245+ // As a result, unexpected manifests could be included. The number of such manifests is likely small, provided that
1246+ // only a small amount of capabilities are added over time and that happens only for minor level updates:
1247+ // #Cap(4.11)=4 -> #Cap(4.17)=15, averagely less than two per minor update.
1248+ // https://docs.openshift.com/container-platform/4.17/installing/overview/cluster-capabilities.html
1249+ deltaKnown := known .Difference (previouslyKnown )
1250+ if deltaKnown .Len () > 0 {
1251+ klog .Infof ("The new capabilities that are introduced in this oc version %s are considered enabled on checking if a manifest is included: %s. They may be disabled on the eventual cluster" , ocVersion , deltaKnown .UnsortedList ())
12521252 }
1253+ enabled = enabled .Union (deltaKnown )
1254+ config .Capabilities .EnabledCapabilities = sets .New [configv1.ClusterVersionCapability ](config .Capabilities .EnabledCapabilities ... ).Union (enabled ).UnsortedList ()
12531255 }
12541256
12551257 if infrastructure , err := client .Infrastructures ().Get (ctx , "cluster" , metav1.GetOptions {}); err != nil {
0 commit comments