Skip to content

Unable to set an custom nodeAffinity via values.yaml #495

@comjf

Description

@comjf

Problem:
Unable to add custom .Values.affinity because of duplicate nodeAffinity definition

This is because you have already defined a default affinity in your helm deployment.yaml template

Bug-in-action:
my-values.yaml

emitKubernetesEvents: true
checkASGTagBeforeDraining: true
enablePrometheusServer: true
enableSqsTerminationDraining: true
ignoreDaemonSets: true
managedAsgTag: aws-node-termination-handler/managed/cluster
queueURL: something-valid
serviceAccount:
  create: true
  name: node-termination-handler
  annotations:
    eks.amazonaws.com/role-arn: "something-valid"
affinity:
  nodeAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
      nodeSelectorTerms:
      - matchExpressions:
        - key: node-role
          operator: In
          values:
          - system

Helm generated output (using 0.15.3 on a dry run install: helm install . --dry-run --debug -f ../my-values.yaml --generate-name)

    spec:
      priorityClassName: "system-node-critical"
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                - key: "kubernetes.io/os"
                  operator: In
                  values:
                    - linux
                - key: "kubernetes.io/arch"
                  operator: In
                  values:
                    - amd64
                    - arm64
                    - arm
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: node-role
                operator: In
                values:
                - system
...

As you can see there are duplicates, and what ends up happening is that helm drops the default (your) nodeAffinity in favor of the values provided one. On my deployed pod, only that second affinity is listed.

In other words, this node-termination-handler bug doesn't affect our current deployment, however this behavior does fully break when using newer versions of fluxcd/flux2 and more specifically kustomize 4 as it now errors out on duplicate yaml keys

I know ya'll probably don't care too much about some tool on top of helm, but I believe more people will run into this and there is an underlying bug here with the way the template is written, so I figured best to report.

Proposed Solution
Why do we even need the hard-coded affinity on the deployment.yaml template?? I can see how it makes a difference for the daemonset approach, but for the SQS listener... is it really needed?

I tried to reconcile the two so you could pass in .Values.affinity and it will merge with your default hardcoded affinity... but I'm having difficulty getting that to work because of the _helper template and includes that are used to build the default affinity. If this is really needed, I'm open to suggestions on how to fix.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority: LowThis issue will not be seen by most users. The issue is a very specific use case or corner caseStatus: Work in ProgressType: BugSomething isn't workingstalebot-ignoreTo NOT let the stalebot update or close the Issue / PR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions