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.77k stars 178 forks source link

podAntiAffinity throws error when topologyKey for zones are used #390

Closed anthr76 closed 3 years ago

anthr76 commented 3 years ago

Which version of kube-score are you using?

kube-score version: 1.12.0, commit: 82810c42bb501443116bfb67dde81bc2f68fa318, built: 2021-08-28T20:47:35Z

Wrote a deployment with

      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - podAffinityTerm:
              labelSelector:
                matchExpressions:
                - key: app.kubernetes.io/name
                  operator: In
                  values:
                  - secret-app
              topologyKey: topology.kubernetes.io/zone
            weight: 60

Got told:

apps/v1/Deployment secret-app in secret-app                              🤔                                             
    [WARNING] Deployment has host PodAntiAffinity                                                                            
        · Deployment does not have a host podAntiAffinity set                                                                
            It's recommended to set a podAntiAffinity that stops multiple pods                                               
            from a deployment from being scheduled on the same node. This                                                    
            increases availability in case the node becomes unavailable.                                                     

Though if I change the topologyKey to hostname it works..

      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - podAffinityTerm:
              labelSelector:
                matchExpressions:
                - key: app.kubernetes.io/name
                  operator: In
                  values:
                  - secret-app
              topologyKey: topology.kubernetes.io/hostname
            weight: 60

Commands used to invoke kubescore

kustomize build . | kube-score score --ignore-test container-image-pull-policy --ignore-test pod-networkpolicy --ignore-tes
t deployment-has-poddisruptionbudget -                                                                                       
anthr76 commented 3 years ago

https://github.com/zegl/kube-score/blob/f6e65726ad2b61529a7d2c467b1c9349330f85f4/score/apps/apps.go#L120-L142