Skip to content

Short name for Issuer CRD is invalid #208

Closed
gardener/cert-management
#147

Description

How to categorize this issue?

/kind bug

What happened:
The issuer CRD definition wrongly uses the singular name as short name

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: issuers.cert.gardener.cloud
labels:
shoot.gardener.cloud/no-cleanup: "true"
app.kubernetes.io/name: gardener-extension-shoot-cert-service
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
group: cert.gardener.cloud
names:
kind: Issuer
listKind: IssuerList
plural: issuers
shortNames:
- issuer

K8s CRD controller has a validation that the short names is not re-used in other CRDs among the same group, see https://github.com/kubernetes/kubernetes/blob/e8d45596dfbdf69fd42aa6881dfdeb089a20ab33/staging/src/k8s.io/apiextensions-apiserver/pkg/controller/status/naming_controller.go#L123-L169 and https://github.com/kubernetes/kubernetes/blob/e8d45596dfbdf69fd42aa6881dfdeb089a20ab33/staging/src/k8s.io/apiextensions-apiserver/pkg/controller/status/naming_controller.go#L89-L121

What you expected to happen:
The short names for issuer to not be the same as the singular name.

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

  1. Create a k8s cluster, e.g. kind
  2. Run the following command to create the CRD without the shortNames
cat <<EOF | kubectl create -f -
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: issuers.cert.gardener.cloud
spec:
  conversion:
    strategy: None
  group: cert.gardener.cloud
  names:
    kind: Issuer
    listKind: IssuerList
    plural: issuers
    singular: issuer
  scope: Namespaced
  versions:
  - name: v1alpha1
    schema:
      openAPIV3Schema:
        type: object
        x-kubernetes-preserve-unknown-fields: true
    served: true
    storage: true
    subresources:
      status: {}
EOF
  1. Check the CRD conditions are healthy
kubectl get crd issuers.cert.gardener.cloud -o json | jq .status.conditions
[
  {
    "lastTransitionTime": "2023-10-31T11:02:59Z",
    "message": "no conflicts found",
    "reason": "NoConflicts",
    "status": "True",
    "type": "NamesAccepted"
  },
  {
    "lastTransitionTime": "2023-10-31T11:02:59Z",
    "message": "the initial names have been accepted",
    "reason": "InitialNamesAccepted",
    "status": "True",
    "type": "Established"
  }
]
  1. Update the CRD with short names
cat <<EOF | kubectl replace -f -
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: issuers.cert.gardener.cloud
spec:
  conversion:
    strategy: None
  group: cert.gardener.cloud
  names:
    kind: Issuer
    listKind: IssuerList
    plural: issuers
    singular: issuer
    shortNames:
    - issuer
  scope: Namespaced
  versions:
  - name: v1alpha1
    schema:
      openAPIV3Schema:
        type: object
        x-kubernetes-preserve-unknown-fields: true
    served: true
    storage: true
    subresources:
      status: {}
EOF
  1. Ensure the CRD status has a failing condition NamesAccepted
kubectl get crd issuers.cert.gardener.cloud -o json | jq .status.conditions
[
  {
    "lastTransitionTime": "2023-10-31T11:01:50Z",
    "message": "\"issuer\" is already in use",
    "reason": "ShortNamesConflict",
    "status": "False",
    "type": "NamesAccepted"
  },
  {
    "lastTransitionTime": "2023-10-31T11:01:03Z",
    "message": "the initial names have been accepted",
    "reason": "InitialNamesAccepted",
    "status": "True",
    "type": "Established"
  }
]

Anything else we need to know?:

Environment:

  • Gardener version (if relevant):
  • Extension version:
  • Kubernetes version (use kubectl version):
  • Cloud provider or hardware configuration:
  • Others:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    kind/bugBugstatus/closedIssue is closed (either delivered or triaged)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions