Skip to content

Commit

Permalink
feat: pass platform from env variables 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, value set during build time
  - if value not match, fall back to detect managed then self-managed
- introduce new env var OPERATOR_RELEASE_VERSION, value also set during build time
  - if value is empty, fall back to use old way from CSV to read version or use 0.0.0
- add support from makefile
  - use envstubst to replace version

Signed-off-by: Wen Zhou <[email protected]>
  • Loading branch information
zdtsw committed Oct 7, 2024
1 parent cb86031 commit fd0c1dc
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ prepare: manifests kustomize manager-kustomization
.PHONY: manager-kustomization
manager-kustomization: config/manager/kustomization.yaml.in
cd config/manager \
&& cp -f kustomization.yaml.in kustomization.yaml \
&& export RELEASE_VERSION=$(VERSION) \
&& envsubst < kustomization.yaml.in > kustomization.yaml \
&& $(KUSTOMIZE) edit set image controller=$(IMG)

.PHONY: install
Expand Down
2 changes: 1 addition & 1 deletion apis/datasciencecluster/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apis/dscinitialization/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1085,12 +1085,16 @@ spec:
env:
- name: DISABLE_DSC_CONFIG
value: "true"
- name: OPERATOR_RELEASE_VERSION
+ value: 2.18.2
- name: OPERATOR_NAMESPACE
valueFrom:
fieldRef:
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
13 changes: 13 additions & 0 deletions config/manager/kustomization.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,16 @@ kind: Kustomization
images:
- name: controller
newName: REPLACE_IMAGE

patches:
- target:
kind: Deployment
name: controller-manager
version: v1
group: apps
patch: |-
- op: add
path: /spec/template/spec/containers/0/env/1
value:
name: OPERATOR_RELEASE_VERSION
value: $RELEASE_VERSION
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
31 changes: 23 additions & 8 deletions pkg/cluster/cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,21 @@ func detectManagedRHODS(ctx context.Context, cli client.Client) (Platform, error
}

func getPlatform(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
} else if platform == ManagedRhods {
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
if platform, err := detectManagedRHODS(ctx, cli); err != nil {
return Unknown, err
} else if platform == ManagedRhods {
return ManagedRhods, nil
}
return detectSelfManaged(ctx, cli)
}

// check and return whether ODH or self-managed platform
return detectSelfManaged(ctx, cli)
}

func getRelease(ctx context.Context, cli client.Client) (Release, error) {
Expand All @@ -197,7 +203,16 @@ func getRelease(ctx context.Context, cli client.Client) (Release, error) {
if os.Getenv("CI") == "true" {
return initRelease, nil
}
// Set Version

// Set Version, if empty string from OPERATOR_RELEASE_VERSION, use CSV version instead.
if os.Getenv("OPERATOR_RELEASE_VERSION") != "" {
initRelease.Version.Version, err = semver.Parse(os.Getenv("OPERATOR_RELEASE_VERSION"))
if err != nil {
return initRelease, err
}
}

// fallback to use CSV version
// Get watchNamespace
operatorNamespace, err := GetOperatorNamespace()
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/cluster/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fd0c1dc

Please sign in to comment.