mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-09-19 22:44:18 +00:00
Tests use CertificatesV1 when available, otherwise use CertificatesV1beta1
CertificatesV1beta1 was removed in Kube 1.22, so the tests cannot blindly rely on it anymore. Use CertificatesV1 whenever the server reports that is available, and otherwise use the old CertificatesV1beta1. Note that CertificatesV1 was introduced in Kube 1.19.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// Copyright 2021 the Pinniped contributors. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
certificatesv1 "k8s.io/api/certificates/v1"
|
||||
"k8s.io/client-go/discovery"
|
||||
)
|
||||
|
||||
func KubeServerSupportsCertificatesV1API(t *testing.T, discoveryClient discovery.DiscoveryInterface) bool {
|
||||
t.Helper()
|
||||
groupList, err := discoveryClient.ServerGroups()
|
||||
require.NoError(t, err)
|
||||
for _, group := range groupList.Groups {
|
||||
if group.Name == certificatesv1.GroupName {
|
||||
for _, version := range group.Versions {
|
||||
if version.Version == "v1" {
|
||||
// Note: v1 should exist in Kubernetes 1.19 and above
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user