-
Notifications
You must be signed in to change notification settings - Fork 213
OTA-209: Add CVOConfiguration controller #1163
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 6 commits into
openshift:main
from
DavidHurta:cvo-configuration-controller
Mar 13, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
13fd095
pkg: Add ClusterVersionOperatorConfiguration feature gate
DavidHurta 9ce6a03
pkg: Add CVOConfiguration controller
DavidHurta fecf267
Do not execute CVOConfiguration logic in HyperShift
DavidHurta a002d37
deps: go mod tidy & go mod vendor
DavidHurta d559d7b
pkg/cvo/configuration: Add TODO to address missing resource
DavidHurta 63878c0
pkg/cvo/configuration: Run sync on resource deletion
DavidHurta 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| package configuration | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "time" | ||
|
|
||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| "k8s.io/client-go/tools/cache" | ||
| "k8s.io/client-go/util/workqueue" | ||
| "k8s.io/klog/v2" | ||
|
|
||
| operatorv1alpha1 "github.com/openshift/api/operator/v1alpha1" | ||
| operatorclientset "github.com/openshift/client-go/operator/clientset/versioned" | ||
| cvoclientv1alpha1 "github.com/openshift/client-go/operator/clientset/versioned/typed/operator/v1alpha1" | ||
| operatorexternalversions "github.com/openshift/client-go/operator/informers/externalversions" | ||
| operatorlistersv1alpha1 "github.com/openshift/client-go/operator/listers/operator/v1alpha1" | ||
| ) | ||
|
|
||
| const ClusterVersionOperatorConfigurationName = "cluster" | ||
|
|
||
| type ClusterVersionOperatorConfiguration struct { | ||
| queueKey string | ||
| // queue tracks checking for the CVO configuration. | ||
| // | ||
| // The type any is used to comply with the worker method of the cvo.Operator struct. | ||
| queue workqueue.TypedRateLimitingInterface[any] | ||
|
|
||
| client cvoclientv1alpha1.ClusterVersionOperatorInterface | ||
| lister operatorlistersv1alpha1.ClusterVersionOperatorLister | ||
| factory operatorexternalversions.SharedInformerFactory | ||
|
|
||
| started bool | ||
| } | ||
|
|
||
| func (config *ClusterVersionOperatorConfiguration) Queue() workqueue.TypedRateLimitingInterface[any] { | ||
| return config.queue | ||
| } | ||
|
|
||
| // clusterVersionOperatorEventHandler queues an update for the cluster version operator on any change to the given object. | ||
| // Callers should use this with an informer. | ||
| func (config *ClusterVersionOperatorConfiguration) clusterVersionOperatorEventHandler() cache.ResourceEventHandler { | ||
| return cache.ResourceEventHandlerFuncs{ | ||
| AddFunc: func(_ interface{}) { | ||
| config.queue.Add(config.queueKey) | ||
| }, | ||
| UpdateFunc: func(_, _ interface{}) { | ||
| config.queue.Add(config.queueKey) | ||
| }, | ||
| DeleteFunc: func(_ interface{}) { | ||
| config.queue.Add(config.queueKey) | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| // NewClusterVersionOperatorConfiguration returns ClusterVersionOperatorConfiguration, which might be used | ||
| // to synchronize with the ClusterVersionOperator resource. | ||
| func NewClusterVersionOperatorConfiguration(client operatorclientset.Interface, factory operatorexternalversions.SharedInformerFactory) *ClusterVersionOperatorConfiguration { | ||
| return &ClusterVersionOperatorConfiguration{ | ||
| queueKey: fmt.Sprintf("ClusterVersionOperator/%s", ClusterVersionOperatorConfigurationName), | ||
| queue: workqueue.NewTypedRateLimitingQueueWithConfig[any]( | ||
| workqueue.DefaultTypedControllerRateLimiter[any](), | ||
| workqueue.TypedRateLimitingQueueConfig[any]{Name: "configuration"}), | ||
| client: client.OperatorV1alpha1().ClusterVersionOperators(), | ||
| factory: factory, | ||
| } | ||
| } | ||
|
|
||
| // Start initializes and starts the configuration's informers. Must be run before Sync is called. | ||
| // Blocks until informers caches are synchronized or the context is cancelled. | ||
| func (config *ClusterVersionOperatorConfiguration) Start(ctx context.Context) error { | ||
| informer := config.factory.Operator().V1alpha1().ClusterVersionOperators() | ||
| if _, err := informer.Informer().AddEventHandler(config.clusterVersionOperatorEventHandler()); err != nil { | ||
| return err | ||
| } | ||
| config.lister = informer.Lister() | ||
|
|
||
| config.factory.Start(ctx.Done()) | ||
| synced := config.factory.WaitForCacheSync(ctx.Done()) | ||
| for _, ok := range synced { | ||
| if !ok { | ||
| return fmt.Errorf("caches failed to sync: %w", ctx.Err()) | ||
| } | ||
| } | ||
|
|
||
| config.started = true | ||
| return nil | ||
| } | ||
|
|
||
| func (config *ClusterVersionOperatorConfiguration) Sync(ctx context.Context, key string) error { | ||
| if !config.started { | ||
| panic("ClusterVersionOperatorConfiguration instance was not properly started before its synchronization.") | ||
| } | ||
| startTime := time.Now() | ||
| klog.V(2).Infof("Started syncing CVO configuration %q", key) | ||
| defer func() { | ||
| klog.V(2).Infof("Finished syncing CVO configuration (%v)", time.Since(startTime)) | ||
| }() | ||
|
|
||
| desiredConfig, err := config.lister.Get(ClusterVersionOperatorConfigurationName) | ||
| if apierrors.IsNotFound(err) { | ||
| // TODO: Set default values | ||
| return nil | ||
| } | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return config.sync(ctx, desiredConfig) | ||
| } | ||
|
|
||
| func (config *ClusterVersionOperatorConfiguration) sync(_ context.Context, _ *operatorv1alpha1.ClusterVersionOperator) error { | ||
| klog.Infof("ClusterVersionOperator configuration has been synced") | ||
| return nil | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.