From cf712d7b45666361bfc7862e4c07c81300a60d69 Mon Sep 17 00:00:00 2001 From: Paul Balogh Date: Tue, 17 Jan 2023 09:27:39 -0600 Subject: [PATCH] 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 --- .../policy/authorization-policy.yaml | 2 +- .../policy/meshtls-authentication.yaml | 2 +- .../policy/network-authentication.yaml | 2 +- .../policy/server-authorization.yaml | 2 +- cli/cmd/testdata/install_crds.golden | 8 +++---- .../testdata/install_helm_crds_output.golden | 8 +++---- .../install_helm_crds_output_ha.golden | 8 +++---- pkg/k8s/k8s.go | 14 +++++++++--- pkg/k8s/k8s_test.go | 22 ++++++++++++------- 9 files changed, 41 insertions(+), 27 deletions(-) diff --git a/charts/linkerd-crds/templates/policy/authorization-policy.yaml b/charts/linkerd-crds/templates/policy/authorization-policy.yaml index d4fa84f94..7d86520e2 100644 --- a/charts/linkerd-crds/templates/policy/authorization-policy.yaml +++ b/charts/linkerd-crds/templates/policy/authorization-policy.yaml @@ -15,7 +15,7 @@ spec: kind: AuthorizationPolicy plural: authorizationpolicies singular: authorizationpolicy - shortNames: [] + shortNames: [authzpolicy] versions: - name: v1alpha1 served: true diff --git a/charts/linkerd-crds/templates/policy/meshtls-authentication.yaml b/charts/linkerd-crds/templates/policy/meshtls-authentication.yaml index c4b3895e7..c2798f07e 100644 --- a/charts/linkerd-crds/templates/policy/meshtls-authentication.yaml +++ b/charts/linkerd-crds/templates/policy/meshtls-authentication.yaml @@ -15,7 +15,7 @@ spec: kind: MeshTLSAuthentication plural: meshtlsauthentications singular: meshtlsauthentication - shortNames: [] + shortNames: [meshtlsauthn] versions: - name: v1alpha1 served: true diff --git a/charts/linkerd-crds/templates/policy/network-authentication.yaml b/charts/linkerd-crds/templates/policy/network-authentication.yaml index 71e7f4f48..cef15d3c4 100644 --- a/charts/linkerd-crds/templates/policy/network-authentication.yaml +++ b/charts/linkerd-crds/templates/policy/network-authentication.yaml @@ -15,7 +15,7 @@ spec: kind: NetworkAuthentication plural: networkauthentications singular: networkauthentication - shortNames: [] + shortNames: [netauthn, networkauthn] versions: - name: v1alpha1 served: true diff --git a/charts/linkerd-crds/templates/policy/server-authorization.yaml b/charts/linkerd-crds/templates/policy/server-authorization.yaml index 87052a29f..33fb65900 100644 --- a/charts/linkerd-crds/templates/policy/server-authorization.yaml +++ b/charts/linkerd-crds/templates/policy/server-authorization.yaml @@ -15,7 +15,7 @@ spec: kind: ServerAuthorization plural: serverauthorizations singular: serverauthorization - shortNames: [saz] + shortNames: [saz, serverauthz, srvauthz] versions: - name: v1alpha1 served: true diff --git a/cli/cmd/testdata/install_crds.golden b/cli/cmd/testdata/install_crds.golden index 3d9c1a5db..041bff225 100644 --- a/cli/cmd/testdata/install_crds.golden +++ b/cli/cmd/testdata/install_crds.golden @@ -15,7 +15,7 @@ spec: kind: AuthorizationPolicy plural: authorizationpolicies singular: authorizationpolicy - shortNames: [] + shortNames: [authzpolicy] versions: - name: v1alpha1 served: true @@ -1649,7 +1649,7 @@ spec: kind: MeshTLSAuthentication plural: meshtlsauthentications singular: meshtlsauthentication - shortNames: [] + shortNames: [meshtlsauthn] versions: - name: v1alpha1 served: true @@ -1735,7 +1735,7 @@ spec: kind: NetworkAuthentication plural: networkauthentications singular: networkauthentication - shortNames: [] + shortNames: [netauthn, networkauthn] versions: - name: v1alpha1 served: true @@ -1788,7 +1788,7 @@ spec: kind: ServerAuthorization plural: serverauthorizations singular: serverauthorization - shortNames: [saz] + shortNames: [saz, serverauthz, srvauthz] versions: - name: v1alpha1 served: true diff --git a/cli/cmd/testdata/install_helm_crds_output.golden b/cli/cmd/testdata/install_helm_crds_output.golden index d32659a6c..b1da7ccbd 100644 --- a/cli/cmd/testdata/install_helm_crds_output.golden +++ b/cli/cmd/testdata/install_helm_crds_output.golden @@ -17,7 +17,7 @@ spec: kind: AuthorizationPolicy plural: authorizationpolicies singular: authorizationpolicy - shortNames: [] + shortNames: [authzpolicy] versions: - name: v1alpha1 served: true @@ -1655,7 +1655,7 @@ spec: kind: MeshTLSAuthentication plural: meshtlsauthentications singular: meshtlsauthentication - shortNames: [] + shortNames: [meshtlsauthn] versions: - name: v1alpha1 served: true @@ -1743,7 +1743,7 @@ spec: kind: NetworkAuthentication plural: networkauthentications singular: networkauthentication - shortNames: [] + shortNames: [netauthn, networkauthn] versions: - name: v1alpha1 served: true @@ -1798,7 +1798,7 @@ spec: kind: ServerAuthorization plural: serverauthorizations singular: serverauthorization - shortNames: [saz] + shortNames: [saz, serverauthz, srvauthz] versions: - name: v1alpha1 served: true diff --git a/cli/cmd/testdata/install_helm_crds_output_ha.golden b/cli/cmd/testdata/install_helm_crds_output_ha.golden index d32659a6c..b1da7ccbd 100644 --- a/cli/cmd/testdata/install_helm_crds_output_ha.golden +++ b/cli/cmd/testdata/install_helm_crds_output_ha.golden @@ -17,7 +17,7 @@ spec: kind: AuthorizationPolicy plural: authorizationpolicies singular: authorizationpolicy - shortNames: [] + shortNames: [authzpolicy] versions: - name: v1alpha1 served: true @@ -1655,7 +1655,7 @@ spec: kind: MeshTLSAuthentication plural: meshtlsauthentications singular: meshtlsauthentication - shortNames: [] + shortNames: [meshtlsauthn] versions: - name: v1alpha1 served: true @@ -1743,7 +1743,7 @@ spec: kind: NetworkAuthentication plural: networkauthentications singular: networkauthentication - shortNames: [] + shortNames: [netauthn, networkauthn] versions: - name: v1alpha1 served: true @@ -1798,7 +1798,7 @@ spec: kind: ServerAuthorization plural: serverauthorizations singular: serverauthorization - shortNames: [saz] + shortNames: [saz, serverauthz, srvauthz] versions: - name: v1alpha1 served: true diff --git a/pkg/k8s/k8s.go b/pkg/k8s/k8s.go index cef4a080b..19931e3cd 100644 --- a/pkg/k8s/k8s.go +++ b/pkg/k8s/k8s.go @@ -20,8 +20,10 @@ const ( Endpoints = "endpoints" EndpointSlices = "endpointslices" Job = "job" + MeshTLSAuthentication = "meshtlsauthentication" MutatingWebhookConfig = "mutatingwebhookconfig" Namespace = "namespace" + NetworkAuthentication = "networkauthentication" Pod = "pod" ReplicationController = "replicationcontroller" ReplicaSet = "replicaset" @@ -117,16 +119,21 @@ var resourceNames = []resourceName{ {"ds", "daemonset", "daemonsets"}, {"deploy", "deployment", "deployments"}, {"job", "job", "jobs"}, + {"meshtlsauthn", "meshtlsauthentication", "meshtlsauthentications"}, {"ns", "namespace", "namespaces"}, + {"netauthn", "networkauthentication", "networkauthentications"}, + {"networkauthn", "networkauthentication", "networkauthentications"}, {"po", "pod", "pods"}, {"rc", "replicationcontroller", "replicationcontrollers"}, {"rs", "replicaset", "replicasets"}, {"svc", "service", "services"}, {"sp", "serviceprofile", "serviceprofiles"}, {"saz", "serverauthorization", "serverauthorizations"}, + {"serverauthz", "serverauthorization", "serverauthorizations"}, + {"srvauthz", "serverauthorization", "serverauthorizations"}, {"srv", "server", "servers"}, {"ap", "authorizationpolicy", "authorizationpolicies"}, - {"route", "httproute", "httproutes"}, + {"authzpolicy", "authorizationpolicy", "authorizationpolicies"}, {"sts", "statefulset", "statefulsets"}, {"ln", "link", "links"}, {"all", "all", "all"}, @@ -206,8 +213,9 @@ func ShortNameFromCanonicalResourceName(canonicalName string) string { // KindToL5DLabel converts a Kubernetes `kind` to a Linkerd label. // For example: -// `pod` -> `pod` -// `job` -> `k8s_job` +// +// `pod` -> `pod` +// `job` -> `k8s_job` func KindToL5DLabel(k8sKind string) string { if k8sKind == Job { return l5dJob diff --git a/pkg/k8s/k8s_test.go b/pkg/k8s/k8s_test.go index f14329993..a4a0eec9c 100644 --- a/pkg/k8s/k8s_test.go +++ b/pkg/k8s/k8s_test.go @@ -28,14 +28,20 @@ func TestGetConfig(t *testing.T) { func TestCanonicalResourceNameFromFriendlyName(t *testing.T) { t.Run("Returns canonical name for all known variants", func(t *testing.T) { expectations := map[string]string{ - "po": Pod, - "pod": Pod, - "deployment": Deployment, - "deployments": Deployment, - "au": Authority, - "authorities": Authority, - "cj": CronJob, - "cronjob": CronJob, + "po": Pod, + "pod": Pod, + "deployment": Deployment, + "deployments": Deployment, + "au": Authority, + "authorities": Authority, + "cj": CronJob, + "cronjob": CronJob, + "serverauthz": ServerAuthorization, + "srvauthz": ServerAuthorization, + "authzpolicy": AuthorizationPolicy, + "meshtlsauthn": MeshTLSAuthentication, + "networkauthn": NetworkAuthentication, + "netauthn": NetworkAuthentication, } for input, expectedName := range expectations {