kubectl: kubectl returns kind: ValidatingAdmissionPolicyList for empty list of policies

What happened?

There is a cosmetic inconsistency of kubectl get validatingadmissionpolicies -o yaml output for empty and non-empty list of validating admission policies.

If there are no policies:

apiVersion: v1
items:
- apiVersion: admissionregistration.k8s.io/v1
  kind: ValidatingAdmissionPolicyList
  metadata:
    resourceVersion: "3817"
kind: List
metadata:
  resourceVersion: ""

If there is at least one policy:

apiVersion: v1
items:
- apiVersion: admissionregistration.k8s.io/v1
  kind: ValidatingAdmissionPolicy
  ...
kind: List
metadata:
  resourceVersion: ""

What did you expect to happen?

If there are no validating admission policies, kubectl get validatingadmissionpolicies -o yaml is expected to output:

apiVersion: v1
items: []
kind: List
metadata:
  resourceVersion: ""

How can we reproduce it (as minimally and precisely as possible)?

Run kubectl get validatingadmissionpolicies -o yaml provided that there are no validating admission policies in the cluster.

Anything else we need to know?

No response

Kubernetes version

$ kubectl version
Client Version: v1.30.0
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.30.0

Cloud provider

bare-metal

OS version

# On Linux:
$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
$ uname -a
Linux k8s-control-plane-1 5.15.0-50-generic kubernetes/kubernetes#56-Ubuntu SMP Tue Sep 20 13:23:26 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Install tools

kubeadm

Container runtime (CRI) and version (if applicable)

containerd=1.6.12-0ubuntu1~22.04.3

Related plugins (CNI, CSI, …) and versions (if applicable)

Calico v3.27.0

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (8 by maintainers)

Most upvoted comments

We noticed an issue when running in kubectl describe,

Note:

  • There is no ValidatingAdmissionPolicy resource in the cluster as well. The kubectl get -oyaml output is the same in this bug.
  • The cluster version is also 1.30.0
kubectl describe validatingadmissionpolicies.admissionregistration.k8s.io

Error message:

error: name is required

Do you know if this might be the same root cause?

Yes, this is the root cause.

Please assign this to me. I think this is a bug of apiserver kubectl get --raw /apis/admissionregistration.k8s.io/v1/validatingadmissionpolicies
{ "kind": "ValidatingAdmissionPolicyList", "apiVersion": "admissionregistration.k8s.io/v1", "metadata": { "resourceVersion": "30603" } } kubectl get --raw /api/v1/nodes | jq .

{ "kind": "NodeList", "apiVersion": "v1", "metadata": { "resourceVersion": "30721" }, "items": [] }