Skip to content

Commit

Permalink
feat: pass platform from env variable or fall back to use old logic
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
zdtsw committed Sep 19, 2024
1 parent c87dc1c commit 3c13cb4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -1216,7 +1218,7 @@ spec:
selector:
matchLabels:
component: opendatahub-operator
version: 2.18.0
version: 2.18.1
webhookdefinitions:
- admissionReviewVersions:
- v1
Expand Down
2 changes: 2 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions pkg/cluster/cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit 3c13cb4

Please sign in to comment.