kubernetes: Unable to apply anti-affinity rules on "all namespaces" for pods

What keywords did you search in Kubernetes issues before filing this one? (If you have found any duplicates, you should instead reply there.):

pod anti-affinity


Is this a BUG REPORT or FEATURE REQUEST? (choose one):

BUG REPORT

Kubernetes version (use kubectl version):

k8s: 1.6.4 client-go: v3.0.0-beta

Environment:

  • Cloud provider or hardware configuration: GKE
  • OS (e.g. from /etc/os-release):
  • Kernel (e.g. uname -a):
  • Install tools:
  • Others:

What happened:

For pod’s affinity field:

	affinity := &v1.Affinity{
		PodAntiAffinity: &v1.PodAntiAffinity{
			RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{
				{
					LabelSelector: "...",
					TopologyKey:   "kubernetes.io/hostname",
					Namespaces:   []string{...},
				},
			},
		},
	}

Namespaces will apply the affinity rules on the namespaces specified.

However, if I provide api.NamespaceAll, the pods API will return error:

cluster failed to setup: Pod \"example-0000\" is invalid:
spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution[0].namespace: 
Invalid value: \"\": a DNS-1123 label must consist of lower case alphanumeric characters or '-', 
and must start and end with an alphanumeric character (e.g. 'my-name',  or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')

What you expected to happen: setting api.NamespaceAll should make affinity rules apply to all namespaces.

How to reproduce it (as minimally and precisely as possible):

Should be straight-forward. I can write a test program if needed.

Anything else we need to know:

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (13 by maintainers)

Most upvoted comments

cherry pick (back merge) to 1.6, 1.7 if necessary.