multicloud-operators-subscription icon indicating copy to clipboard operation
multicloud-operators-subscription copied to clipboard

Pass Values from a relative Path in a Git Repo to a HelmRelease created by Subscription

Open abdennour opened this issue 2 years ago • 1 comments
trafficstars

I have helm chart in a Git repo, and alongside the file "values.yaml" there is other Values files within same directory ( same helm chart directory).

-- my-git-repo
 |___myapp/
           |__ templates/
           |__ Chart.yaml
           |__ values.yaml
           |__ values.cluster1.yaml

With helm command, it's about :

cd my-git-repo
helm install xxx ./myapp/ -f values.cluster1.yaml

How to reach the same with Subscription/Channel resources?

So far, this is the resources that i configured:

apiVersion: app.k8s.io/v1beta1
kind: Application
metadata:
  name: test-myapp
  namespace: services
spec:
  componentKinds:
  - group: apps.open-cluster-management.io
    kind: Subscription
  descriptor: {}
  selector:
    matchExpressions:
      - key: app
        operator: In
        values: 
          - test-myapp
---
apiVersion: v1
kind: Namespace
metadata:
  name: gbitbucketcompanycom-scl-boilerplate-helm-releases-ns
---
apiVersion: apps.open-cluster-management.io/v1
kind: Channel
metadata:
  annotations:
    apps.open-cluster-management.io/reconcile-rate: medium
  name: gbitbucketcompanycom-scl-boilerplate-helm-releases
  namespace: gbitbucketcompanycom-scl-boilerplate-helm-releases-ns
spec:
  type: Git
  pathname: 'https://bitbucket.company.com/scl/boilerplate-helm-releases.git'
  secretRef:
    name: gbitbucketcompanycom-scl-boilerplate-helm-releases-auth
---
apiVersion: v1
kind: Secret
metadata:
  name: gbitbucketcompanycom-scl-boilerplate-helm-releases-auth
  namespace: gbitbucketcompanycom-scl-boilerplate-helm-releases-ns
data:
  user: # injected on create
  accessToken: # injected on create
---
apiVersion: apps.open-cluster-management.io/v1
kind: Subscription
metadata:
  annotations:
    apps.open-cluster-management.io/git-branch: master
    apps.open-cluster-management.io/git-path: myapp
    apps.open-cluster-management.io/reconcile-option: merge
  labels:
    app: test-myapp
  name: test-myapp-subscription-1
  namespace: services
spec:
  channel: gbitbucketcompanycom-scl-boilerplate-helm-releases-ns/gbitbucketcompanycom-scl-boilerplate-helm-releases
  placement:
    placementRef:
      kind: PlacementRule
      name: test-myapp-placement-1
---
apiVersion: apps.open-cluster-management.io/v1
kind: PlacementRule
metadata:
  labels:
    app: test-myapp
  name: test-myapp-placement-1
  namespace: services
spec:
  clusterSelector:
    matchLabels:
       cluster-env: lab

After creating those resources, a resource HelmRelease has been auto-generated in the target cluster, and it looks like :

apiVersion: apps.open-cluster-management.io/v1
kind: HelmRelease
metadata:
  annotations:
    apps.open-cluster-management.io/hosting-subscription: services/test-myapp-subscription-1
  finalizers:
    - uninstall-helm-release
  generation: 1
  labels:
    app: test-myapp
    app.kubernetes.io/part-of: test-myapp
    apps.open-cluster-management.io/reconcile-rate: medium
  name: myapp-e7b58
  namespace: services
  ownerReferences:
    - apiVersion: apps.open-cluster-management.io/v1
      kind: Subscription
      name: test-myapp-subscription-1
      uid: xxxxxx-tttt-dddd-eeee-xxxxxx

repo:
  chartName: myapp
  digest: generated-by-multicloud-operators-subscription
  secretRef:
    name: gbitbucketcompanycom-scl-boilerplate-helm-releases-auth
    namespace: gbitbucketcompanycom-scl-boilerplate-helm-releases-ns
  source:
    git:
      branch: master
      chartPath: myapp
      urls:
        - https://bitbucket.company.com/scl/boilerplate-helm-releases.git
    type: git
  version: 0.1.0
spec:
  '': ''
status:
  conditions:
    - lastTransitionTime: 'xxx'
      reason: InstallSuccessful
      status: 'True'
      type: Deployed
  deployedRelease:
    name: myapp-e7b58

Is there a way to pass values file path (relative to the chart directory) to the HelmRelease CR thru its Subscription CR ?

abdennour avatar May 03 '23 23:05 abdennour

https://github.com/open-cluster-management-io/multicloud-operators-subscription/blob/main/examples/helmrepo-channel/02-subscription.yaml#L10-L17

  packageOverrides:
  - packageName: nginx-ingress # your helm chart name
    packageAlias: nginx-ingress-simple # this will enforce a helm release name ie: when you do helm ls
    packageOverrides:
    - path: spec # must be this value 
      value: # below this key is where you define the "values.yaml" overrides
        defaultBackend:
          replicaCount: 3

Does that help answer your question?

mikeshng avatar May 03 '23 23:05 mikeshng