zegl / kube-score

Kubernetes object analysis with recommendations for improved reliability and security. kube-score actively prevents downtime and bugs in your Kubernetes YAML and Charts. Static code analysis for Kubernetes.
https://kube-score.com
MIT License
2.74k stars 176 forks source link

deployment-has-host-podantiaffinity / statefulset-has-host-podantiaffinity generates false positives #297

Closed Iristyle closed 4 years ago

Iristyle commented 4 years ago

Which version of kube-score are you using?

kube-score version: 1.8.1, commit: cdab99b6ee4d135bb716a92cbb91828ea28ff492, built: 2020-08-11T08:12:42Z

What did you do?

    spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app.kubernetes.io/name
                operator: In
                values:
                - issuer
            topologyKey: kubernetes.io/hostname

What did you expect to see?

Given a podAntiAffinity like the above (similar to the example at https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#always-co-located-in-the-same-node), I would expect the following to meet the guidelines for deployment-has-host-podantiaffinity / statefulset-has-host-podantiaffinity

What did you see instead?

[WARNING] StatefulSet has host PodAntiAffinity
        · StatefulSet does not have a host podAntiAffinity set
            It's recommended to set a podAntiAffinity that stops multiple pods
            from a statefulset from being scheduled on the same node. This
            increases availability in case the node becomes unavailable.

If I instead to switch to what is in the tests then the check passes

    spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 100
            podAffinityTerm:
              labelSelector:
                matchLabels:
                  app.kubernetes.io/name: issuer
              topologyKey: kubernetes.io/hostname
Iristyle commented 4 years ago

You know what -- I think the docs / examples at https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#always-co-located-in-the-same-node may be outdated. Just trying to deploy, and I'm getting validation errors. This might be my mistake!

UPDATE: Yeah, the docs are not up to date with the schema. Closing!