From 3c13cb48906fff6620b03af7a26fa9e897bd0ab2 Mon Sep 17 00:00:00 2001 From: Wen Zhou Date: Thu, 19 Sep 2024 14:20:06 +0200 Subject: [PATCH] feat: pass platform from env variable or fall back to use old logic - introduce new env var ODH_PLATFORM_TYPE set during buildtime - rename old function GetPlatform() to DetectPlatform() - create new GetPlatform to check env first or fall to call DetectPlatform() Signed-off-by: Wen Zhou --- ...datahub-operator.clusterserviceversion.yaml | 8 +++++--- config/manager/manager.yaml | 2 ++ pkg/cluster/cluster_config.go | 18 ++++++++++++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/bundle/manifests/opendatahub-operator.clusterserviceversion.yaml b/bundle/manifests/opendatahub-operator.clusterserviceversion.yaml index ad5272d170a..4ca35a31f59 100644 --- a/bundle/manifests/opendatahub-operator.clusterserviceversion.yaml +++ b/bundle/manifests/opendatahub-operator.clusterserviceversion.yaml @@ -104,11 +104,11 @@ metadata: certified: "False" containerImage: quay.io/opendatahub/opendatahub-operator:v2.18.0 createdAt: "2024-09-17T16:16:19Z" - olm.skipRange: '>=1.0.0 <2.18.0' + olm.skipRange: '>=1.0.0 <2.18.1' operators.operatorframework.io/builder: operator-sdk-v1.31.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 repository: https://github.com/opendatahub-io/opendatahub-operator - name: opendatahub-operator.v2.18.0 + name: opendatahub-operator.v2.18.1 namespace: placeholder spec: apiservicedefinitions: {} @@ -1131,6 +1131,8 @@ spec: fieldPath: metadata.namespace - name: DEFAULT_MANIFESTS_PATH value: /opt/manifests + - name: ODH_PLATFORM_TYPE + value: OpenDataHub image: REPLACE_IMAGE:latest imagePullPolicy: Always livenessProbe: @@ -1216,7 +1218,7 @@ spec: selector: matchLabels: component: opendatahub-operator - version: 2.18.0 + version: 2.18.1 webhookdefinitions: - admissionReviewVersions: - v1 diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 0aadbcc2e89..bff26ae5022 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -46,6 +46,8 @@ spec: fieldPath: metadata.namespace - name: DEFAULT_MANIFESTS_PATH value: /opt/manifests + - name: ODH_PLATFORM_TYPE + value: OpenDataHub args: - --leader-elect - --operator-name=opendatahub diff --git a/pkg/cluster/cluster_config.go b/pkg/cluster/cluster_config.go index a1c462aeeee..13a82632357 100644 --- a/pkg/cluster/cluster_config.go +++ b/pkg/cluster/cluster_config.go @@ -114,7 +114,7 @@ func detectManagedRHODS(ctx context.Context, cli client.Client) (Platform, error return ManagedRhods, nil } -func GetPlatform(ctx context.Context, cli client.Client) (Platform, error) { +func DetectPlatform(ctx context.Context, cli client.Client) (Platform, error) { // First check if its addon installation to return 'ManagedRhods, nil' if platform, err := detectManagedRHODS(ctx, cli); err != nil { return Unknown, err @@ -126,6 +126,20 @@ func GetPlatform(ctx context.Context, cli client.Client) (Platform, error) { return detectSelfManaged(ctx, cli) } +func GetPlatform(ctx context.Context, cli client.Client) (Platform, error) { + switch os.Getenv("ODH_PLATFORM_TYPE") { + case "OpenDataHub", "": + return OpenDataHub, nil + case "ManagedRHOAI": + return ManagedRhods, nil + case "SelfManagedRHOAI": + return SelfManagedRhods, nil + default: + // fall back to detect platform if ODH_PLATFORM_TYPE env is not provided + return DetectPlatform(ctx, cli) + } +} + // Release includes information on operator version and platform // +kubebuilder:object:generate=true type Release struct { @@ -141,7 +155,7 @@ func GetRelease(ctx context.Context, cli client.Client) (Release, error) { }, } // Set platform - platform, err := GetPlatform(ctx, cli) + platform, err := DetectPlatform(ctx, cli) if err != nil { return initRelease, err }