Skip to content

Commit 05353f3

Browse files
committed
hypershift: Add version annotation to controller Deployments
New annotation `release.openshift.io/version` signals that rollout of Deployment is complete (see https://issues.redhat.com/browse/STOR-2523 for details)
1 parent 307ef19 commit 05353f3

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

pkg/driver/aws-ebs/aws_ebs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ func GetAWSEBSOperatorControllerConfig(ctx context.Context, flavour generator.Cl
187187
} else {
188188
// HyperShift only hooks
189189
cfg.AddDeploymentHookBuilders(c, getCustomAWSCABundleBuilder("user-ca-bundle"))
190+
cfg.AddDeploymentHookBuilders(c, operator.GetDeploymentVersionBuilder())
190191
}
191192
cfg.DeploymentWatchedSecretNames = append(cfg.DeploymentWatchedSecretNames, cloudCredSecretName, metricsCertSecretName)
192193
cfg.StaleConditionsName = []string{

pkg/driver/common/operator/hooks.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package operator
22

33
import (
4+
"context"
45
"fmt"
56
"os"
67
"strconv"
@@ -15,8 +16,10 @@ import (
1516
"github.com/openshift/library-go/pkg/controller/factory"
1617
"github.com/openshift/library-go/pkg/operator/csi/csidrivercontrollerservicecontroller"
1718
dc "github.com/openshift/library-go/pkg/operator/deploymentcontroller"
19+
"github.com/openshift/library-go/pkg/operator/status"
1820
appsv1 "k8s.io/api/apps/v1"
1921
corev1 "k8s.io/api/core/v1"
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2023
"k8s.io/apimachinery/pkg/labels"
2124
"k8s.io/apimachinery/pkg/runtime/schema"
2225
"k8s.io/klog/v2"
@@ -252,3 +255,46 @@ func withHyperShiftRunAsUser(c *clients.Clients) (dc.DeploymentHookFunc, []facto
252255
}
253256
return hook, nil
254257
}
258+
259+
func hasFinishedProgressing(deployment *appsv1.Deployment) bool {
260+
if deployment.Status.ObservedGeneration != deployment.Generation {
261+
// The Deployment controller did not act on the Deployment spec change yet.
262+
// Any condition in the status may be stale.
263+
return false
264+
}
265+
// Deployment whose rollout is complete gets Progressing condition with Reason NewReplicaSetAvailable condition.
266+
// https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#complete-deployment
267+
for _, cond := range deployment.Status.Conditions {
268+
if cond.Type == appsv1.DeploymentProgressing {
269+
return cond.Status == corev1.ConditionTrue && cond.Reason == "NewReplicaSetAvailable"
270+
}
271+
}
272+
return false
273+
}
274+
275+
func GetDeploymentVersionBuilder() config.DeploymentHookBuilder {
276+
return func(c *clients.Clients) (dc.DeploymentHookFunc, []factory.Informer) {
277+
hook := func(_ *opv1.OperatorSpec, deployment *appsv1.Deployment) error {
278+
var desiredVersion string
279+
for k, v := range deployment.Annotations {
280+
if k == "release.openshift.io/desired-version" {
281+
desiredVersion = v
282+
}
283+
}
284+
if desiredVersion != status.VersionForOperatorFromEnv() {
285+
return nil
286+
}
287+
288+
// deployment.Status is empty: {0 0 0 0 0 0 <nil> [] <nil>}
289+
deployment2, err := c.ControlPlaneKubeClient.AppsV1().Deployments(deployment.Namespace).Get(context.TODO(), deployment.Name, metav1.GetOptions{})
290+
if err != nil {
291+
return fmt.Errorf("could not get Deployment %s in Namespace %s: %w", deployment.Name, deployment.Namespace, err)
292+
}
293+
if hasFinishedProgressing(deployment2) {
294+
deployment.Annotations["release.openshift.io/version"] = desiredVersion
295+
}
296+
return nil
297+
}
298+
return hook, nil
299+
}
300+
}

0 commit comments

Comments
 (0)