Skip to content

Commit

Permalink
pkg/operator/upgradebackupcontroller: update cluster operator status
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Batschelet <sbatsche@redhat.com>
  • Loading branch information
hexfusion committed Sep 1, 2021
1 parent b4a70ef commit 7c183f3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
2 changes: 2 additions & 0 deletions pkg/operator/starter.go
Expand Up @@ -248,8 +248,10 @@ func RunOperator(ctx context.Context, controllerContext *controllercmd.Controlle
controllerContext.EventRecorder,
)

staticPodOperatorClient := operatorClient
upgradeBackupController := upgradebackupcontroller.NewUpgradeBackupController(
operatorClient,
staticPodOperatorClient,
kubeClient,
etcdClient,
kubeInformersForNamespaces,
Expand Down
47 changes: 25 additions & 22 deletions pkg/operator/upgradebackupcontroller/upgradebackupcontroller.go
Expand Up @@ -45,17 +45,19 @@ const (
)

type UpgradeBackupController struct {
operatorClient v1helpers.OperatorClient
kubeClient kubernetes.Interface
etcdClient etcdcli.EtcdClient
podLister corev1listers.PodLister
clusterVersionLister configv1listers.ClusterVersionLister
targetImagePullSpec string
operatorImagePullSpec string
operatorClient v1helpers.OperatorClient
staticPodOperatorClient v1helpers.StaticPodOperatorClient
kubeClient kubernetes.Interface
etcdClient etcdcli.EtcdClient
podLister corev1listers.PodLister
clusterVersionLister configv1listers.ClusterVersionLister
targetImagePullSpec string
operatorImagePullSpec string
}

func NewUpgradeBackupController(
operatorClient v1helpers.OperatorClient,
staticPodOperatorClient v1helpers.StaticPodOperatorClient,
kubeClient kubernetes.Interface,
etcdClient etcdcli.EtcdClient,
kubeInformers v1helpers.KubeInformersForNamespaces,
Expand All @@ -65,13 +67,14 @@ func NewUpgradeBackupController(
operatorImagePullSpec string,
) factory.Controller {
c := &UpgradeBackupController{
operatorClient: operatorClient,
kubeClient: kubeClient,
etcdClient: etcdClient,
podLister: kubeInformers.InformersFor(operatorclient.TargetNamespace).Core().V1().Pods().Lister(),
clusterVersionLister: clusterVersionInformer.Lister(),
targetImagePullSpec: targetImagePullSpec,
operatorImagePullSpec: operatorImagePullSpec,
operatorClient: operatorClient,
staticPodOperatorClient: staticPodOperatorClient,
kubeClient: kubeClient,
etcdClient: etcdClient,
podLister: kubeInformers.InformersFor(operatorclient.TargetNamespace).Core().V1().Pods().Lister(),
clusterVersionLister: clusterVersionInformer.Lister(),
targetImagePullSpec: targetImagePullSpec,
operatorImagePullSpec: operatorImagePullSpec,
}
return factory.New().ResyncEvery(1*time.Minute).WithInformers(
kubeInformers.InformersFor(operatorclient.TargetNamespace).Core().V1().Pods().Informer(),
Expand All @@ -88,12 +91,13 @@ func (c *UpgradeBackupController) sync(ctx context.Context, syncCtx factory.Sync
backupCondition := v1helpers.FindOperatorCondition(status.Conditions, backupConditionType)
newConditionRequired := backupCondition == nil
if newConditionRequired {
_, _, err := v1helpers.UpdateStatus(c.operatorClient, v1helpers.UpdateConditionFn(operatorv1.OperatorCondition{
_, _, err := v1helpers.UpdateStaticPodStatus(c.staticPodOperatorClient, v1helpers.UpdateStaticPodConditionFn(operatorv1.OperatorCondition{
Type: "RecentBackup",
Status: operatorv1.ConditionUnknown,
Reason: "ControllerStarted",
}))
if err != nil {
syncCtx.Recorder().Warning("ClusterBackupControllerUpdatingStatus", err.Error())
return err
}
}
Expand All @@ -111,12 +115,11 @@ func (c *UpgradeBackupController) sync(ctx context.Context, syncCtx factory.Sync
}
return err
}
_, _, updateErr := v1helpers.UpdateStatus(c.operatorClient,
v1helpers.UpdateConditionFn(operatorv1.OperatorCondition{
Type: "UpgradeBackupControllerDegraded",
Status: operatorv1.ConditionFalse,
Reason: "AsExpected",
}))
_, _, updateErr := v1helpers.UpdateStatus(c.operatorClient, v1helpers.UpdateConditionFn(operatorv1.OperatorCondition{
Type: "UpgradeBackupControllerDegraded",
Status: operatorv1.ConditionFalse,
Reason: "AsExpected",
}))
if updateErr != nil {
syncCtx.Recorder().Warning("ClusterBackupControllerUpdatingStatus", updateErr.Error())
return updateErr
Expand All @@ -127,7 +130,7 @@ func (c *UpgradeBackupController) sync(ctx context.Context, syncCtx factory.Sync
return nil
}

_, _, err = v1helpers.UpdateStatus(c.operatorClient, v1helpers.UpdateConditionFn(*recentBackupCondition))
_, _, err = v1helpers.UpdateStaticPodStatus(c.staticPodOperatorClient, v1helpers.UpdateStaticPodConditionFn(*recentBackupCondition))
if err != nil {
syncCtx.Recorder().Warning("ClusterBackupControllerUpdatingStatus", err.Error())
return err
Expand Down

0 comments on commit 7c183f3

Please sign in to comment.