-
Notifications
You must be signed in to change notification settings - Fork 198
OTA-1010: Add a new version of GetImplicitlyEnabledCapabilities #1133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-bot
merged 1 commit into
openshift:main
from
hongkailiu:new-GetImplicitlyEnabledCapabilities
May 14, 2025
+101
−118
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Package manifest collects functions about manifests that are going to be lifted to library-go | ||
// https://github.com/openshift/library-go | ||
// Thus it should not depend on any packages from CVO: github.com/openshift/cluster-version-operator/ | ||
package manifest | ||
|
||
import ( | ||
configv1 "github.com/openshift/api/config/v1" | ||
"github.com/openshift/library-go/pkg/manifest" | ||
|
||
"k8s.io/apimachinery/pkg/util/sets" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
// InclusionConfiguration configures manifest inclusion, so | ||
// callers can opt in to new filtering options instead of having to | ||
// update existing call-sites, even if they do not need a new | ||
// filtering option. | ||
type InclusionConfiguration struct { | ||
// ExcludeIdentifier, if non-nil, excludes manifests that match the exclusion identifier. | ||
ExcludeIdentifier *string | ||
|
||
// RequiredFeatureSet, if non-nil, excludes manifests unless they match the desired feature set. | ||
RequiredFeatureSet *string | ||
|
||
// Profile, if non-nil, excludes manifests unless they match the cluster profile. | ||
Profile *string | ||
|
||
// Capabilities, if non-nil, excludes manifests unless they match the enabled cluster capabilities. | ||
Capabilities *configv1.ClusterVersionCapabilitiesStatus | ||
|
||
// Overrides excludes manifests for overridden resources. | ||
Overrides []configv1.ComponentOverride | ||
|
||
// Platform, if non-nil, excludes CredentialsRequests manifests unless they match the infrastructure platform. | ||
Platform *string | ||
} | ||
|
||
// GetImplicitlyEnabledCapabilities returns a set of capabilities that are implicitly enabled after a cluster update. | ||
// The arguments are two sets of manifests, manifest inclusion configuration, and | ||
// a set of capabilities that are implicitly enabled on the cluster, i.e., the capabilities | ||
// that are NOT specified in the cluster version but has to considered enabled on the cluster. | ||
// The manifest inclusion configuration is used to determine if a manifest should be included. | ||
// In other words, whether, or not the cluster version operator reconcile that manifest on the cluster. | ||
// The two sets of manifests are respectively from the release that is currently running on the cluster and | ||
// from the release that the cluster is updated to. | ||
func GetImplicitlyEnabledCapabilities( | ||
updatePayloadManifests []manifest.Manifest, | ||
currentPayloadManifests []manifest.Manifest, | ||
manifestInclusionConfiguration InclusionConfiguration, | ||
currentImplicitlyEnabled sets.Set[configv1.ClusterVersionCapability], | ||
) sets.Set[configv1.ClusterVersionCapability] { | ||
ret := currentImplicitlyEnabled.Clone() | ||
for _, updateManifest := range updatePayloadManifests { | ||
updateManErr := updateManifest.IncludeAllowUnknownCapabilities( | ||
manifestInclusionConfiguration.ExcludeIdentifier, | ||
manifestInclusionConfiguration.RequiredFeatureSet, | ||
manifestInclusionConfiguration.Profile, | ||
manifestInclusionConfiguration.Capabilities, | ||
manifestInclusionConfiguration.Overrides, | ||
true, | ||
) | ||
// update manifest is enabled, no need to check | ||
if updateManErr == nil { | ||
continue | ||
} | ||
for _, currentManifest := range currentPayloadManifests { | ||
if !updateManifest.SameResourceID(currentManifest) { | ||
continue | ||
} | ||
// current manifest is disabled, no need to check | ||
if err := currentManifest.IncludeAllowUnknownCapabilities( | ||
manifestInclusionConfiguration.ExcludeIdentifier, | ||
manifestInclusionConfiguration.RequiredFeatureSet, | ||
manifestInclusionConfiguration.Profile, | ||
manifestInclusionConfiguration.Capabilities, | ||
manifestInclusionConfiguration.Overrides, | ||
true, | ||
); err != nil { | ||
continue | ||
} | ||
newImplicitlyEnabled := sets.New[configv1.ClusterVersionCapability](updateManifest.GetManifestCapabilities()...). | ||
Difference(sets.New[configv1.ClusterVersionCapability](currentManifest.GetManifestCapabilities()...)). | ||
Difference(currentImplicitlyEnabled). | ||
Difference(sets.New[configv1.ClusterVersionCapability](manifestInclusionConfiguration.Capabilities.EnabledCapabilities...)) | ||
ret = ret.Union(newImplicitlyEnabled) | ||
if newImplicitlyEnabled.Len() > 0 { | ||
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", | ||
updateManifest.String(), sets.List(newImplicitlyEnabled)) | ||
} | ||
} | ||
} | ||
return ret | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we test this implementation is:
GetImplicitlyEnabledCapabilities
?For (1) I assume that we'll need tests once we lift it to o/library-go so why not write them right away?
For (2) I wonder if if would be proper to keep the old implementation for a while, implement a test that shows that the two implementations are equivalent (same inputs -> same outputs) and only delete the code (and the equivalence test) once the o/library-go implementation fully settles?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For (2): There are tests for it already.
cluster-version-operator/pkg/payload/payload_test.go
Line 220 in 198fdab
At least, from those tests point of view, they are equivalent.
For (1):
I moved over the unit tests from (2) to https://github.com/openshift/library-go/pull/1908/files with modifications
manifestInclusionConfiguration
), ando/lib
approvers that it OK to do it .There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay, we have tests on the payload-level
GetImplicitlyEnabledCapabilities
which calls the new function, good!