@@ -14,7 +14,6 @@ import (
1414 "io"
1515 "os"
1616 "path/filepath"
17- "regexp"
1817 "runtime"
1918 "sort"
2019 "strings"
@@ -1238,18 +1237,33 @@ func findClusterIncludeConfig(ctx context.Context, restConfig *rest.Config) (man
12381237 config .Overrides = clusterVersion .Spec .Overrides
12391238 config .Capabilities = & clusterVersion .Status .Capabilities
12401239
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 )
1240+ // The set of the capabilities defined in configv1.ClusterVersionCapabilitySets may grow over time.
1241+ // Here we refresh "known" and "enabled" from lib so the new capabilities are included.
1242+ known := sets .New [configv1.ClusterVersionCapability ]()
1243+ for _ , s := range configv1 .ClusterVersionCapabilitySets {
1244+ known .Insert (s ... )
12521245 }
1246+ previouslyKnown := sets .New [configv1.ClusterVersionCapability ](config .Capabilities .KnownCapabilities ... )
1247+ config .Capabilities .KnownCapabilities = previouslyKnown .Union (known ).UnsortedList ()
1248+
1249+ key := configv1 .ClusterVersionCapabilitySetCurrent
1250+ if clusterVersion .Spec .Capabilities != nil && clusterVersion .Spec .Capabilities .BaselineCapabilitySet != "" {
1251+ key = clusterVersion .Spec .Capabilities .BaselineCapabilitySet
1252+ }
1253+ enabled := sets .New [configv1.ClusterVersionCapability ](configv1 .ClusterVersionCapabilitySets [key ]... )
1254+ // Without downloading the payload that is running on the cluster, it is hard to collect all the enabled capabilities.
1255+ // We may create a manifest in dry-run mode on the cluster and check if the output contains the existing error
1256+ // which indicates the capabilities of the manifest are all enabled. We have to wait until all manifests are checked
1257+ // this way to collect the complete set of enabled capabilities.It might not be worth the effort to calculate the
1258+ // exact enabled capabilities.
1259+ // Instead, newly introduced capabilities are blindly enabled and some of them might not be actually enabled on the cluster.
1260+ // As a result, unexpected manifests could be included. The number of such manifests is likely small, provided that
1261+ // only a small amount of capabilities are added over time and that happens only for minor level updates:
1262+ // #C(4.11)=4 -> #C(4.17)=15, averagely less than two per minor update.
1263+ // https://docs.openshift.com/container-platform/4.17/installing/overview/cluster-capabilities.html
1264+ deltaKnown := known .Difference (previouslyKnown )
1265+ enabled = enabled .Union (deltaKnown )
1266+ config .Capabilities .EnabledCapabilities = sets .New [configv1.ClusterVersionCapability ](config .Capabilities .EnabledCapabilities ... ).Union (enabled ).UnsortedList ()
12531267 }
12541268
12551269 if infrastructure , err := client .Infrastructures ().Get (ctx , "cluster" , metav1.GetOptions {}); err != nil {
0 commit comments