Provide additional shortnames for resources (#10030)

This change expands on existing shortnames while adding others for various policy resources. This improves the user experience when issuing commands via kubectl.

Fixes #9322

Signed-off-by: Paul Balogh <javaducky@gmail.com>
This commit is contained in:
Paul Balogh 2023-01-17 09:27:39 -06:00 committed by GitHub
parent 439a130cd4
commit cf712d7b45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 41 additions and 27 deletions

View File

@ -15,7 +15,7 @@ spec:
kind: AuthorizationPolicy kind: AuthorizationPolicy
plural: authorizationpolicies plural: authorizationpolicies
singular: authorizationpolicy singular: authorizationpolicy
shortNames: [] shortNames: [authzpolicy]
versions: versions:
- name: v1alpha1 - name: v1alpha1
served: true served: true

View File

@ -15,7 +15,7 @@ spec:
kind: MeshTLSAuthentication kind: MeshTLSAuthentication
plural: meshtlsauthentications plural: meshtlsauthentications
singular: meshtlsauthentication singular: meshtlsauthentication
shortNames: [] shortNames: [meshtlsauthn]
versions: versions:
- name: v1alpha1 - name: v1alpha1
served: true served: true

View File

@ -15,7 +15,7 @@ spec:
kind: NetworkAuthentication kind: NetworkAuthentication
plural: networkauthentications plural: networkauthentications
singular: networkauthentication singular: networkauthentication
shortNames: [] shortNames: [netauthn, networkauthn]
versions: versions:
- name: v1alpha1 - name: v1alpha1
served: true served: true

View File

@ -15,7 +15,7 @@ spec:
kind: ServerAuthorization kind: ServerAuthorization
plural: serverauthorizations plural: serverauthorizations
singular: serverauthorization singular: serverauthorization
shortNames: [saz] shortNames: [saz, serverauthz, srvauthz]
versions: versions:
- name: v1alpha1 - name: v1alpha1
served: true served: true

View File

@ -15,7 +15,7 @@ spec:
kind: AuthorizationPolicy kind: AuthorizationPolicy
plural: authorizationpolicies plural: authorizationpolicies
singular: authorizationpolicy singular: authorizationpolicy
shortNames: [] shortNames: [authzpolicy]
versions: versions:
- name: v1alpha1 - name: v1alpha1
served: true served: true
@ -1649,7 +1649,7 @@ spec:
kind: MeshTLSAuthentication kind: MeshTLSAuthentication
plural: meshtlsauthentications plural: meshtlsauthentications
singular: meshtlsauthentication singular: meshtlsauthentication
shortNames: [] shortNames: [meshtlsauthn]
versions: versions:
- name: v1alpha1 - name: v1alpha1
served: true served: true
@ -1735,7 +1735,7 @@ spec:
kind: NetworkAuthentication kind: NetworkAuthentication
plural: networkauthentications plural: networkauthentications
singular: networkauthentication singular: networkauthentication
shortNames: [] shortNames: [netauthn, networkauthn]
versions: versions:
- name: v1alpha1 - name: v1alpha1
served: true served: true
@ -1788,7 +1788,7 @@ spec:
kind: ServerAuthorization kind: ServerAuthorization
plural: serverauthorizations plural: serverauthorizations
singular: serverauthorization singular: serverauthorization
shortNames: [saz] shortNames: [saz, serverauthz, srvauthz]
versions: versions:
- name: v1alpha1 - name: v1alpha1
served: true served: true

View File

@ -17,7 +17,7 @@ spec:
kind: AuthorizationPolicy kind: AuthorizationPolicy
plural: authorizationpolicies plural: authorizationpolicies
singular: authorizationpolicy singular: authorizationpolicy
shortNames: [] shortNames: [authzpolicy]
versions: versions:
- name: v1alpha1 - name: v1alpha1
served: true served: true
@ -1655,7 +1655,7 @@ spec:
kind: MeshTLSAuthentication kind: MeshTLSAuthentication
plural: meshtlsauthentications plural: meshtlsauthentications
singular: meshtlsauthentication singular: meshtlsauthentication
shortNames: [] shortNames: [meshtlsauthn]
versions: versions:
- name: v1alpha1 - name: v1alpha1
served: true served: true
@ -1743,7 +1743,7 @@ spec:
kind: NetworkAuthentication kind: NetworkAuthentication
plural: networkauthentications plural: networkauthentications
singular: networkauthentication singular: networkauthentication
shortNames: [] shortNames: [netauthn, networkauthn]
versions: versions:
- name: v1alpha1 - name: v1alpha1
served: true served: true
@ -1798,7 +1798,7 @@ spec:
kind: ServerAuthorization kind: ServerAuthorization
plural: serverauthorizations plural: serverauthorizations
singular: serverauthorization singular: serverauthorization
shortNames: [saz] shortNames: [saz, serverauthz, srvauthz]
versions: versions:
- name: v1alpha1 - name: v1alpha1
served: true served: true

View File

@ -17,7 +17,7 @@ spec:
kind: AuthorizationPolicy kind: AuthorizationPolicy
plural: authorizationpolicies plural: authorizationpolicies
singular: authorizationpolicy singular: authorizationpolicy
shortNames: [] shortNames: [authzpolicy]
versions: versions:
- name: v1alpha1 - name: v1alpha1
served: true served: true
@ -1655,7 +1655,7 @@ spec:
kind: MeshTLSAuthentication kind: MeshTLSAuthentication
plural: meshtlsauthentications plural: meshtlsauthentications
singular: meshtlsauthentication singular: meshtlsauthentication
shortNames: [] shortNames: [meshtlsauthn]
versions: versions:
- name: v1alpha1 - name: v1alpha1
served: true served: true
@ -1743,7 +1743,7 @@ spec:
kind: NetworkAuthentication kind: NetworkAuthentication
plural: networkauthentications plural: networkauthentications
singular: networkauthentication singular: networkauthentication
shortNames: [] shortNames: [netauthn, networkauthn]
versions: versions:
- name: v1alpha1 - name: v1alpha1
served: true served: true
@ -1798,7 +1798,7 @@ spec:
kind: ServerAuthorization kind: ServerAuthorization
plural: serverauthorizations plural: serverauthorizations
singular: serverauthorization singular: serverauthorization
shortNames: [saz] shortNames: [saz, serverauthz, srvauthz]
versions: versions:
- name: v1alpha1 - name: v1alpha1
served: true served: true

View File

@ -20,8 +20,10 @@ const (
Endpoints = "endpoints" Endpoints = "endpoints"
EndpointSlices = "endpointslices" EndpointSlices = "endpointslices"
Job = "job" Job = "job"
MeshTLSAuthentication = "meshtlsauthentication"
MutatingWebhookConfig = "mutatingwebhookconfig" MutatingWebhookConfig = "mutatingwebhookconfig"
Namespace = "namespace" Namespace = "namespace"
NetworkAuthentication = "networkauthentication"
Pod = "pod" Pod = "pod"
ReplicationController = "replicationcontroller" ReplicationController = "replicationcontroller"
ReplicaSet = "replicaset" ReplicaSet = "replicaset"
@ -117,16 +119,21 @@ var resourceNames = []resourceName{
{"ds", "daemonset", "daemonsets"}, {"ds", "daemonset", "daemonsets"},
{"deploy", "deployment", "deployments"}, {"deploy", "deployment", "deployments"},
{"job", "job", "jobs"}, {"job", "job", "jobs"},
{"meshtlsauthn", "meshtlsauthentication", "meshtlsauthentications"},
{"ns", "namespace", "namespaces"}, {"ns", "namespace", "namespaces"},
{"netauthn", "networkauthentication", "networkauthentications"},
{"networkauthn", "networkauthentication", "networkauthentications"},
{"po", "pod", "pods"}, {"po", "pod", "pods"},
{"rc", "replicationcontroller", "replicationcontrollers"}, {"rc", "replicationcontroller", "replicationcontrollers"},
{"rs", "replicaset", "replicasets"}, {"rs", "replicaset", "replicasets"},
{"svc", "service", "services"}, {"svc", "service", "services"},
{"sp", "serviceprofile", "serviceprofiles"}, {"sp", "serviceprofile", "serviceprofiles"},
{"saz", "serverauthorization", "serverauthorizations"}, {"saz", "serverauthorization", "serverauthorizations"},
{"serverauthz", "serverauthorization", "serverauthorizations"},
{"srvauthz", "serverauthorization", "serverauthorizations"},
{"srv", "server", "servers"}, {"srv", "server", "servers"},
{"ap", "authorizationpolicy", "authorizationpolicies"}, {"ap", "authorizationpolicy", "authorizationpolicies"},
{"route", "httproute", "httproutes"}, {"authzpolicy", "authorizationpolicy", "authorizationpolicies"},
{"sts", "statefulset", "statefulsets"}, {"sts", "statefulset", "statefulsets"},
{"ln", "link", "links"}, {"ln", "link", "links"},
{"all", "all", "all"}, {"all", "all", "all"},
@ -206,8 +213,9 @@ func ShortNameFromCanonicalResourceName(canonicalName string) string {
// KindToL5DLabel converts a Kubernetes `kind` to a Linkerd label. // KindToL5DLabel converts a Kubernetes `kind` to a Linkerd label.
// For example: // For example:
// `pod` -> `pod` //
// `job` -> `k8s_job` // `pod` -> `pod`
// `job` -> `k8s_job`
func KindToL5DLabel(k8sKind string) string { func KindToL5DLabel(k8sKind string) string {
if k8sKind == Job { if k8sKind == Job {
return l5dJob return l5dJob

View File

@ -28,14 +28,20 @@ func TestGetConfig(t *testing.T) {
func TestCanonicalResourceNameFromFriendlyName(t *testing.T) { func TestCanonicalResourceNameFromFriendlyName(t *testing.T) {
t.Run("Returns canonical name for all known variants", func(t *testing.T) { t.Run("Returns canonical name for all known variants", func(t *testing.T) {
expectations := map[string]string{ expectations := map[string]string{
"po": Pod, "po": Pod,
"pod": Pod, "pod": Pod,
"deployment": Deployment, "deployment": Deployment,
"deployments": Deployment, "deployments": Deployment,
"au": Authority, "au": Authority,
"authorities": Authority, "authorities": Authority,
"cj": CronJob, "cj": CronJob,
"cronjob": CronJob, "cronjob": CronJob,
"serverauthz": ServerAuthorization,
"srvauthz": ServerAuthorization,
"authzpolicy": AuthorizationPolicy,
"meshtlsauthn": MeshTLSAuthentication,
"networkauthn": NetworkAuthentication,
"netauthn": NetworkAuthentication,
} }
for input, expectedName := range expectations { for input, expectedName := range expectations {