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

Merge lists? #4514

Closed
dev-samples opened this issue Mar 11, 2022 · 6 comments
Closed

Merge lists? #4514

dev-samples opened this issue Mar 11, 2022 · 6 comments
Labels
kind/support Categorizes issue or PR as a support question. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.

Comments

@dev-samples
Copy link

In my base I have:

base/deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ldap
  labels:
    app: ldap
spec:
  template:
    metadata:
      labels:
        app: ldap
    spec:
      containers:
        - name: ldap
          containerEnv:
            - name: BASE_A
              value: "value-a"
            - name: BASE_B
              value: "value-b"

base/kustomization.yaml

resources:
- deployment.yaml

In my overlay I have:

overlay/deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ldap
  labels:
    app: ldap
spec:
  template:
    metadata:
      labels:
        app: ldap
    spec:
      containers:
        - name: ldap
          containerEnv:
            - name: OVERLAY_X
              value: "value-x"
            - name: OVERLAY_Y
              value: "value-y"

overlay/kustomization.yaml

resources:
- ../base
patchesStrategicMerge:
- deployment.yaml

But when I build its only the ENVs from the overlay that gets generated:

kustomize build .
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: ldap
  name: ldap
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ldap
  template:
    metadata:
      labels:
        app: ldap
    spec:
      containers:
      - containerEnv:
        - name: OVERLAY_X
          value: value-x
        - name: OVERLAY_Y
          value: value-y
        name: ldap

How do I merge lists?

Possibly related:
fluxcd/helm-controller#300

@k8s-ci-robot k8s-ci-robot added the needs-kind Indicates a PR lacks a `kind/foo` label and requires one. label Mar 11, 2022
@k8s-ci-robot
Copy link
Contributor

@dev-samples: This issue is currently awaiting triage.

SIG CLI takes a lead on issue triage for this repo, but any Kubernetes member can accept issues by applying the triage/accepted label.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Mar 11, 2022
@KnVerey
Copy link
Contributor

KnVerey commented Mar 16, 2022

The field name is env, not containerEnv. I've confirmed that the merge works as expected with that fixed.

/close
/kind support

@k8s-ci-robot k8s-ci-robot added the kind/support Categorizes issue or PR as a support question. label Mar 16, 2022
@k8s-ci-robot
Copy link
Contributor

@KnVerey: Closing this issue.

In response to this:

The field name is env, not containerEnv. I've confirmed that the merge works as expected with that fixed.

/close
/kind support

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot removed the needs-kind Indicates a PR lacks a `kind/foo` label and requires one. label Mar 16, 2022
@dev-samples
Copy link
Author

Yes you are right works as expected. The example I provided was not really clear, sorry for that. I am trying to patch this values file:
https://github.com/jenkinsci/helm-charts/blob/main/charts/jenkins/values.yaml

in a flux release. E.g with this base:

base/kustomization.yaml

resources:
- release.yaml

base/release.yaml

---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: jenkins
  namespace: jenkins
  annotations:
    flux.weave.works/automated: "true"
spec:
  releaseName: jenkins
  interval: 5m
  chart:
    spec:
      chart: jenkins
      version: 3.11.4
      sourceRef:
        kind: HelmRepository
        name: jenkins
        namespace: flux-system
  values:
    rbac:
      create: true
      readSecrets: true   
    controller:
      containerEnv:
        - name: BASE_VAR_A
          value: "base-value-a"
        - name: BASE_VAR_B
          value: "base-value-b"

And this overlay.

dev/kustomization.yaml

resources:
- ../base
patchesStrategicMerge:
- release.yaml

dev/release.yaml

---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: jenkins
  namespace: jenkins
  annotations:
    flux.weave.works/automated: "true"
spec:
  releaseName: jenkins
  interval: 5m
  chart:
    spec:
      chart: jenkins
      version: 3.11.4
      sourceRef:
        kind: HelmRepository
        name: jenkins
        namespace: flux-system
  values:
    rbac:
      create: true
      readSecrets: true   
    controller:
      containerEnv:
        - name: OVERLAY_X
          value: "overlay-value-a"
        - name: OVERLAY_Y
          value: "overlay-value-b"

But when I run build I get:

apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  annotations:
    flux.weave.works/automated: "true"
  name: jenkins
  namespace: jenkins
spec:
  chart:
    spec:
      chart: jenkins
      sourceRef:
        kind: HelmRepository
        name: jenkins
        namespace: flux-system
      version: 3.11.4
  interval: 5m
  releaseName: jenkins
  values:
    controller:
      containerEnv:
      - name: OVERLAY_X
        value: overlay-value-a
      - name: OVERLAY_Y
        value: overlay-value-b
    rbac:
      create: true
      readSecrets: true

So the base values are gone. I am sure I am missing something basic here maybe that kustomize is not working with arbitrary values files?

@natasha41575
Copy link
Contributor

Kustomize gets merge keys from openapi data, so if you want it to merge CRDs you will have to provide your own openapi schema through the openapi field. You will have to specify the merge key for the spec.values.controller.containerEnv object.

Docs are here, with an example: https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/openapi/

It's not the easiest thing in the world to do ATM but we are hoping to come up with a better way to support CRDs.

@dev-samples
Copy link
Author

Ok that's gonna be a mess since in the case of flux most objects are crds.

Also how would the openAPI know that this is a mix of a flux crd and elements from a values file from the Jenkins helm chart?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Categorizes issue or PR as a support question. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.
Projects
None yet
Development

No branches or pull requests

4 participants