@@ -20,6 +20,7 @@ import (
20
20
utilerrors "k8s.io/apimachinery/pkg/util/errors"
21
21
"k8s.io/apimachinery/pkg/util/yaml"
22
22
"k8s.io/client-go/kubernetes/scheme"
23
+ "k8s.io/klog/v2"
23
24
)
24
25
25
26
const (
@@ -422,3 +423,84 @@ func addIfNotDuplicateResource(manifest Manifest, resourceIds map[resourceId]boo
422
423
}
423
424
return fmt .Errorf ("duplicate resource: (%s)" , manifest .id )
424
425
}
426
+
427
+ // InclusionConfiguration configures manifest inclusion, so
428
+ // callers can opt in to new filtering options instead of having to
429
+ // update existing call-sites, even if they do not need a new
430
+ // filtering option.
431
+ type InclusionConfiguration struct {
432
+ // ExcludeIdentifier, if non-nil, excludes manifests that match the exclusion identifier.
433
+ ExcludeIdentifier * string
434
+
435
+ // RequiredFeatureSet, if non-nil, excludes manifests unless they match the desired feature set.
436
+ RequiredFeatureSet * string
437
+
438
+ // Profile, if non-nil, excludes manifests unless they match the cluster profile.
439
+ Profile * string
440
+
441
+ // Capabilities, if non-nil, excludes manifests unless they match the enabled cluster capabilities.
442
+ Capabilities * configv1.ClusterVersionCapabilitiesStatus
443
+
444
+ // Overrides excludes manifests for overridden resources.
445
+ Overrides []configv1.ComponentOverride
446
+
447
+ // Platform, if non-nil, excludes CredentialsRequests manifests unless they match the infrastructure platform.
448
+ Platform * string
449
+ }
450
+
451
+ // GetImplicitlyEnabledCapabilities returns a set of capabilities that are implicitly enabled after a cluster update.
452
+ // The arguments are two sets of manifests, manifest inclusion configuration, and
453
+ // a set of capabilities that are implicitly enabled on the cluster, i.e., the capabilities
454
+ // that are NOT specified in the cluster version but has to considered enabled on the cluster.
455
+ // The manifest inclusion configuration is used to determine if a manifest should be included.
456
+ // In other words, whether, or not the cluster version operator reconcile that manifest on the cluster.
457
+ // The two sets of manifests are respectively from the release that is currently running on the cluster and
458
+ // from the release that the cluster is updated to.
459
+ func GetImplicitlyEnabledCapabilities (
460
+ updatePayloadManifests []Manifest ,
461
+ currentPayloadManifests []Manifest ,
462
+ manifestInclusionConfiguration InclusionConfiguration ,
463
+ currentImplicitlyEnabled sets.Set [configv1.ClusterVersionCapability ],
464
+ ) sets.Set [configv1.ClusterVersionCapability ] {
465
+ ret := currentImplicitlyEnabled .Clone ()
466
+ for _ , updateManifest := range updatePayloadManifests {
467
+ updateManErr := updateManifest .IncludeAllowUnknownCapabilities (
468
+ manifestInclusionConfiguration .ExcludeIdentifier ,
469
+ manifestInclusionConfiguration .RequiredFeatureSet ,
470
+ manifestInclusionConfiguration .Profile ,
471
+ manifestInclusionConfiguration .Capabilities ,
472
+ manifestInclusionConfiguration .Overrides ,
473
+ true ,
474
+ )
475
+ // update manifest is enabled, no need to check
476
+ if updateManErr == nil {
477
+ continue
478
+ }
479
+ for _ , currentManifest := range currentPayloadManifests {
480
+ if ! updateManifest .SameResourceID (currentManifest ) {
481
+ continue
482
+ }
483
+ // current manifest is disabled, no need to check
484
+ if err := currentManifest .IncludeAllowUnknownCapabilities (
485
+ manifestInclusionConfiguration .ExcludeIdentifier ,
486
+ manifestInclusionConfiguration .RequiredFeatureSet ,
487
+ manifestInclusionConfiguration .Profile ,
488
+ manifestInclusionConfiguration .Capabilities ,
489
+ manifestInclusionConfiguration .Overrides ,
490
+ true ,
491
+ ); err != nil {
492
+ continue
493
+ }
494
+ newImplicitlyEnabled := sets .New [configv1.ClusterVersionCapability ](updateManifest .GetManifestCapabilities ()... ).
495
+ Difference (sets .New [configv1.ClusterVersionCapability ](currentManifest .GetManifestCapabilities ()... )).
496
+ Difference (currentImplicitlyEnabled ).
497
+ Difference (sets .New [configv1.ClusterVersionCapability ](manifestInclusionConfiguration .Capabilities .EnabledCapabilities ... ))
498
+ ret = ret .Union (newImplicitlyEnabled )
499
+ if newImplicitlyEnabled .Len () > 0 {
500
+ klog .V (2 ).Infof ("%s has changed and is now part of one or more disabled capabilities. The following capabilities will be implicitly enabled: %s" ,
501
+ updateManifest .String (), sets .List (newImplicitlyEnabled ))
502
+ }
503
+ }
504
+ }
505
+ return ret
506
+ }
0 commit comments