kubernetes: Confusing error message with apps/v1beta2.statefulset

apps/v1beta2.StatefulSet is going to have a change that changes the defaulting behavior. The user facing aspect of this change is that .Spec.selector will need to be provided when trying to create an object.

apiVersion: apps/v1beta2
kind: StatefulSet
metadata:
  name: test
spec:
  serviceName: "test"
  replicas: 2
  template:
    metadata:
      labels:
        name: test
    spec:
      containers:
      - name: alpine
        image: alpine
        command: 
        - /bin/sleep
        - "1000000"

Trying to create this object throws the following errors:

The StatefulSet "test" is invalid: 
* spec.selector: Required value
* spec.template.metadata.labels: Invalid value: map[string]string{"name":"test"}: `selector` does not match template `labels`

We could have a better error message that indicates:

(1) The spec.selector must match at least one label in spec.template.metadata.labels (2) Optionally, also saying that the spec.selector is set-based (as opposed to being equality based)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

I stumbled on this too and found the error message pretty confusing. Without this issue, it would have taken me a lot longer to find the answer.

If it helps someone else, here’s exactly what I had to do.

From extensions/v1beta1

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: test
spec:
  template:
    metadata:
      labels:
        k8s-app: test
    spec:
      containers:
      - name: test
        image: alpine
        command: ["/bin/sh","-c","echo 'Napping...' && sleep 10000"]

to apps/v1beta2

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: test
spec:
  selector:
    matchLabels:
      k8s-app: test
  template:
    metadata:
      labels:
        k8s-app: test
    spec:
      containers:
      - name: test
        image: alpine
        command: ["/bin/sh","-c","echo 'Napping...' && sleep 10000"]

The line that says spec.selector: Required value does seem to help in this case. It points at the problem that you now must set that field explicitly.

@foxish In the case you described this morning, spec.selector was filled in but with the wrong format. Did it not complain about spec.selector being missing in that case?

Maybe it would help if the second error about labels not matching also printed the value of spec.selector so you could see that it is using a value you didn’t expect?