|
8 | 8 | "sync" |
9 | 9 | "time" |
10 | 10 |
|
| 11 | + runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" |
| 12 | + "sigs.k8s.io/controller-runtime/pkg/client/config" |
| 13 | + |
11 | 14 | corev1 "k8s.io/api/core/v1" |
12 | 15 | apierrors "k8s.io/apimachinery/pkg/api/errors" |
13 | 16 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
@@ -53,6 +56,7 @@ import ( |
53 | 56 | "github.com/openshift/cluster-version-operator/pkg/payload" |
54 | 57 | "github.com/openshift/cluster-version-operator/pkg/payload/precondition" |
55 | 58 | preconditioncv "github.com/openshift/cluster-version-operator/pkg/payload/precondition/clusterversion" |
| 59 | + "github.com/openshift/cluster-version-operator/pkg/proposal" |
56 | 60 | "github.com/openshift/cluster-version-operator/pkg/risk" |
57 | 61 | "github.com/openshift/cluster-version-operator/pkg/risk/alert" |
58 | 62 | ) |
@@ -213,6 +217,9 @@ type Operator struct { |
213 | 217 | // risks holds update-risk source (in-cluster alerts, etc.) |
214 | 218 | // that will be aggregated into conditional update risks. |
215 | 219 | risks risk.Source |
| 220 | + |
| 221 | + // proposalController, if enabled, watch available updates and manage proposals |
| 222 | + proposalController *proposal.Controller |
216 | 223 | } |
217 | 224 |
|
218 | 225 | // New returns a new cluster version operator. |
@@ -317,6 +324,17 @@ func New( |
317 | 324 |
|
318 | 325 | optr.configuration = configuration.NewClusterVersionOperatorConfiguration(operatorClient, operatorInformerFactory) |
319 | 326 |
|
| 327 | + c, err := runtimeclient.New(config.GetConfigOrDie(), runtimeclient.Options{}) |
| 328 | + if err != nil { |
| 329 | + return nil, err |
| 330 | + } |
| 331 | + optr.proposalController = proposal.NewController(func() ([]configv1.Release, []configv1.ConditionalUpdate, error) { |
| 332 | + if optr.availableUpdates == nil { |
| 333 | + return nil, nil, nil |
| 334 | + } |
| 335 | + return optr.availableUpdates.Updates, optr.availableUpdates.ConditionalUpdates, nil |
| 336 | + }, c) |
| 337 | + |
320 | 338 | return optr, nil |
321 | 339 | } |
322 | 340 |
|
@@ -470,6 +488,7 @@ func (optr *Operator) Run(runContext context.Context, shutdownContext context.Co |
470 | 488 | defer optr.availableUpdatesQueue.ShutDown() |
471 | 489 | defer optr.upgradeableQueue.ShutDown() |
472 | 490 | defer optr.configuration.Queue().ShutDown() |
| 491 | + defer optr.proposalController.Queue().ShutDown() |
473 | 492 | stopCh := runContext.Done() |
474 | 493 |
|
475 | 494 | klog.Infof("Starting ClusterVersionOperator with minimum reconcile period %s", optr.minimumUpdateCheckInterval) |
@@ -525,6 +544,19 @@ func (optr *Operator) Run(runContext context.Context, shutdownContext context.Co |
525 | 544 | klog.Infof("The ClusterVersionOperatorConfiguration feature gate is disabled or HyperShift is detected; the configuration sync routine will not run.") |
526 | 545 | } |
527 | 546 |
|
| 547 | + if optr.shouldEnableProposalController() { |
| 548 | + resultChannelCount++ |
| 549 | + go func() { |
| 550 | + defer utilruntime.HandleCrash() |
| 551 | + wait.UntilWithContext(runContext, func(runContext context.Context) { |
| 552 | + optr.worker(runContext, optr.proposalController.Queue(), optr.proposalController.Sync) |
| 553 | + }, time.Second) |
| 554 | + resultChannel <- asyncResult{name: "proposal controller"} |
| 555 | + }() |
| 556 | + } else { |
| 557 | + klog.Infof("The proposal controller is disabled.") |
| 558 | + } |
| 559 | + |
528 | 560 | resultChannelCount++ |
529 | 561 | go func() { |
530 | 562 | defer utilruntime.HandleCrash() |
@@ -595,6 +627,7 @@ func (optr *Operator) Run(runContext context.Context, shutdownContext context.Co |
595 | 627 | optr.availableUpdatesQueue.ShutDown() |
596 | 628 | optr.upgradeableQueue.ShutDown() |
597 | 629 | optr.configuration.Queue().ShutDown() |
| 630 | + optr.proposalController.Queue().ShutDown() |
598 | 631 | } |
599 | 632 | } |
600 | 633 |
|
@@ -1191,3 +1224,8 @@ func (optr *Operator) shouldReconcileAcceptRisks() bool { |
1191 | 1224 | // HyperShift will be supported later if needed |
1192 | 1225 | return optr.enabledCVOFeatureGates.AcceptRisks() && !optr.hypershift |
1193 | 1226 | } |
| 1227 | + |
| 1228 | +// shouldEnableProposalController returns whether the CVO should enable the proposal controller |
| 1229 | +func (optr *Operator) shouldEnableProposalController() bool { |
| 1230 | + return optr.enabledCVOFeatureGates.Proposal() |
| 1231 | +} |
0 commit comments