Skip to content

Commit

Permalink
Ensure release version is injected into all controller status clients
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelSpeed committed Apr 28, 2022
1 parent d9bab3c commit 77612b9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
15 changes: 2 additions & 13 deletions cmd/cluster-cloud-controller-manager-operator/main.go
Expand Up @@ -56,9 +56,7 @@ var (
)

const (
defaultImagesLocation = "/etc/cloud-controller-manager-config/images.json"
releaseVersionEnvVariableName = "RELEASE_VERSION"
unknownVersionValue = "unknown"
defaultImagesLocation = "/etc/cloud-controller-manager-config/images.json"
)

func init() {
Expand Down Expand Up @@ -136,7 +134,7 @@ func main() {
ClusterOperatorStatusClient: controllers.ClusterOperatorStatusClient{
Client: mgr.GetClient(),
Recorder: mgr.GetEventRecorderFor("cloud-controller-manager-operator"),
ReleaseVersion: getReleaseVersion(),
ReleaseVersion: controllers.GetReleaseVersion(),
ManagedNamespace: *managedNamespace,
},
Scheme: mgr.GetScheme(),
Expand All @@ -162,12 +160,3 @@ func main() {
os.Exit(1)
}
}

func getReleaseVersion() string {
releaseVersion := os.Getenv(releaseVersionEnvVariableName)
if len(releaseVersion) == 0 {
releaseVersion = unknownVersionValue
klog.Infof("%s environment variable is missing, defaulting to %q", releaseVersionEnvVariableName, unknownVersionValue)
}
return releaseVersion
}
2 changes: 2 additions & 0 deletions cmd/config-sync-controllers/main.go
Expand Up @@ -120,6 +120,7 @@ func main() {
ClusterOperatorStatusClient: controllers.ClusterOperatorStatusClient{
Client: mgr.GetClient(),
Recorder: mgr.GetEventRecorderFor("cloud-controller-manager-operator-cloud-config-sync-controller"),
ReleaseVersion: controllers.GetReleaseVersion(),
ManagedNamespace: *managedNamespace,
},
Scheme: mgr.GetScheme(),
Expand All @@ -132,6 +133,7 @@ func main() {
ClusterOperatorStatusClient: controllers.ClusterOperatorStatusClient{
Client: mgr.GetClient(),
Recorder: mgr.GetEventRecorderFor("cloud-controller-manager-operator-ca-sync-controller"),
ReleaseVersion: controllers.GetReleaseVersion(),
ManagedNamespace: *managedNamespace,
},
Scheme: mgr.GetScheme(),
Expand Down
Expand Up @@ -91,6 +91,9 @@ spec:
- containerPort: 9260
name: healthz
protocol: TCP
env:
- name: RELEASE_VERSION
value: "0.0.1-snapshot"
resources:
requests:
cpu: 10m
Expand Down
16 changes: 16 additions & 0 deletions pkg/controllers/status.go
Expand Up @@ -3,6 +3,7 @@ package controllers
import (
"context"
"fmt"
"os"
"reflect"
"strings"

Expand Down Expand Up @@ -31,6 +32,11 @@ const (
defaultManagementNamespace = "openshift-cloud-controller-manager-operator"
)

const (
releaseVersionEnvVariableName = "RELEASE_VERSION"
unknownVersionValue = "unknown"
)

type ClusterOperatorStatusClient struct {
client.Client
Recorder record.EventRecorder
Expand Down Expand Up @@ -204,3 +210,13 @@ func (r *ClusterOperatorStatusClient) syncStatus(ctx context.Context, co *config

return r.Status().Update(ctx, co)
}

// GetReleaseVersion gets the release version string from the env
func GetReleaseVersion() string {
releaseVersion := os.Getenv(releaseVersionEnvVariableName)
if len(releaseVersion) == 0 {
releaseVersion = unknownVersionValue
klog.Infof("%s environment variable is missing, defaulting to %q", releaseVersionEnvVariableName, unknownVersionValue)
}
return releaseVersion
}

0 comments on commit 77612b9

Please sign in to comment.