grafana / helm-charts

Apache License 2.0
1.6k stars 2.24k forks source link

[loki-distributed] Compactor affinity error #2440

Open whaleqiss opened 1 year ago

whaleqiss commented 1 year ago

Hello, when in compactor section I write this code:

  affinity: |
    podAntiAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        - labelSelector:
            matchLabels:
              {{- include "loki.compactorSelectorLabels" . | nindent 10 }}
          topologyKey: kubernetes.io/hostname
      preferredDuringSchedulingIgnoredDuringExecution:
        - weight: 100
          podAffinityTerm:
            labelSelector:
              matchLabels:
                {{- include "loki.compactorSelectorLabels" . | nindent 12 }}
            topologyKey: failure-domain.beta.kubernetes.io/zone
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
          - matchExpressions:
              - key: node_pool
                operator: In
                values:
                  - kristina-dev-node-pool

Flux give me this error:

Helm upgrade failed: error validating "": error validating data: ValidationError(Deployment.spec.template.spec.affinity): invalid type for io.k8s.api.core.v1.Affinity: got "string", expected "map"

knechtionscoding commented 1 year ago

Remove the | from after affinity.

It should be a map, not a string, as the error implies.

whaleqiss commented 1 year ago

Remove the | from after affinity.

It should be a map, not a string, as the error implies.

I deleted the |, it's the same. For other components the code written in the same way doesn't give an error.

zanhsieh commented 1 year ago

It's because compactor under loki-distributed chart does not take the same syntax as others: https://github.com/grafana/helm-charts/blob/610ee0630581667fe06af39a5a11059faa54b85d/charts/loki-distributed/templates/compactor/deployment-compactor.yaml#L109

Should be

        {{- tpl . $ | nindent 8 }}

comparing other components: https://github.com/grafana/helm-charts/blob/610ee0630581667fe06af39a5a11059faa54b85d/charts/loki-distributed/templates/gateway/deployment-gateway.yaml#L95 https://github.com/grafana/helm-charts/blob/610ee0630581667fe06af39a5a11059faa54b85d/charts/loki-distributed/templates/distributor/deployment-distributor.yaml#L107 https://github.com/grafana/helm-charts/blob/610ee0630581667fe06af39a5a11059faa54b85d/charts/loki-distributed/templates/index-gateway/statefulset-index-gateway.yaml#L102 https://github.com/grafana/helm-charts/blob/610ee0630581667fe06af39a5a11059faa54b85d/charts/loki-distributed/templates/ingester/deployment-ingester.yaml#L106 https://github.com/grafana/helm-charts/blob/610ee0630581667fe06af39a5a11059faa54b85d/charts/loki-distributed/templates/ingester/statefulset-ingester.yaml#L121 https://github.com/grafana/helm-charts/blob/610ee0630581667fe06af39a5a11059faa54b85d/charts/loki-distributed/templates/memcached-chunks/statefulset-memcached-chunks.yaml#L122 ...

whaleqiss commented 1 year ago

comparing other components:

but the same {{- tpl . $ | nindent 8 }} config for other components

zanhsieh commented 1 year ago

@whaleqiss you might try to modify it locally to see if that fix your problem first, then PR it. i don't have any idea if that the syntax difference was just typo or purposed made. Something like this:

git checkout https://github.com/grafana/helm-charts.git grafana-helm-chart
cd grafana-helm-chart/charts/loki-distributed
vi ./templates/compactor/deployment-compactor.yaml
# change to {{- toYaml . | nindent 8 }} 
helm install <your-release-name> .
whaleqiss commented 1 year ago

Nothing changed :( it’s the same error

DeveloperDarkhan commented 10 months ago

@whaleqiss

Here is my work manifest for Loki-distributed

compactor:
     ...
      affinity: 
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: name
                operator: In
                values:
                - infrastructure
            - matchExpressions:
              - key: type
                operator: In
                values:
                - db

gateway:
...
      affinity: |
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: name
                operator: In
                values:
                - infrastructure
            - matchExpressions:
              - key: type
                operator: In
                values:
                - db

I use | everywhere in affinity section except compactor.