Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add value reference in OperandConfig #990

Merged
merged 4 commits into from
Nov 2, 2023

Conversation

Daniel-Fan
Copy link
Contributor

@Daniel-Fan Daniel-Fan commented Nov 1, 2023

Overview

NOTE: Basic test cases are added in this PR, and overall usage is illustrated below. I will create another PR to add more test cases and write complete doc.

ODLM OperandConfig supports to reference value from ConfigMap, Secret and other arbitrary objects.
templatingValueFrom is the top level key for the entire Templating Structure.

Default hardcode value reference

Template

image: 
  templatingValueFrom:
     default:
        defaultValue: cp.icr.io/cp/cpd/edb-postgres-license-provider@sha256:2f302acebe51e10c5ddb24e425b70eebda3cd0cc1696a01e9aa1c51558da5f99

Final rendered template

image:  cp.icr.io/cp/cpd/edb-postgres-license-provider@sha256:2f302acebe51e10c5ddb24e425b70eebda3cd0cc1696a01e9aa1c51558da5f99

ConfigMap Key value reference

configMapkeyRef could be added under templatingValueFrom or templatingValueFrom.default

Template

apiVersion: v1
kind: ConfigMap
metadata:
  name: cloud-native-postgresql-image-list
data:
  edb-postgres-license-provider-image: default-image
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: customized-license
data:
  customized-license-provider-image: custom-image
---
image:
    templatingValueFrom:
      default:
        configMapKeyRef:
          name: cloud-native-postgresql-image-list
          namespace: xxx
          key: edb-postgres-license-provider-image
      configMapKeyRef:
        name: customized-license
        namespace: xxx
        key: customized-license-provider-image

Final rendered template

When there are multiple references exist, the latter takes precedence.

image:  custom-image

Secret Key value reference

secretKeyRef could be added under templatingValueFrom or templatingValueFrom.default

Template

apiVersion: v1
kind: Secret
metadata:
  name: keycloak-custom-tls-secret
  namespace: 
data:
  ca.crt: data-string
---
caCertificate:
    templatingValueFrom:
      secretKeyRef:
        key: ca.crt
        name: keycloak-custom-tls-secret

Final rendered template

caCertificate: data-string

Arbitrary Object

objectRef could be added under templatingValueFrom or templatingValueFrom.default

Template

kind: Route
apiVersion: route.openshift.io/v1
metadata:
  name: keycloak
spec:
  host: keycloak.apps.installer-cp3pt0.cp.fyre.ibm.com
---
hostname:
  templatingValueFrom:
    objectRef:
      apiVersion: route.openshift.io/v1
      kind: Route
      name: keycloak
      path: .spec.host
SERVICE_ENDPOINT:
  templatingValueFrom:
    objectRef:
      apiVersion: v1
      kind: Service
      name: my-service
      path: https://+.metadata.name+.+.metadata.namespace+.+svc:+.spec.ports[0].port

Final rendered template

hostname: keycloak.apps.installer-cp3pt0.cp.fyre.ibm.com
SERVICE_ENDPOINT: https://my-service.<namespace>.svc:8001

Additional attributes

required could be added under templatingValueFrom or templatingValueFrom.default

  • required: true: the value reference could not be empty
  • required: false: the value reference could be empty

Template

apiVersion: v1
kind: ConfigMap
metadata:
  name: reference-map
data:
  domain_name: installer-cp3
---
domain:
    templatingValueFrom:
      required: true
      configMapKeyRef:
        name: reference-map
        key: non_domain_name

Final rendered template

It failed to render the template, because required: true is set.
Key non_domain_name does not exist in ConfigMap reference-map, domain in template has nothing to reference.

Signed-off-by: Daniel Fan <fanyuchensx@gmail.com>
@Daniel-Fan
Copy link
Contributor Author

/retest

Signed-off-by: Daniel Fan <fanyuchensx@gmail.com>
Signed-off-by: Daniel Fan <fanyuchensx@gmail.com>
Signed-off-by: Daniel Fan <fanyuchensx@gmail.com>
Copy link
Contributor

@YCShen1010 YCShen1010 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@ibm-ci-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Daniel-Fan, YCShen1010

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [Daniel-Fan,YCShen1010]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ibm-ci-bot ibm-ci-bot merged commit 15c4823 into IBM:master Nov 2, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants