Put all of our APIs into a "pinniped" category, and never use "all".

We want to have our APIs respond to `kubectl get pinniped`, and we shouldn't use `all` because we don't think most average users should have permission to see our API types, which means if we put our types there, they would get an error from `kubectl get all`.

I also added some tests to assert these properties on all `*.pinniped.dev` API resources.

Signed-off-by: Matt Moyer <moyerm@vmware.com>
This commit is contained in:
Matt Moyer 2020-11-12 16:24:25 -06:00
parent d73fdb1d33
commit 7f2c43cd62
No known key found for this signature in database
GPG Key ID: EAE88AD172C5AE2D
28 changed files with 82 additions and 33 deletions

View File

@ -30,7 +30,7 @@ type WebhookAuthenticatorSpec struct {
// WebhookAuthenticator describes the configuration of a webhook authenticator. // WebhookAuthenticator describes the configuration of a webhook authenticator.
// +genclient // +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:categories=all;authenticator;authenticators // +kubebuilder:resource:categories=pinniped;pinniped-authenticator;pinniped-authenticators
// +kubebuilder:printcolumn:name="Endpoint",type=string,JSONPath=`.spec.endpoint` // +kubebuilder:printcolumn:name="Endpoint",type=string,JSONPath=`.spec.endpoint`
type WebhookAuthenticator struct { type WebhookAuthenticator struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`

View File

@ -68,7 +68,7 @@ type CredentialIssuerStrategy struct {
// Describes the configuration status of a Pinniped credential issuer. // Describes the configuration status of a Pinniped credential issuer.
// +genclient // +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:categories=pinniped
type CredentialIssuer struct { type CredentialIssuer struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"` metav1.ObjectMeta `json:"metadata,omitempty"`
@ -79,7 +79,6 @@ type CredentialIssuer struct {
// List of CredentialIssuer objects. // List of CredentialIssuer objects.
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type CredentialIssuerList struct { type CredentialIssuerList struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"` metav1.ListMeta `json:"metadata,omitempty"`

View File

@ -86,6 +86,7 @@ type OIDCProviderStatus struct {
// OIDCProvider describes the configuration of an OIDC provider. // OIDCProvider describes the configuration of an OIDC provider.
// +genclient // +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:categories=pinniped
type OIDCProvider struct { type OIDCProvider struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"` metav1.ObjectMeta `json:"metadata,omitempty"`

View File

@ -11,9 +11,9 @@ spec:
group: authentication.concierge.pinniped.dev group: authentication.concierge.pinniped.dev
names: names:
categories: categories:
- all - pinniped
- authenticator - pinniped-authenticator
- authenticators - pinniped-authenticators
kind: WebhookAuthenticator kind: WebhookAuthenticator
listKind: WebhookAuthenticatorList listKind: WebhookAuthenticatorList
plural: webhookauthenticators plural: webhookauthenticators

View File

@ -10,6 +10,8 @@ metadata:
spec: spec:
group: config.concierge.pinniped.dev group: config.concierge.pinniped.dev
names: names:
categories:
- pinniped
kind: CredentialIssuer kind: CredentialIssuer
listKind: CredentialIssuerList listKind: CredentialIssuerList
plural: credentialissuers plural: credentialissuers
@ -19,6 +21,7 @@ spec:
- name: v1alpha1 - name: v1alpha1
schema: schema:
openAPIV3Schema: openAPIV3Schema:
description: Describes the configuration status of a Pinniped credential issuer.
properties: properties:
apiVersion: apiVersion:
description: 'APIVersion defines the versioned schema of this representation description: 'APIVersion defines the versioned schema of this representation

View File

@ -10,6 +10,8 @@ metadata:
spec: spec:
group: config.supervisor.pinniped.dev group: config.supervisor.pinniped.dev
names: names:
categories:
- pinniped
kind: OIDCProvider kind: OIDCProvider
listKind: OIDCProviderList listKind: OIDCProviderList
plural: oidcproviders plural: oidcproviders

View File

@ -125,7 +125,7 @@ Package v1alpha1 is the v1alpha1 version of the Pinniped concierge configuration
[id="{anchor_prefix}-go-pinniped-dev-generated-1-17-apis-concierge-config-v1alpha1-credentialissuer"] [id="{anchor_prefix}-go-pinniped-dev-generated-1-17-apis-concierge-config-v1alpha1-credentialissuer"]
==== CredentialIssuer ==== CredentialIssuer
Describes the configuration status of a Pinniped credential issuer.
.Appears In: .Appears In:
**** ****

View File

@ -30,7 +30,7 @@ type WebhookAuthenticatorSpec struct {
// WebhookAuthenticator describes the configuration of a webhook authenticator. // WebhookAuthenticator describes the configuration of a webhook authenticator.
// +genclient // +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:categories=all;authenticator;authenticators // +kubebuilder:resource:categories=pinniped;pinniped-authenticator;pinniped-authenticators
// +kubebuilder:printcolumn:name="Endpoint",type=string,JSONPath=`.spec.endpoint` // +kubebuilder:printcolumn:name="Endpoint",type=string,JSONPath=`.spec.endpoint`
type WebhookAuthenticator struct { type WebhookAuthenticator struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`

View File

@ -68,7 +68,7 @@ type CredentialIssuerStrategy struct {
// Describes the configuration status of a Pinniped credential issuer. // Describes the configuration status of a Pinniped credential issuer.
// +genclient // +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:categories=pinniped
type CredentialIssuer struct { type CredentialIssuer struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"` metav1.ObjectMeta `json:"metadata,omitempty"`
@ -79,7 +79,6 @@ type CredentialIssuer struct {
// List of CredentialIssuer objects. // List of CredentialIssuer objects.
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type CredentialIssuerList struct { type CredentialIssuerList struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"` metav1.ListMeta `json:"metadata,omitempty"`

View File

@ -86,6 +86,7 @@ type OIDCProviderStatus struct {
// OIDCProvider describes the configuration of an OIDC provider. // OIDCProvider describes the configuration of an OIDC provider.
// +genclient // +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:categories=pinniped
type OIDCProvider struct { type OIDCProvider struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"` metav1.ObjectMeta `json:"metadata,omitempty"`

View File

@ -11,9 +11,9 @@ spec:
group: authentication.concierge.pinniped.dev group: authentication.concierge.pinniped.dev
names: names:
categories: categories:
- all - pinniped
- authenticator - pinniped-authenticator
- authenticators - pinniped-authenticators
kind: WebhookAuthenticator kind: WebhookAuthenticator
listKind: WebhookAuthenticatorList listKind: WebhookAuthenticatorList
plural: webhookauthenticators plural: webhookauthenticators

View File

@ -10,6 +10,8 @@ metadata:
spec: spec:
group: config.concierge.pinniped.dev group: config.concierge.pinniped.dev
names: names:
categories:
- pinniped
kind: CredentialIssuer kind: CredentialIssuer
listKind: CredentialIssuerList listKind: CredentialIssuerList
plural: credentialissuers plural: credentialissuers
@ -19,6 +21,7 @@ spec:
- name: v1alpha1 - name: v1alpha1
schema: schema:
openAPIV3Schema: openAPIV3Schema:
description: Describes the configuration status of a Pinniped credential issuer.
properties: properties:
apiVersion: apiVersion:
description: 'APIVersion defines the versioned schema of this representation description: 'APIVersion defines the versioned schema of this representation

View File

@ -10,6 +10,8 @@ metadata:
spec: spec:
group: config.supervisor.pinniped.dev group: config.supervisor.pinniped.dev
names: names:
categories:
- pinniped
kind: OIDCProvider kind: OIDCProvider
listKind: OIDCProviderList listKind: OIDCProviderList
plural: oidcproviders plural: oidcproviders

View File

@ -125,7 +125,7 @@ Package v1alpha1 is the v1alpha1 version of the Pinniped concierge configuration
[id="{anchor_prefix}-go-pinniped-dev-generated-1-18-apis-concierge-config-v1alpha1-credentialissuer"] [id="{anchor_prefix}-go-pinniped-dev-generated-1-18-apis-concierge-config-v1alpha1-credentialissuer"]
==== CredentialIssuer ==== CredentialIssuer
Describes the configuration status of a Pinniped credential issuer.
.Appears In: .Appears In:
**** ****

View File

@ -30,7 +30,7 @@ type WebhookAuthenticatorSpec struct {
// WebhookAuthenticator describes the configuration of a webhook authenticator. // WebhookAuthenticator describes the configuration of a webhook authenticator.
// +genclient // +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:categories=all;authenticator;authenticators // +kubebuilder:resource:categories=pinniped;pinniped-authenticator;pinniped-authenticators
// +kubebuilder:printcolumn:name="Endpoint",type=string,JSONPath=`.spec.endpoint` // +kubebuilder:printcolumn:name="Endpoint",type=string,JSONPath=`.spec.endpoint`
type WebhookAuthenticator struct { type WebhookAuthenticator struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`

View File

@ -68,7 +68,7 @@ type CredentialIssuerStrategy struct {
// Describes the configuration status of a Pinniped credential issuer. // Describes the configuration status of a Pinniped credential issuer.
// +genclient // +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:categories=pinniped
type CredentialIssuer struct { type CredentialIssuer struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"` metav1.ObjectMeta `json:"metadata,omitempty"`
@ -79,7 +79,6 @@ type CredentialIssuer struct {
// List of CredentialIssuer objects. // List of CredentialIssuer objects.
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type CredentialIssuerList struct { type CredentialIssuerList struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"` metav1.ListMeta `json:"metadata,omitempty"`

View File

@ -86,6 +86,7 @@ type OIDCProviderStatus struct {
// OIDCProvider describes the configuration of an OIDC provider. // OIDCProvider describes the configuration of an OIDC provider.
// +genclient // +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:categories=pinniped
type OIDCProvider struct { type OIDCProvider struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"` metav1.ObjectMeta `json:"metadata,omitempty"`

View File

@ -11,9 +11,9 @@ spec:
group: authentication.concierge.pinniped.dev group: authentication.concierge.pinniped.dev
names: names:
categories: categories:
- all - pinniped
- authenticator - pinniped-authenticator
- authenticators - pinniped-authenticators
kind: WebhookAuthenticator kind: WebhookAuthenticator
listKind: WebhookAuthenticatorList listKind: WebhookAuthenticatorList
plural: webhookauthenticators plural: webhookauthenticators

View File

@ -10,6 +10,8 @@ metadata:
spec: spec:
group: config.concierge.pinniped.dev group: config.concierge.pinniped.dev
names: names:
categories:
- pinniped
kind: CredentialIssuer kind: CredentialIssuer
listKind: CredentialIssuerList listKind: CredentialIssuerList
plural: credentialissuers plural: credentialissuers
@ -19,6 +21,7 @@ spec:
- name: v1alpha1 - name: v1alpha1
schema: schema:
openAPIV3Schema: openAPIV3Schema:
description: Describes the configuration status of a Pinniped credential issuer.
properties: properties:
apiVersion: apiVersion:
description: 'APIVersion defines the versioned schema of this representation description: 'APIVersion defines the versioned schema of this representation

View File

@ -10,6 +10,8 @@ metadata:
spec: spec:
group: config.supervisor.pinniped.dev group: config.supervisor.pinniped.dev
names: names:
categories:
- pinniped
kind: OIDCProvider kind: OIDCProvider
listKind: OIDCProviderList listKind: OIDCProviderList
plural: oidcproviders plural: oidcproviders

View File

@ -125,7 +125,7 @@ Package v1alpha1 is the v1alpha1 version of the Pinniped concierge configuration
[id="{anchor_prefix}-go-pinniped-dev-generated-1-19-apis-concierge-config-v1alpha1-credentialissuer"] [id="{anchor_prefix}-go-pinniped-dev-generated-1-19-apis-concierge-config-v1alpha1-credentialissuer"]
==== CredentialIssuer ==== CredentialIssuer
Describes the configuration status of a Pinniped credential issuer.
.Appears In: .Appears In:
**** ****

View File

@ -30,7 +30,7 @@ type WebhookAuthenticatorSpec struct {
// WebhookAuthenticator describes the configuration of a webhook authenticator. // WebhookAuthenticator describes the configuration of a webhook authenticator.
// +genclient // +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:categories=all;authenticator;authenticators // +kubebuilder:resource:categories=pinniped;pinniped-authenticator;pinniped-authenticators
// +kubebuilder:printcolumn:name="Endpoint",type=string,JSONPath=`.spec.endpoint` // +kubebuilder:printcolumn:name="Endpoint",type=string,JSONPath=`.spec.endpoint`
type WebhookAuthenticator struct { type WebhookAuthenticator struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`

View File

@ -68,7 +68,7 @@ type CredentialIssuerStrategy struct {
// Describes the configuration status of a Pinniped credential issuer. // Describes the configuration status of a Pinniped credential issuer.
// +genclient // +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:categories=pinniped
type CredentialIssuer struct { type CredentialIssuer struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"` metav1.ObjectMeta `json:"metadata,omitempty"`
@ -79,7 +79,6 @@ type CredentialIssuer struct {
// List of CredentialIssuer objects. // List of CredentialIssuer objects.
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type CredentialIssuerList struct { type CredentialIssuerList struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"` metav1.ListMeta `json:"metadata,omitempty"`

View File

@ -86,6 +86,7 @@ type OIDCProviderStatus struct {
// OIDCProvider describes the configuration of an OIDC provider. // OIDCProvider describes the configuration of an OIDC provider.
// +genclient // +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:categories=pinniped
type OIDCProvider struct { type OIDCProvider struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"` metav1.ObjectMeta `json:"metadata,omitempty"`

View File

@ -11,9 +11,9 @@ spec:
group: authentication.concierge.pinniped.dev group: authentication.concierge.pinniped.dev
names: names:
categories: categories:
- all - pinniped
- authenticator - pinniped-authenticator
- authenticators - pinniped-authenticators
kind: WebhookAuthenticator kind: WebhookAuthenticator
listKind: WebhookAuthenticatorList listKind: WebhookAuthenticatorList
plural: webhookauthenticators plural: webhookauthenticators

View File

@ -10,6 +10,8 @@ metadata:
spec: spec:
group: config.concierge.pinniped.dev group: config.concierge.pinniped.dev
names: names:
categories:
- pinniped
kind: CredentialIssuer kind: CredentialIssuer
listKind: CredentialIssuerList listKind: CredentialIssuerList
plural: credentialissuers plural: credentialissuers
@ -19,6 +21,7 @@ spec:
- name: v1alpha1 - name: v1alpha1
schema: schema:
openAPIV3Schema: openAPIV3Schema:
description: Describes the configuration status of a Pinniped credential issuer.
properties: properties:
apiVersion: apiVersion:
description: 'APIVersion defines the versioned schema of this representation description: 'APIVersion defines the versioned schema of this representation

View File

@ -10,6 +10,8 @@ metadata:
spec: spec:
group: config.supervisor.pinniped.dev group: config.supervisor.pinniped.dev
names: names:
categories:
- pinniped
kind: OIDCProvider kind: OIDCProvider
listKind: OIDCProviderList listKind: OIDCProviderList
plural: oidcproviders plural: oidcproviders

View File

@ -4,8 +4,10 @@
package integration package integration
import ( import (
"strings"
"testing" "testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -45,11 +47,6 @@ func TestGetAPIResourceList(t *testing.T) {
Kind: "TokenCredentialRequest", Kind: "TokenCredentialRequest",
Verbs: []string{"create"}, Verbs: []string{"create"},
Namespaced: true, Namespaced: true,
// This is currently an empty string in the response; maybe it should not be
// empty? Seems like no harm in keeping it like this for now, but feel free
// to update in the future if there is a compelling reason to do so.
SingularName: "",
}, },
}, },
}, },
@ -76,6 +73,7 @@ func TestGetAPIResourceList(t *testing.T) {
Namespaced: true, Namespaced: true,
Kind: "OIDCProvider", Kind: "OIDCProvider",
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"}, Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
Categories: []string{"pinniped"},
}, },
}, },
}, },
@ -102,6 +100,7 @@ func TestGetAPIResourceList(t *testing.T) {
Namespaced: true, Namespaced: true,
Kind: "CredentialIssuer", Kind: "CredentialIssuer",
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"}, Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
Categories: []string{"pinniped"},
}, },
}, },
}, },
@ -128,16 +127,46 @@ func TestGetAPIResourceList(t *testing.T) {
Namespaced: true, Namespaced: true,
Kind: "WebhookAuthenticator", Kind: "WebhookAuthenticator",
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"}, Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
Categories: []string{"all", "authenticator", "authenticators"}, Categories: []string{"pinniped", "pinniped-authenticator", "pinniped-authenticators"},
}, },
}, },
}, },
}, },
} }
t.Run("every Pinniped API has explicit test coverage", func(t *testing.T) {
t.Parallel()
testedGroups := map[string]bool{}
for _, tt := range tests {
testedGroups[tt.group.Name] = true
}
for _, g := range groups {
if !strings.Contains(g.Name, "pinniped.dev") {
continue
}
assert.Truef(t, testedGroups[g.Name], "expected group %q to have assertions defined", g.Name)
}
})
t.Run("every API categorized appropriately", func(t *testing.T) {
t.Parallel()
for _, r := range resources {
if !strings.Contains(r.GroupVersion, "pinniped.dev") {
continue
}
for _, a := range r.APIResources {
if a.Kind != "TokenCredentialRequest" {
assert.Containsf(t, a.Categories, "pinniped", "expected resource %q to be in the 'pinniped' category", a.Name)
}
assert.NotContainsf(t, a.Categories, "all", "expected resource %q not to be in the 'all' category", a.Name)
}
}
})
for _, tt := range tests { for _, tt := range tests {
tt := tt tt := tt
t.Run(tt.group.Name, func(t *testing.T) { t.Run(tt.group.Name, func(t *testing.T) {
t.Parallel()
require.Contains(t, groups, &tt.group) require.Contains(t, groups, &tt.group)
for groupVersion, expectedResources := range tt.resourceByVersion { for groupVersion, expectedResources := range tt.resourceByVersion {