Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 3 additions & 15 deletions cmd/cluster-storage-operator/main.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package main

import (
"flag"
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

k8sflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"
"k8s.io/component-base/cli"

"github.com/openshift/library-go/pkg/controller/controllercmd"

Expand All @@ -18,17 +14,9 @@ import (
)

func main() {
pflag.CommandLine.SetNormalizeFunc(k8sflag.WordSepNormalizeFunc)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)

logs.InitLogs()
defer logs.FlushLogs()

command := NewOperatorCommand()
if err := command.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
code := cli.Run(command)
os.Exit(code)
}

func NewOperatorCommand() *cobra.Command {
Expand Down
21 changes: 10 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@ go 1.16
require (
github.com/google/go-cmp v0.5.5
github.com/google/gofuzz v1.2.0 // indirect
github.com/openshift/api v0.0.0-20211018182944-3a31a0369345
github.com/openshift/api v0.0.0-20211209135129-c58d9f695577
github.com/openshift/build-machinery-go v0.0.0-20211213093930-7e33a7eb4ce3
github.com/openshift/client-go v0.0.0-20211014121513-e0d04d36b53a
github.com/openshift/library-go v0.0.0-20210830145332-4a9873bf5e74
github.com/openshift/client-go v0.0.0-20211209144617-7385dd6338e3
github.com/openshift/library-go v0.0.0-20211214183058-58531ccbde67
github.com/prometheus-operator/prometheus-operator v0.44.1
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.44.1
github.com/prometheus/client_golang v1.11.0
github.com/spf13/cobra v1.1.3
github.com/spf13/pflag v1.0.5
k8s.io/api v0.22.1
k8s.io/apiextensions-apiserver v0.22.1
k8s.io/apimachinery v0.22.1
github.com/spf13/cobra v1.2.1
k8s.io/api v0.23.0
k8s.io/apiextensions-apiserver v0.23.0
k8s.io/apimachinery v0.23.0
k8s.io/client-go v12.0.0+incompatible
k8s.io/component-base v0.22.1
k8s.io/klog/v2 v2.10.0
k8s.io/component-base v0.23.0
k8s.io/klog/v2 v2.30.0
)

replace k8s.io/client-go => k8s.io/client-go v0.22.1
replace k8s.io/client-go => k8s.io/client-go v0.23.0
238 changes: 168 additions & 70 deletions go.sum

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions pkg/operator/csidriveroperator/crcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (c *CSIDriverOperatorCRController) Sync(ctx context.Context, syncCtx factor

// Sync CSIDriver CR
requiredCR := c.getRequestedClusterCSIDriver(opSpec.LogLevel)
cr, _, err := c.applyClusterCSIDriver(requiredCR)
cr, _, err := c.applyClusterCSIDriver(ctx, requiredCR)
if err != nil {
// This will set Degraded condition
return err
Expand All @@ -136,7 +136,7 @@ func (c *CSIDriverOperatorCRController) Sync(ctx context.Context, syncCtx factor
return nil
}

if err := c.syncConditions(cr.Status.Conditions, updateGenerationFn); err != nil {
if err := c.syncConditions(ctx, cr.Status.Conditions, updateGenerationFn); err != nil {
errs = append(errs, err)
}
return errors.NewAggregate(errs)
Expand Down Expand Up @@ -171,10 +171,10 @@ func (c *CSIDriverOperatorCRController) crConditionName(cndType string) string {
return c.name + csiDriverControllerConditionPrefix + cndType
}

func (c *CSIDriverOperatorCRController) applyClusterCSIDriver(required *operatorapi.ClusterCSIDriver) (*operatorapi.ClusterCSIDriver, bool, error) {
existing, err := c.operatorClientSet.OperatorV1().ClusterCSIDrivers().Get(context.TODO(), required.Name, metav1.GetOptions{})
func (c *CSIDriverOperatorCRController) applyClusterCSIDriver(ctx context.Context, required *operatorapi.ClusterCSIDriver) (*operatorapi.ClusterCSIDriver, bool, error) {
existing, err := c.operatorClientSet.OperatorV1().ClusterCSIDrivers().Get(ctx, required.Name, metav1.GetOptions{})
if apierrors.IsNotFound(err) {
actual, err := c.operatorClientSet.OperatorV1().ClusterCSIDrivers().Create(context.TODO(), required, metav1.CreateOptions{})
actual, err := c.operatorClientSet.OperatorV1().ClusterCSIDrivers().Create(ctx, required, metav1.CreateOptions{})
reportCreateEvent(c.eventRecorder, required, err)
return actual, true, err
}
Expand All @@ -185,7 +185,7 @@ func (c *CSIDriverOperatorCRController) applyClusterCSIDriver(required *operator
return existing.DeepCopy(), false, nil
}

func (c *CSIDriverOperatorCRController) syncConditions(conditions []operatorapi.OperatorCondition, updatefn v1helpers.UpdateStatusFunc) error {
func (c *CSIDriverOperatorCRController) syncConditions(ctx context.Context, conditions []operatorapi.OperatorCondition, updatefn v1helpers.UpdateStatusFunc) error {
var availableCnd operatorapi.OperatorCondition
disabled, msg := c.hasDisabledCondition(conditions)
if disabled && c.allowDisabled {
Expand Down Expand Up @@ -222,7 +222,7 @@ func (c *CSIDriverOperatorCRController) syncConditions(conditions []operatorapi.
degradedCnd.Status = operatorapi.ConditionFalse
}

_, _, err := v1helpers.UpdateStatus(c.operatorClient,
_, _, err := v1helpers.UpdateStatus(ctx, c.operatorClient,
v1helpers.UpdateConditionFn(availableCnd),
v1helpers.UpdateConditionFn(progressingCnd),
v1helpers.UpdateConditionFn(degradedCnd),
Expand Down
1 change: 1 addition & 0 deletions pkg/operator/csidriveroperator/deploymentcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func (c *CSIDriverOperatorDeploymentController) Sync(ctx context.Context, syncCt
}

_, _, err = v1helpers.UpdateStatus(
ctx,
c.operatorClient,
updateStatusFn,
v1helpers.UpdateConditionFn(progressingCondition),
Expand Down
20 changes: 10 additions & 10 deletions pkg/operator/csidriveroperator/olmremovalcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (c *OLMOperatorRemovalController) Sync(ctx context.Context, syncCtx factory
}
if !removed {
klog.V(4).Infof("OLMOperatorRemovalController.Sync waiting for OLM Subscription to disappear")
return c.markProgressing(syncCtx, "Waiting for OLM Subscription to be deleted")
return c.markProgressing(ctx, syncCtx, "Waiting for OLM Subscription to be deleted")
}
}

Expand All @@ -148,7 +148,7 @@ func (c *OLMOperatorRemovalController) Sync(ctx context.Context, syncCtx factory
// There is no Subscription + there is no work recorded in CR annotations: we're done!
klog.V(4).Infof("OLMOperatorRemovalController.Sync the old driver was not installed")
// Since the old driver wasn't installed, we don't add any messages to avoid noisy Available/Progressing conditions.
return c.markFinished("")
return c.markFinished(ctx, "")
}
}

Expand All @@ -159,7 +159,7 @@ func (c *OLMOperatorRemovalController) Sync(ctx context.Context, syncCtx factory
}
if !removed {
klog.V(4).Infof("OLMOperatorRemovalController.Sync waiting for OLM CSV to disappear")
return c.markProgressing(syncCtx, "Waiting for OLM CSV to be deleted")
return c.markProgressing(ctx, syncCtx, "Waiting for OLM CSV to be deleted")
}

// 3. Wait until OLM removes the the operator deployment
Expand All @@ -169,7 +169,7 @@ func (c *OLMOperatorRemovalController) Sync(ctx context.Context, syncCtx factory
}
if !removed {
klog.V(4).Infof("OLMOperatorRemovalController.Sync waiting for OLM to delete the operator")
return c.markProgressing(syncCtx, "Waiting for OLM to delete the operator")
return c.markProgressing(ctx, syncCtx, "Waiting for OLM to delete the operator")
}

// 4. Remove CR
Expand All @@ -179,11 +179,11 @@ func (c *OLMOperatorRemovalController) Sync(ctx context.Context, syncCtx factory
}
if !removed {
klog.V(4).Infof("OLMOperatorRemovalController.Sync waiting for the CR to disappear")
return c.markProgressing(syncCtx, "Waiting for the old operator CR to be deleted")
return c.markProgressing(ctx, syncCtx, "Waiting for the old operator CR to be deleted")
}

klog.V(4).Infof("OLMOperatorRemovalController.Sync done!")
return c.markFinished("CSI driver has been removed from OLM")
return c.markFinished(ctx, "CSI driver has been removed from OLM")
}

func (c *OLMOperatorRemovalController) findSubscription(ctx context.Context) (string, string, string, bool, error) {
Expand Down Expand Up @@ -272,7 +272,7 @@ func (c *OLMOperatorRemovalController) loadMetadata() (string, string, error) {
return ns, csv, nil
}

func (c *OLMOperatorRemovalController) markProgressing(syncCtx factory.SyncContext, message string) error {
func (c *OLMOperatorRemovalController) markProgressing(ctx context.Context, syncCtx factory.SyncContext, message string) error {
progressing := operatorapi.OperatorCondition{
Type: c.Name() + operatorapi.OperatorStatusTypeProgressing,
Reason: "RemovingOLMOperator",
Expand All @@ -286,7 +286,7 @@ func (c *OLMOperatorRemovalController) markProgressing(syncCtx factory.SyncConte
Message: message,
}

if _, _, err := v1helpers.UpdateStatus(c.operatorClient,
if _, _, err := v1helpers.UpdateStatus(ctx, c.operatorClient,
v1helpers.UpdateConditionFn(progressing),
v1helpers.UpdateConditionFn(available),
); err != nil {
Expand All @@ -299,7 +299,7 @@ func (c *OLMOperatorRemovalController) markProgressing(syncCtx factory.SyncConte
return nil
}

func (c *OLMOperatorRemovalController) markFinished(message string) error {
func (c *OLMOperatorRemovalController) markFinished(ctx context.Context, message string) error {
progressing := operatorapi.OperatorCondition{
Type: c.Name() + operatorapi.OperatorStatusTypeProgressing,
Reason: "Finished",
Expand All @@ -317,7 +317,7 @@ func (c *OLMOperatorRemovalController) markFinished(message string) error {
if err := c.saveMetadata("", ""); err != nil {
return err
}
_, _, err := v1helpers.UpdateStatus(c.operatorClient,
_, _, err := v1helpers.UpdateStatus(ctx, c.operatorClient,
v1helpers.UpdateConditionFn(progressing),
v1helpers.UpdateConditionFn(available),
)
Expand Down
6 changes: 3 additions & 3 deletions pkg/operator/defaultstorageclass/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (c *Controller) sync(ctx context.Context, syncCtx factory.SyncContext) erro
availableCnd.Message = "No default StorageClass for this platform"
availableCnd.Status = operatorapi.ConditionTrue

_, _, updateErr := v1helpers.UpdateStatus(c.operatorClient,
_, _, updateErr := v1helpers.UpdateStatus(ctx, c.operatorClient,
v1helpers.UpdateConditionFn(disabledCnd),
v1helpers.UpdateConditionFn(availableCnd),
v1helpers.UpdateConditionFn(progressingCnd),
Expand All @@ -115,7 +115,7 @@ func (c *Controller) sync(ctx context.Context, syncCtx factory.SyncContext) erro
availableCnd.Message = "StorageClass provided by supplied CSI Driver instead of the cluster-storage-operator"
availableCnd.Status = operatorapi.ConditionTrue

_, _, updateErr := v1helpers.UpdateStatus(c.operatorClient,
_, _, updateErr := v1helpers.UpdateStatus(ctx, c.operatorClient,
v1helpers.UpdateConditionFn(availableCnd),
v1helpers.UpdateConditionFn(progressingCnd),
)
Expand All @@ -131,7 +131,7 @@ func (c *Controller) sync(ctx context.Context, syncCtx factory.SyncContext) erro
progressingCnd.Message = syncErr.Error()
}

if _, _, updateErr := v1helpers.UpdateStatus(c.operatorClient,
if _, _, updateErr := v1helpers.UpdateStatus(ctx, c.operatorClient,
v1helpers.UpdateConditionFn(availableCnd),
v1helpers.UpdateConditionFn(progressingCnd),
removeConditionFn(conditionsPrefix+disabledConditionType),
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/snapshotcrd/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (c *Controller) sync(ctx context.Context, syncCtx factory.SyncContext) erro
upgradeable.Reason = "AlphaDetected"
}

if _, _, updateErr := v1helpers.UpdateStatus(c.operatorClient,
if _, _, updateErr := v1helpers.UpdateStatus(ctx, c.operatorClient,
v1helpers.UpdateConditionFn(upgradeable),
); updateErr != nil {
return updateErr
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/vsphereproblemdetector/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (c *monitoringController) sync(ctx context.Context, syncContext factory.Syn
Type: monitoringControllerName + operatorapi.OperatorStatusTypeAvailable,
Status: operatorapi.ConditionTrue,
}
if _, _, err := v1helpers.UpdateStatus(c.operatorClient,
if _, _, err := v1helpers.UpdateStatus(ctx, c.operatorClient,
v1helpers.UpdateConditionFn(monitoringCondition),
); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/operatorclient/operatorclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (c OperatorClient) GetOperatorState() (*operatorv1.OperatorSpec, *operatorv
return &instance.Spec.OperatorSpec, &instance.Status.OperatorStatus, instance.ResourceVersion, nil
}

func (c OperatorClient) UpdateOperatorSpec(resourceVersion string, spec *operatorv1.OperatorSpec) (*operatorv1.OperatorSpec, string, error) {
func (c OperatorClient) UpdateOperatorSpec(ctx context.Context, resourceVersion string, spec *operatorv1.OperatorSpec) (*operatorv1.OperatorSpec, string, error) {
original, err := c.Informers.Operator().V1().Storages().Lister().Get(GlobalConfigName)
if err != nil {
return nil, "", err
Expand All @@ -54,7 +54,7 @@ func (c OperatorClient) UpdateOperatorSpec(resourceVersion string, spec *operato
return &ret.Spec.OperatorSpec, ret.ResourceVersion, nil
}

func (c OperatorClient) UpdateOperatorStatus(resourceVersion string, status *operatorv1.OperatorStatus) (*operatorv1.OperatorStatus, error) {
func (c OperatorClient) UpdateOperatorStatus(ctx context.Context, resourceVersion string, status *operatorv1.OperatorStatus) (*operatorv1.OperatorStatus, error) {
original, err := c.Informers.Operator().V1().Storages().Lister().Get(GlobalConfigName)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/deployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func CreateDeployment(ctx context.Context, depOpts DeploymentOptions) (*appsv1.D
return nil
}

if _, _, err := v1helpers.UpdateStatus(depOpts.OperatorClient,
if _, _, err := v1helpers.UpdateStatus(ctx, depOpts.OperatorClient,
v1helpers.UpdateConditionFn(deploymentAvailable),
v1helpers.UpdateConditionFn(deploymentProgressing),
updateGenerationFn,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading