2022-06-05 04:04:40 +00:00
|
|
|
// Copyright 2020-2022 the Pinniped contributors. All Rights Reserved.
|
2020-09-16 14:19:51 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2020-08-01 00:37:59 +00:00
|
|
|
|
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
2022-08-30 19:11:17 +00:00
|
|
|
"bytes"
|
2021-09-20 19:47:39 +00:00
|
|
|
"context"
|
2021-01-13 01:27:41 +00:00
|
|
|
"errors"
|
2021-01-19 18:50:22 +00:00
|
|
|
"fmt"
|
2022-08-30 19:11:17 +00:00
|
|
|
"os/exec"
|
|
|
|
"regexp"
|
2020-11-12 22:24:25 +00:00
|
|
|
"strings"
|
2020-08-01 00:37:59 +00:00
|
|
|
"testing"
|
2021-09-20 19:47:39 +00:00
|
|
|
"time"
|
2020-08-01 00:37:59 +00:00
|
|
|
|
2020-11-12 22:24:25 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-08-01 00:37:59 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-09-20 19:47:39 +00:00
|
|
|
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
2020-08-01 00:37:59 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2021-01-19 18:50:22 +00:00
|
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
2021-02-19 18:21:10 +00:00
|
|
|
"k8s.io/apimachinery/pkg/util/sets"
|
2021-01-13 01:27:41 +00:00
|
|
|
"k8s.io/client-go/discovery"
|
2020-08-01 00:37:59 +00:00
|
|
|
|
2021-06-22 15:23:19 +00:00
|
|
|
"go.pinniped.dev/test/testlib"
|
2020-08-01 00:37:59 +00:00
|
|
|
)
|
|
|
|
|
2022-08-30 19:11:17 +00:00
|
|
|
func TestGetAPIResourceList(t *testing.T) { //nolint:gocyclo // each t.Run is pretty simple, but there are many
|
2021-06-22 15:23:19 +00:00
|
|
|
env := testlib.IntegrationEnv(t)
|
2020-08-07 01:44:14 +00:00
|
|
|
|
2021-06-22 15:23:19 +00:00
|
|
|
client := testlib.NewKubernetesClientset(t)
|
2020-08-01 00:37:59 +00:00
|
|
|
groups, resources, err := client.Discovery().ServerGroupsAndResources()
|
2021-01-13 01:27:41 +00:00
|
|
|
|
|
|
|
// discovery can have partial failures when an API service is unavailable (i.e. because of TestAPIServingCertificateAutoCreationAndRotation)
|
|
|
|
// we ignore failures for groups that are not relevant to this test
|
|
|
|
if err != nil {
|
|
|
|
discoveryFailed := &discovery.ErrGroupDiscoveryFailed{}
|
|
|
|
isDiscoveryFailed := errors.As(err, &discoveryFailed)
|
|
|
|
require.True(t, isDiscoveryFailed, err)
|
|
|
|
for gv, gvErr := range discoveryFailed.Groups {
|
|
|
|
if strings.HasSuffix(gv.Group, "."+env.APIGroupSuffix) {
|
|
|
|
require.NoError(t, gvErr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-01 00:37:59 +00:00
|
|
|
|
2021-01-19 18:50:22 +00:00
|
|
|
makeGV := func(firstSegment, secondSegment string) schema.GroupVersion {
|
|
|
|
return schema.GroupVersion{
|
|
|
|
Group: fmt.Sprintf("%s.%s.%s", firstSegment, secondSegment, env.APIGroupSuffix),
|
|
|
|
Version: "v1alpha1",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
loginConciergeGV := makeGV("login", "concierge")
|
2021-02-19 18:21:10 +00:00
|
|
|
identityConciergeGV := makeGV("identity", "concierge")
|
2021-01-19 18:50:22 +00:00
|
|
|
authenticationConciergeGV := makeGV("authentication", "concierge")
|
|
|
|
configConciergeGV := makeGV("config", "concierge")
|
|
|
|
idpSupervisorGV := makeGV("idp", "supervisor")
|
|
|
|
configSupervisorGV := makeGV("config", "supervisor")
|
2022-06-15 16:38:21 +00:00
|
|
|
clientSecretSupervisorGV := makeGV("clientsecret", "supervisor")
|
2021-01-19 18:50:22 +00:00
|
|
|
|
2020-09-09 15:36:38 +00:00
|
|
|
tests := []struct {
|
|
|
|
group metav1.APIGroup
|
|
|
|
resourceByVersion map[string][]metav1.APIResource
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
group: metav1.APIGroup{
|
2021-01-19 18:50:22 +00:00
|
|
|
Name: loginConciergeGV.Group,
|
2020-09-09 15:36:38 +00:00
|
|
|
Versions: []metav1.GroupVersionForDiscovery{
|
|
|
|
{
|
2021-01-19 18:50:22 +00:00
|
|
|
GroupVersion: loginConciergeGV.String(),
|
|
|
|
Version: loginConciergeGV.Version,
|
2020-09-09 15:36:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
PreferredVersion: metav1.GroupVersionForDiscovery{
|
2021-01-19 18:50:22 +00:00
|
|
|
GroupVersion: loginConciergeGV.String(),
|
|
|
|
Version: loginConciergeGV.Version,
|
2020-09-09 15:23:28 +00:00
|
|
|
},
|
|
|
|
},
|
2020-09-09 15:36:38 +00:00
|
|
|
resourceByVersion: map[string][]metav1.APIResource{
|
2021-01-19 18:50:22 +00:00
|
|
|
loginConciergeGV.String(): {
|
2020-09-09 15:36:38 +00:00
|
|
|
{
|
2020-09-18 22:15:04 +00:00
|
|
|
Name: "tokencredentialrequests",
|
|
|
|
Kind: "TokenCredentialRequest",
|
2021-02-05 15:55:19 +00:00
|
|
|
Verbs: []string{"create", "list"},
|
2021-02-09 16:57:34 +00:00
|
|
|
Namespaced: false,
|
2020-11-13 18:09:22 +00:00
|
|
|
Categories: []string{"pinniped"},
|
2020-09-09 15:36:38 +00:00
|
|
|
},
|
|
|
|
},
|
2020-09-09 15:23:28 +00:00
|
|
|
},
|
2020-09-09 15:36:38 +00:00
|
|
|
},
|
2021-02-19 18:21:10 +00:00
|
|
|
{
|
|
|
|
group: metav1.APIGroup{
|
|
|
|
Name: identityConciergeGV.Group,
|
|
|
|
Versions: []metav1.GroupVersionForDiscovery{
|
|
|
|
{
|
|
|
|
GroupVersion: identityConciergeGV.String(),
|
|
|
|
Version: identityConciergeGV.Version,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PreferredVersion: metav1.GroupVersionForDiscovery{
|
|
|
|
GroupVersion: identityConciergeGV.String(),
|
|
|
|
Version: identityConciergeGV.Version,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
resourceByVersion: map[string][]metav1.APIResource{
|
|
|
|
identityConciergeGV.String(): {
|
|
|
|
{
|
|
|
|
Name: "whoamirequests",
|
|
|
|
Kind: "WhoAmIRequest",
|
|
|
|
Verbs: []string{"create", "list"},
|
|
|
|
Namespaced: false,
|
|
|
|
Categories: []string{"pinniped"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-06-09 20:45:21 +00:00
|
|
|
{
|
|
|
|
group: metav1.APIGroup{
|
2022-06-15 16:38:21 +00:00
|
|
|
Name: clientSecretSupervisorGV.Group,
|
2022-06-09 20:45:21 +00:00
|
|
|
Versions: []metav1.GroupVersionForDiscovery{
|
|
|
|
{
|
2022-06-15 16:38:21 +00:00
|
|
|
GroupVersion: clientSecretSupervisorGV.String(),
|
|
|
|
Version: clientSecretSupervisorGV.Version,
|
2022-06-09 20:45:21 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
PreferredVersion: metav1.GroupVersionForDiscovery{
|
2022-06-15 16:38:21 +00:00
|
|
|
GroupVersion: clientSecretSupervisorGV.String(),
|
|
|
|
Version: clientSecretSupervisorGV.Version,
|
2022-06-09 20:45:21 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
resourceByVersion: map[string][]metav1.APIResource{
|
2022-06-15 16:38:21 +00:00
|
|
|
clientSecretSupervisorGV.String(): {
|
2022-06-09 20:45:21 +00:00
|
|
|
{
|
|
|
|
Name: "oidcclientsecretrequests",
|
|
|
|
Kind: "OIDCClientSecretRequest",
|
2022-06-15 16:38:21 +00:00
|
|
|
Verbs: []string{"create", "list"},
|
2022-06-09 20:45:21 +00:00
|
|
|
Namespaced: true,
|
2022-06-15 16:38:21 +00:00
|
|
|
Categories: []string{"pinniped"},
|
2022-06-09 20:45:21 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-09-09 15:36:38 +00:00
|
|
|
{
|
|
|
|
group: metav1.APIGroup{
|
2021-01-19 18:50:22 +00:00
|
|
|
Name: configSupervisorGV.Group,
|
2020-09-09 15:36:38 +00:00
|
|
|
Versions: []metav1.GroupVersionForDiscovery{
|
|
|
|
{
|
2021-01-19 18:50:22 +00:00
|
|
|
GroupVersion: configSupervisorGV.String(),
|
|
|
|
Version: configSupervisorGV.Version,
|
2020-09-09 15:36:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
PreferredVersion: metav1.GroupVersionForDiscovery{
|
2021-01-19 18:50:22 +00:00
|
|
|
GroupVersion: configSupervisorGV.String(),
|
|
|
|
Version: configSupervisorGV.Version,
|
2020-09-09 15:36:38 +00:00
|
|
|
},
|
2020-09-09 15:23:28 +00:00
|
|
|
},
|
2020-09-09 15:36:38 +00:00
|
|
|
resourceByVersion: map[string][]metav1.APIResource{
|
2021-01-19 18:50:22 +00:00
|
|
|
configSupervisorGV.String(): {
|
2020-10-07 00:53:29 +00:00
|
|
|
{
|
2020-12-16 22:27:09 +00:00
|
|
|
Name: "federationdomains",
|
|
|
|
SingularName: "federationdomain",
|
2020-10-07 00:53:29 +00:00
|
|
|
Namespaced: true,
|
2020-12-16 22:27:09 +00:00
|
|
|
Kind: "FederationDomain",
|
2020-10-07 00:53:29 +00:00
|
|
|
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
|
2020-11-12 22:24:25 +00:00
|
|
|
Categories: []string{"pinniped"},
|
2020-10-07 00:53:29 +00:00
|
|
|
},
|
2021-02-11 02:20:19 +00:00
|
|
|
{
|
|
|
|
Name: "federationdomains/status",
|
|
|
|
Namespaced: true,
|
|
|
|
Kind: "FederationDomain",
|
|
|
|
Verbs: []string{"get", "patch", "update"},
|
|
|
|
},
|
2022-06-05 04:04:40 +00:00
|
|
|
{
|
|
|
|
Name: "oidcclients",
|
|
|
|
SingularName: "oidcclient",
|
|
|
|
Namespaced: true,
|
|
|
|
Kind: "OIDCClient",
|
|
|
|
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
|
|
|
|
Categories: []string{"pinniped"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "oidcclients/status",
|
|
|
|
Namespaced: true,
|
|
|
|
Kind: "OIDCClient",
|
|
|
|
Verbs: []string{"get", "patch", "update"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-11-12 00:28:42 +00:00
|
|
|
{
|
|
|
|
group: metav1.APIGroup{
|
2021-01-19 18:50:22 +00:00
|
|
|
Name: idpSupervisorGV.Group,
|
2020-11-12 00:28:42 +00:00
|
|
|
Versions: []metav1.GroupVersionForDiscovery{
|
|
|
|
{
|
2021-01-19 18:50:22 +00:00
|
|
|
GroupVersion: idpSupervisorGV.String(),
|
|
|
|
Version: idpSupervisorGV.Version,
|
2020-11-12 00:28:42 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
PreferredVersion: metav1.GroupVersionForDiscovery{
|
2021-01-19 18:50:22 +00:00
|
|
|
GroupVersion: idpSupervisorGV.String(),
|
|
|
|
Version: idpSupervisorGV.Version,
|
2020-11-12 00:28:42 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
resourceByVersion: map[string][]metav1.APIResource{
|
2021-01-19 18:50:22 +00:00
|
|
|
idpSupervisorGV.String(): {
|
2020-11-12 00:28:42 +00:00
|
|
|
{
|
2020-12-16 22:27:09 +00:00
|
|
|
Name: "oidcidentityproviders",
|
|
|
|
SingularName: "oidcidentityprovider",
|
2020-11-12 00:28:42 +00:00
|
|
|
Namespaced: true,
|
2020-12-16 22:27:09 +00:00
|
|
|
Kind: "OIDCIdentityProvider",
|
2020-11-12 00:28:42 +00:00
|
|
|
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
|
|
|
|
Categories: []string{"pinniped", "pinniped-idp", "pinniped-idps"},
|
|
|
|
},
|
|
|
|
{
|
2020-12-16 22:27:09 +00:00
|
|
|
Name: "oidcidentityproviders/status",
|
2020-11-12 00:28:42 +00:00
|
|
|
Namespaced: true,
|
2020-12-16 22:27:09 +00:00
|
|
|
Kind: "OIDCIdentityProvider",
|
2020-11-12 00:28:42 +00:00
|
|
|
Verbs: []string{"get", "patch", "update"},
|
2021-04-06 17:10:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "ldapidentityproviders",
|
|
|
|
SingularName: "ldapidentityprovider",
|
|
|
|
Namespaced: true,
|
|
|
|
Kind: "LDAPIdentityProvider",
|
|
|
|
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
|
|
|
|
Categories: []string{"pinniped", "pinniped-idp", "pinniped-idps"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "ldapidentityproviders/status",
|
|
|
|
Namespaced: true,
|
|
|
|
Kind: "LDAPIdentityProvider",
|
|
|
|
Verbs: []string{"get", "patch", "update"},
|
2021-07-07 18:15:52 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "activedirectoryidentityproviders",
|
|
|
|
SingularName: "activedirectoryidentityprovider",
|
|
|
|
Namespaced: true,
|
|
|
|
Kind: "ActiveDirectoryIdentityProvider",
|
|
|
|
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
|
|
|
|
Categories: []string{"pinniped", "pinniped-idp", "pinniped-idps"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "activedirectoryidentityproviders/status",
|
|
|
|
Namespaced: true,
|
|
|
|
Kind: "ActiveDirectoryIdentityProvider",
|
|
|
|
Verbs: []string{"get", "patch", "update"},
|
2020-11-12 00:28:42 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-10-30 20:09:14 +00:00
|
|
|
{
|
|
|
|
group: metav1.APIGroup{
|
2021-01-19 18:50:22 +00:00
|
|
|
Name: configConciergeGV.Group,
|
2020-10-30 20:09:14 +00:00
|
|
|
Versions: []metav1.GroupVersionForDiscovery{
|
|
|
|
{
|
2021-01-19 18:50:22 +00:00
|
|
|
GroupVersion: configConciergeGV.String(),
|
|
|
|
Version: configConciergeGV.Version,
|
2020-10-30 20:09:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
PreferredVersion: metav1.GroupVersionForDiscovery{
|
2021-01-19 18:50:22 +00:00
|
|
|
GroupVersion: configConciergeGV.String(),
|
|
|
|
Version: configConciergeGV.Version,
|
2020-10-30 20:09:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
resourceByVersion: map[string][]metav1.APIResource{
|
2021-01-19 18:50:22 +00:00
|
|
|
configConciergeGV.String(): {
|
2020-10-30 20:09:14 +00:00
|
|
|
{
|
2020-11-02 21:39:43 +00:00
|
|
|
Name: "credentialissuers",
|
|
|
|
SingularName: "credentialissuer",
|
2021-02-09 16:57:34 +00:00
|
|
|
Namespaced: false,
|
2020-11-02 21:39:43 +00:00
|
|
|
Kind: "CredentialIssuer",
|
2020-10-30 20:09:14 +00:00
|
|
|
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
|
2020-11-12 22:24:25 +00:00
|
|
|
Categories: []string{"pinniped"},
|
2020-10-30 20:09:14 +00:00
|
|
|
},
|
2021-02-11 02:20:19 +00:00
|
|
|
{
|
|
|
|
Name: "credentialissuers/status",
|
|
|
|
Namespaced: false,
|
|
|
|
Kind: "CredentialIssuer",
|
|
|
|
Verbs: []string{"get", "patch", "update"},
|
|
|
|
},
|
2020-10-30 20:09:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-09-09 15:36:38 +00:00
|
|
|
{
|
|
|
|
group: metav1.APIGroup{
|
2021-01-19 18:50:22 +00:00
|
|
|
Name: authenticationConciergeGV.Group,
|
2020-09-09 15:36:38 +00:00
|
|
|
Versions: []metav1.GroupVersionForDiscovery{
|
|
|
|
{
|
2021-01-19 18:50:22 +00:00
|
|
|
GroupVersion: authenticationConciergeGV.String(),
|
|
|
|
Version: authenticationConciergeGV.Version,
|
2020-09-09 15:36:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
PreferredVersion: metav1.GroupVersionForDiscovery{
|
2021-01-19 18:50:22 +00:00
|
|
|
GroupVersion: authenticationConciergeGV.String(),
|
|
|
|
Version: authenticationConciergeGV.Version,
|
2020-09-09 15:36:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
resourceByVersion: map[string][]metav1.APIResource{
|
2021-01-19 18:50:22 +00:00
|
|
|
authenticationConciergeGV.String(): {
|
2020-09-09 15:36:38 +00:00
|
|
|
{
|
2020-10-30 16:39:26 +00:00
|
|
|
Name: "webhookauthenticators",
|
|
|
|
SingularName: "webhookauthenticator",
|
2021-02-09 16:57:34 +00:00
|
|
|
Namespaced: false,
|
2020-10-30 16:39:26 +00:00
|
|
|
Kind: "WebhookAuthenticator",
|
2020-09-09 15:36:38 +00:00
|
|
|
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
|
2020-11-12 22:24:25 +00:00
|
|
|
Categories: []string{"pinniped", "pinniped-authenticator", "pinniped-authenticators"},
|
2020-09-09 15:36:38 +00:00
|
|
|
},
|
2021-02-11 02:20:19 +00:00
|
|
|
{
|
|
|
|
Name: "webhookauthenticators/status",
|
|
|
|
Namespaced: false,
|
|
|
|
Kind: "WebhookAuthenticator",
|
|
|
|
Verbs: []string{"get", "patch", "update"},
|
|
|
|
},
|
2020-12-08 01:37:43 +00:00
|
|
|
{
|
|
|
|
Name: "jwtauthenticators",
|
|
|
|
SingularName: "jwtauthenticator",
|
2021-02-09 16:57:34 +00:00
|
|
|
Namespaced: false,
|
2020-12-08 01:37:43 +00:00
|
|
|
Kind: "JWTAuthenticator",
|
|
|
|
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
|
|
|
|
Categories: []string{"pinniped", "pinniped-authenticator", "pinniped-authenticators"},
|
|
|
|
},
|
2021-02-11 02:20:19 +00:00
|
|
|
{
|
|
|
|
Name: "jwtauthenticators/status",
|
|
|
|
Namespaced: false,
|
|
|
|
Kind: "JWTAuthenticator",
|
|
|
|
Verbs: []string{"get", "patch", "update"},
|
|
|
|
},
|
2020-09-09 15:36:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-08-01 00:37:59 +00:00
|
|
|
}
|
2020-09-09 15:23:28 +00:00
|
|
|
|
2020-11-12 22:24:25 +00:00
|
|
|
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
|
|
|
|
}
|
2021-01-13 01:27:41 +00:00
|
|
|
foundPinnipedGroups := 0
|
2020-11-12 22:24:25 +00:00
|
|
|
for _, g := range groups {
|
2021-01-19 18:50:22 +00:00
|
|
|
if !strings.Contains(g.Name, env.APIGroupSuffix) {
|
2020-11-12 22:24:25 +00:00
|
|
|
continue
|
|
|
|
}
|
2021-01-13 01:27:41 +00:00
|
|
|
foundPinnipedGroups++
|
2020-11-12 22:24:25 +00:00
|
|
|
assert.Truef(t, testedGroups[g.Name], "expected group %q to have assertions defined", g.Name)
|
|
|
|
}
|
2021-01-13 01:27:41 +00:00
|
|
|
require.Equal(t, len(testedGroups), foundPinnipedGroups)
|
2020-11-12 22:24:25 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("every API categorized appropriately", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
for _, r := range resources {
|
2021-01-19 18:50:22 +00:00
|
|
|
if !strings.Contains(r.GroupVersion, env.APIGroupSuffix) {
|
2020-11-12 22:24:25 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
for _, a := range r.APIResources {
|
2020-11-12 00:28:42 +00:00
|
|
|
if strings.HasSuffix(a.Name, "/status") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
assert.Containsf(t, a.Categories, "pinniped", "expected resource %q to be in the 'pinniped' category", a.Name)
|
2020-11-13 18:09:22 +00:00
|
|
|
assert.NotContainsf(t, a.Categories, "all", "expected resource %q not to be in the 'all' category", a.Name)
|
2020-11-12 22:24:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-02-09 16:57:34 +00:00
|
|
|
t.Run("every concierge API is cluster scoped", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
for _, r := range resources {
|
|
|
|
if !strings.Contains(r.GroupVersion, env.APIGroupSuffix) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(r.GroupVersion, ".concierge.") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, a := range r.APIResources {
|
|
|
|
assert.False(t, a.Namespaced, "concierge APIs must be cluster scoped: %#v", a)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-02-11 02:20:19 +00:00
|
|
|
t.Run("every API has a status subresource", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2022-06-09 20:45:21 +00:00
|
|
|
aggregatedAPIs := sets.NewString("tokencredentialrequests", "whoamirequests", "oidcclientsecretrequests")
|
2021-02-19 18:21:10 +00:00
|
|
|
|
2021-02-11 02:20:19 +00:00
|
|
|
var regular, status []string
|
|
|
|
|
|
|
|
for _, r := range resources {
|
|
|
|
if !strings.Contains(r.GroupVersion, env.APIGroupSuffix) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, a := range r.APIResources {
|
2021-02-19 18:21:10 +00:00
|
|
|
if aggregatedAPIs.Has(a.Name) {
|
|
|
|
continue // skip our special aggregated APIs with their own magical properties
|
2021-02-11 02:20:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if strings.HasSuffix(a.Name, "/status") {
|
|
|
|
status = append(status, strings.TrimSuffix(a.Name, "/status"))
|
|
|
|
} else {
|
|
|
|
regular = append(regular, a.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, regular, status)
|
|
|
|
})
|
|
|
|
|
2022-08-30 19:11:17 +00:00
|
|
|
t.Run("every API can show its docs to the user via kubectl explain, including aggregated APIs, and everything has a description", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
for _, r := range resources {
|
|
|
|
if !strings.Contains(r.GroupVersion, env.APIGroupSuffix) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, a := range r.APIResources {
|
|
|
|
if strings.HasSuffix(a.Name, "/status") {
|
|
|
|
// skip status subresources for this test, as they don't work with `kubectl explain`
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that this test might indirectly depend on the kubectl discovery cache, found in $HOME/.kube/cache/discovery.
|
|
|
|
// If you are working on changing API type struct comments, then you may need to clear your discovery cache
|
|
|
|
// (or wait ~10 minutes for the cache to expire) for the new comments to appear in the `kubectl explain` results.
|
|
|
|
requireKubectlExplainShowsDescriptionForResource(t, a.Name, a.Kind, r.GroupVersion)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-11-12 22:49:21 +00:00
|
|
|
t.Run("Pinniped resources do not have short names", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
for _, r := range resources {
|
2021-01-19 18:50:22 +00:00
|
|
|
if !strings.Contains(r.GroupVersion, env.APIGroupSuffix) {
|
2020-11-12 22:49:21 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
for _, a := range r.APIResources {
|
|
|
|
assert.Empty(t, a.ShortNames, "expected resource %q not to have any short names", a.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-09-09 15:36:38 +00:00
|
|
|
for _, tt := range tests {
|
|
|
|
tt := tt
|
|
|
|
t.Run(tt.group.Name, func(t *testing.T) {
|
2020-11-12 22:24:25 +00:00
|
|
|
t.Parallel()
|
2020-09-09 15:36:38 +00:00
|
|
|
require.Contains(t, groups, &tt.group)
|
|
|
|
|
|
|
|
for groupVersion, expectedResources := range tt.resourceByVersion {
|
|
|
|
// Find the actual resource list and make a copy.
|
|
|
|
var actualResourceList *metav1.APIResourceList
|
|
|
|
for _, resource := range resources {
|
|
|
|
if resource.GroupVersion == groupVersion {
|
|
|
|
actualResourceList = resource.DeepCopy()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require.NotNilf(t, actualResourceList, "could not find groupVersion %s", groupVersion)
|
|
|
|
|
|
|
|
// Because its hard to predict the storage version hash (e.g. "t/+v41y+3e4="), we just don't
|
|
|
|
// worry about comparing that field.
|
|
|
|
for i := range actualResourceList.APIResources {
|
|
|
|
actualResourceList.APIResources[i].StorageVersionHash = ""
|
|
|
|
}
|
2020-10-07 18:42:30 +00:00
|
|
|
require.ElementsMatch(t, expectedResources, actualResourceList.APIResources, "unexpected API resources")
|
2020-09-09 15:36:38 +00:00
|
|
|
}
|
|
|
|
})
|
2020-09-09 15:23:28 +00:00
|
|
|
}
|
2020-08-01 00:37:59 +00:00
|
|
|
}
|
2021-09-20 19:47:39 +00:00
|
|
|
|
|
|
|
// safe to run in parallel with serial tests since it only reads CRDs, see main_test.go.
|
|
|
|
func TestCRDAdditionalPrinterColumns_Parallel(t *testing.T) {
|
|
|
|
// AdditionalPrinterColumns can be set on a CRD to make `kubectl get` return those columns in its table output.
|
|
|
|
// The main purpose of this test is to fail when we add a new CRD without considering which
|
|
|
|
// AdditionalPrinterColumns to set on it. This test will force us to consider it and make an explicit choice.
|
|
|
|
env := testlib.IntegrationEnv(t)
|
|
|
|
|
|
|
|
ctx, cancelFunc := context.WithTimeout(context.Background(), time.Minute)
|
|
|
|
defer cancelFunc()
|
|
|
|
|
|
|
|
// AdditionalPrinterColumns are not returned by the Kube discovery endpoints,
|
|
|
|
// so "discover" them in the CRD definitions instead.
|
|
|
|
apiExtensionsV1Client := testlib.NewAPIExtensionsV1Client(t)
|
|
|
|
crdList, err := apiExtensionsV1Client.CustomResourceDefinitions().List(ctx, metav1.ListOptions{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
addSuffix := func(base string) string {
|
|
|
|
return base + "." + env.APIGroupSuffix
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since we're checking that AdditionalPrinterColumns exists on every CRD then we might as well also
|
|
|
|
// assert which fields are set as AdditionalPrinterColumns.
|
|
|
|
// Ideally, every CRD should show some kind of identifying info, some kind of status, and Age.
|
|
|
|
expectedColumnsPerCRDVersion := map[string]map[string][]apiextensionsv1.CustomResourceColumnDefinition{
|
|
|
|
addSuffix("credentialissuers.config.concierge"): {
|
|
|
|
"v1alpha1": []apiextensionsv1.CustomResourceColumnDefinition{
|
|
|
|
{Name: "ProxyMode", Type: "string", JSONPath: ".spec.impersonationProxy.mode"},
|
2021-09-21 19:01:30 +00:00
|
|
|
// CredentialIssuer status is a list of strategies, each with its own status. Unfortunately,
|
2021-09-20 19:47:39 +00:00
|
|
|
// AdditionalPrinterColumns cannot show multiple results, e.g. a list of strategy types where
|
|
|
|
// the status is equal to Successful. See https://github.com/kubernetes/kubernetes/issues/67268.
|
2021-09-21 21:07:08 +00:00
|
|
|
// Although this selector can evaluate to multiple results, the Kube CRD implementation of JSONPath
|
2021-09-21 19:01:30 +00:00
|
|
|
// will always only show the first result. Thus, this column will show the first successful strategy
|
|
|
|
// type, which is the same thing that `pinniped get kubeconfig` looks for, so the value of this
|
|
|
|
// column represents the current default strategy that will be used by `pinniped get kubeconfig`.
|
|
|
|
{Name: "DefaultStrategy", Type: "string", JSONPath: `.status.strategies[?(@.status == "Success")].type`},
|
2021-09-20 19:47:39 +00:00
|
|
|
{Name: "Age", Type: "date", JSONPath: ".metadata.creationTimestamp"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
addSuffix("webhookauthenticators.authentication.concierge"): {
|
|
|
|
"v1alpha1": []apiextensionsv1.CustomResourceColumnDefinition{
|
|
|
|
{Name: "Endpoint", Type: "string", JSONPath: ".spec.endpoint"},
|
|
|
|
// Note that WebhookAuthenticators have a status type, but no controller currently sets the status, so we don't show it.
|
|
|
|
{Name: "Age", Type: "date", JSONPath: ".metadata.creationTimestamp"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
addSuffix("jwtauthenticators.authentication.concierge"): {
|
|
|
|
"v1alpha1": []apiextensionsv1.CustomResourceColumnDefinition{
|
|
|
|
{Name: "Issuer", Type: "string", JSONPath: ".spec.issuer"},
|
|
|
|
{Name: "Audience", Type: "string", JSONPath: ".spec.audience"},
|
|
|
|
// Note that JWTAuthenticators have a status type, but no controller currently sets the status, so we don't show it.
|
|
|
|
{Name: "Age", Type: "date", JSONPath: ".metadata.creationTimestamp"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
addSuffix("activedirectoryidentityproviders.idp.supervisor"): {
|
|
|
|
"v1alpha1": []apiextensionsv1.CustomResourceColumnDefinition{
|
|
|
|
{Name: "Host", Type: "string", JSONPath: ".spec.host"},
|
|
|
|
{Name: "Status", Type: "string", JSONPath: ".status.phase"},
|
|
|
|
{Name: "Age", Type: "date", JSONPath: ".metadata.creationTimestamp"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
addSuffix("federationdomains.config.supervisor"): {
|
|
|
|
"v1alpha1": []apiextensionsv1.CustomResourceColumnDefinition{
|
|
|
|
{Name: "Issuer", Type: "string", JSONPath: ".spec.issuer"},
|
|
|
|
{Name: "Status", Type: "string", JSONPath: ".status.status"},
|
|
|
|
{Name: "Age", Type: "date", JSONPath: ".metadata.creationTimestamp"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
addSuffix("ldapidentityproviders.idp.supervisor"): {
|
|
|
|
"v1alpha1": []apiextensionsv1.CustomResourceColumnDefinition{
|
|
|
|
{Name: "Host", Type: "string", JSONPath: ".spec.host"},
|
|
|
|
{Name: "Status", Type: "string", JSONPath: ".status.phase"},
|
|
|
|
{Name: "Age", Type: "date", JSONPath: ".metadata.creationTimestamp"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
addSuffix("oidcidentityproviders.idp.supervisor"): {
|
|
|
|
"v1alpha1": []apiextensionsv1.CustomResourceColumnDefinition{
|
|
|
|
{Name: "Issuer", Type: "string", JSONPath: ".spec.issuer"},
|
|
|
|
{Name: "Status", Type: "string", JSONPath: ".status.phase"},
|
|
|
|
{Name: "Age", Type: "date", JSONPath: ".metadata.creationTimestamp"},
|
|
|
|
},
|
|
|
|
},
|
2022-06-13 21:28:05 +00:00
|
|
|
addSuffix("oidcclients.config.supervisor"): {
|
2022-06-05 04:04:40 +00:00
|
|
|
"v1alpha1": []apiextensionsv1.CustomResourceColumnDefinition{
|
2022-07-21 23:40:03 +00:00
|
|
|
{Name: "Privileged Scopes", Type: "string", JSONPath: `.spec.allowedScopes[?(@ == "pinniped:request-audience")]`},
|
|
|
|
{Name: "Client Secrets", Type: "integer", JSONPath: ".status.totalClientSecrets"},
|
|
|
|
{Name: "Status", Type: "string", JSONPath: ".status.phase"},
|
2022-06-05 04:04:40 +00:00
|
|
|
{Name: "Age", Type: "date", JSONPath: ".metadata.creationTimestamp"},
|
|
|
|
},
|
|
|
|
},
|
2021-09-20 19:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
actualPinnipedCRDCount := 0
|
2022-06-05 04:04:40 +00:00
|
|
|
expectedPinnipedCRDCount := 8 // the current number of CRDs that we ship as part of Pinniped
|
2021-09-20 19:47:39 +00:00
|
|
|
|
|
|
|
for _, crd := range crdList.Items {
|
|
|
|
if !strings.Contains(crd.Spec.Group, env.APIGroupSuffix) {
|
|
|
|
continue // skip non-Pinniped CRDs
|
|
|
|
}
|
|
|
|
|
|
|
|
// Found a Pinniped CRD, so let's check it for AdditionalPrinterColumns.
|
|
|
|
actualPinnipedCRDCount++
|
|
|
|
|
|
|
|
for _, version := range crd.Spec.Versions {
|
|
|
|
expectedColumns, ok := expectedColumnsPerCRDVersion[crd.Name][version.Name]
|
|
|
|
assert.Truef(t, ok,
|
|
|
|
"should have found an expected AdditionalPrinterColumns for CRD %q version %q: "+
|
|
|
|
"please make sure that some useful AdditionalPrinterColumns are defined on the CRD and update this test's expectations",
|
|
|
|
crd.Name, version.Name)
|
|
|
|
assert.Equalf(t, expectedColumns, version.AdditionalPrinterColumns,
|
|
|
|
"CRD %q version %q had unexpected AdditionalPrinterColumns", crd.Name, version.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure that the logic of this test did not accidentally skip a CRD that it should have interrogated.
|
|
|
|
require.Equal(t, expectedPinnipedCRDCount, actualPinnipedCRDCount,
|
|
|
|
"did not find expected number of Pinniped CRDs to check for additionalPrinterColumns")
|
|
|
|
}
|
2022-08-30 19:11:17 +00:00
|
|
|
|
|
|
|
func requireKubectlExplainShowsDescriptionForResource(t *testing.T, resourceName string, resourceKind string, resourceGroupVersion string) {
|
|
|
|
// Run kubectl explain on the resource.
|
|
|
|
output := runKubectlExplain(t, resourceName, resourceGroupVersion)
|
|
|
|
|
|
|
|
// Check that the output is as expected.
|
|
|
|
require.Regexp(t, `(?m)^KIND:\s+`+regexp.QuoteMeta(resourceKind)+`$`, output)
|
|
|
|
require.Regexp(t, `(?m)^VERSION:\s+`+regexp.QuoteMeta(resourceGroupVersion)+`$`, output)
|
|
|
|
require.Regexp(t, `(?m)^DESCRIPTION:$`, output)
|
|
|
|
|
|
|
|
// Use assert here so that the test keeps running when a description is empty, so we can find all the empty descriptions.
|
|
|
|
assert.NotRegexp(t, `(?m)^\s*<empty>\s*$`, output, "resource or field should not have an empty description in kubectl explain")
|
|
|
|
|
|
|
|
if strings.Contains(output, "\nFIELD: ") {
|
|
|
|
// We must have explained a leaf field, which has no children fields.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if resourceName == "whoamirequests.spec" {
|
|
|
|
// This is an exception because this field is declared to be an empty struct in its type definition. It is
|
|
|
|
// not a leaf field because it is a struct, but it also has no children because the struct contains no fields.
|
|
|
|
// So it has neither the `FIELD:` section nor the `FIELDS:` section in the output.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we must have explained a resource or field which has children fields, so it should have a fields list.
|
|
|
|
require.Contains(t, output, "\nFIELDS:\n")
|
|
|
|
|
|
|
|
// Grab everything after the line that says `FIELDS:`.
|
|
|
|
fieldsSectionMatches := regexp.MustCompile(`(?s).+\nFIELDS:\n(.+)`).FindStringSubmatch(output)
|
|
|
|
require.Len(t, fieldsSectionMatches, 2)
|
|
|
|
allFieldsDescribedText := fieldsSectionMatches[1]
|
|
|
|
|
|
|
|
// Grab the names of all the fields from the fields description.
|
|
|
|
fieldNames := []string{}
|
|
|
|
for _, line := range strings.Split(allFieldsDescribedText, "\n") {
|
|
|
|
if strings.HasPrefix(line, " ") {
|
|
|
|
// Field names are indented by exactly three spaces.
|
|
|
|
// Skip lines that are indented deeper, which are field descriptions.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if len(strings.TrimSpace(line)) == 0 {
|
|
|
|
// Ignore empty lines.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// Field name lines start with 3 spaces, then the field name, then some tabs/spaces, then the field type.
|
|
|
|
// Grab just the field name.
|
|
|
|
fieldsNameMatches := regexp.MustCompile(`^ {3}(\S+)\s+`).FindStringSubmatch(line)
|
|
|
|
require.Len(t, fieldsNameMatches, 2, fmt.Sprintf("field name line which did not match: %s", line))
|
|
|
|
fieldNames = append(fieldNames, fieldsNameMatches[1])
|
|
|
|
}
|
|
|
|
require.Greater(t, len(fieldNames), 0, "should have found some field names in the kubectl explain output, but didn't find any")
|
|
|
|
|
|
|
|
// For each field, check to see that docs were provided for that field by making a recursive call to this function.
|
|
|
|
for _, fieldName := range fieldNames {
|
|
|
|
if fieldName == "kind" || fieldName == "metadata" || fieldName == "apiVersion" {
|
|
|
|
// Skip these since the docs are implemented by k8s packages, so we can assume that they are correct.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
requireKubectlExplainShowsDescriptionForResource(t, fmt.Sprintf("%s.%s", resourceName, fieldName), resourceKind, resourceGroupVersion)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func runKubectlExplain(t *testing.T, resourceName string, apiVersion string) string {
|
|
|
|
t.Helper()
|
|
|
|
var stdOut, stdErr bytes.Buffer
|
|
|
|
cmd := exec.Command("kubectl", "explain", resourceName, "--api-version", apiVersion)
|
|
|
|
t.Log("Running:", cmd.String())
|
|
|
|
cmd.Stdout = &stdOut
|
|
|
|
cmd.Stderr = &stdErr
|
|
|
|
err := cmd.Run()
|
|
|
|
var exitErr *exec.ExitError
|
|
|
|
if errors.As(err, &exitErr) {
|
|
|
|
t.Logf("Running kubectl explain had non-zero exit code."+
|
|
|
|
"\nkubectl explain stdout: %s\nkubectl explain stderr: %s", stdOut.String(), stdErr.String())
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
return stdOut.String()
|
|
|
|
}
|