From 379805f0c8c5a0b75002f71c1f1df455b4dd6947 Mon Sep 17 00:00:00 2001 From: Andrej Krejcir Date: Fri, 26 Jul 2024 11:09:15 +0200 Subject: [PATCH] api: Increase API version to v1 The current API is good enough to be v1. Signed-off-by: Andrej Krejcir --- api/{v1alpha1 => v1}/constants.go | 4 ++-- api/{v1alpha1 => v1}/types.go | 2 +- docs/api.md | 4 ++-- manifests/api_service.yaml | 4 ++-- manifests/config_map.yaml | 2 +- pkg/console/console.go | 4 ++-- pkg/console/service/service.go | 4 ++-- pkg/console/service/service_test.go | 2 +- pkg/console/tlsconfig/tlsconfig.go | 16 ++++++++-------- pkg/console/tlsconfig/tlsconfig_test.go | 16 ++++++++-------- tests/proxy_test.go | 2 +- tests/tests_suite_test.go | 2 +- tests/tlsconfig_test.go | 2 +- tests/user-role_test.go | 2 +- 14 files changed, 33 insertions(+), 33 deletions(-) rename api/{v1alpha1 => v1}/constants.go (51%) rename api/{v1alpha1 => v1}/types.go (98%) diff --git a/api/v1alpha1/constants.go b/api/v1/constants.go similarity index 51% rename from api/v1alpha1/constants.go rename to api/v1/constants.go index 1f3a6724..ab6958e0 100644 --- a/api/v1alpha1/constants.go +++ b/api/v1/constants.go @@ -1,6 +1,6 @@ -package v1alpha1 +package v1 const ( Group = "token.kubevirt.io" - Version = "v1alpha1" + Version = "v1" ) diff --git a/api/v1alpha1/types.go b/api/v1/types.go similarity index 98% rename from api/v1alpha1/types.go rename to api/v1/types.go index 37c7633b..c5d33fae 100644 --- a/api/v1alpha1/types.go +++ b/api/v1/types.go @@ -1,4 +1,4 @@ -package v1alpha1 +package v1 import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/docs/api.md b/docs/api.md index 2ab077a8..5a55ac96 100644 --- a/docs/api.md +++ b/docs/api.md @@ -4,7 +4,7 @@ A temporary token can be generated using: ``` -GET /apis/token.kubevirt.io/v1alpha1/namespaces/${VMI_NAMESPACE}/virtualmachines/${VMI_NAME}/vnc +GET /apis/token.kubevirt.io/v1/namespaces/${VMI_NAMESPACE}/virtualmachines/${VMI_NAME}/vnc ``` Where `${VMI_NAMESPACE}` and `${VMI_NAME}` are the namespace and name of a running VMI. @@ -28,7 +28,7 @@ Result is a JSON object containing the token: ### Example ```bash curl --header "Authorization: Bearer ${KUBERNETES_USER_TOKEN}" \ - "https://${K8S_API_URL}/apis/token.kubevirt.io/v1alpha1/namespaces/${VMI_NAMESPACE}/virtualmachines/${VMI_NAME}/vnc?duration=${DURATION}" + "https://${K8S_API_URL}/apis/token.kubevirt.io/v1/namespaces/${VMI_NAMESPACE}/virtualmachines/${VMI_NAME}/vnc?duration=${DURATION}" ``` In this example, we use a bearer token to authenticate the user with the Kubernetes API server. diff --git a/manifests/api_service.yaml b/manifests/api_service.yaml index 4e9916cd..44c7af74 100644 --- a/manifests/api_service.yaml +++ b/manifests/api_service.yaml @@ -1,12 +1,12 @@ apiVersion: apiregistration.k8s.io/v1 kind: APIService metadata: - name: v1alpha1.token.kubevirt.io + name: v1.token.kubevirt.io annotations: service.beta.openshift.io/inject-cabundle: "true" spec: group: token.kubevirt.io - version: v1alpha1 + version: v1 groupPriorityMinimum: 2000 versionPriority: 10 service: diff --git a/manifests/config_map.yaml b/manifests/config_map.yaml index 6015e97f..693c05ae 100644 --- a/manifests/config_map.yaml +++ b/manifests/config_map.yaml @@ -3,4 +3,4 @@ kind: ConfigMap metadata: name: vm-console-proxy data: - tls-profile-v1alpha1.yaml: "{}" + tls-profile-v1.yaml: "{}" diff --git a/pkg/console/console.go b/pkg/console/console.go index 33e3d598..30c43aae 100644 --- a/pkg/console/console.go +++ b/pkg/console/console.go @@ -6,7 +6,7 @@ import ( "net/http" "github.com/emicklei/go-restful/v3" - api "github.com/kubevirt/vm-console-proxy/api/v1alpha1" + api "github.com/kubevirt/vm-console-proxy/api/v1" "github.com/kubevirt/vm-console-proxy/pkg/console/authConfig" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "kubevirt.io/client-go/kubecli" @@ -26,7 +26,7 @@ const ( keyName = "tls.key" configDir = "/config" - TlsProfileFile = "tls-profile-v1alpha1.yaml" + TlsProfileFile = "tls-profile-v1.yaml" ) func Run() error { diff --git a/pkg/console/service/service.go b/pkg/console/service/service.go index 66c2f6e2..6e5363ae 100644 --- a/pkg/console/service/service.go +++ b/pkg/console/service/service.go @@ -21,7 +21,7 @@ import ( kubevirtv1 "kubevirt.io/api/core/v1" "kubevirt.io/client-go/kubecli" - "github.com/kubevirt/vm-console-proxy/api/v1alpha1" + "github.com/kubevirt/vm-console-proxy/api/v1" "github.com/kubevirt/vm-console-proxy/pkg/console/authConfig" ) @@ -85,7 +85,7 @@ func (s *service) TokenHandler(request *restful.Request, response *restful.Respo return } - _ = response.WriteAsJson(&v1alpha1.TokenResponse{ + _ = response.WriteAsJson(&v1.TokenResponse{ Token: tokenRequestStatus.Token, ExpirationTimestamp: tokenRequestStatus.ExpirationTimestamp, }) diff --git a/pkg/console/service/service_test.go b/pkg/console/service/service_test.go index d4523c96..6d3e3f6f 100644 --- a/pkg/console/service/service_test.go +++ b/pkg/console/service/service_test.go @@ -25,7 +25,7 @@ import ( v1 "kubevirt.io/api/core/v1" "kubevirt.io/client-go/kubecli" - api "github.com/kubevirt/vm-console-proxy/api/v1alpha1" + api "github.com/kubevirt/vm-console-proxy/api/v1" "github.com/kubevirt/vm-console-proxy/pkg/console/authConfig" fakeAuth "github.com/kubevirt/vm-console-proxy/pkg/console/authConfig/fake" ) diff --git a/pkg/console/tlsconfig/tlsconfig.go b/pkg/console/tlsconfig/tlsconfig.go index 9caffaac..71854338 100644 --- a/pkg/console/tlsconfig/tlsconfig.go +++ b/pkg/console/tlsconfig/tlsconfig.go @@ -13,7 +13,7 @@ import ( "k8s.io/client-go/util/cert" "kubevirt.io/client-go/log" - "github.com/kubevirt/vm-console-proxy/api/v1alpha1" + "github.com/kubevirt/vm-console-proxy/api/v1" "github.com/kubevirt/vm-console-proxy/pkg/console/authConfig" "github.com/kubevirt/vm-console-proxy/pkg/filewatch" ) @@ -176,7 +176,7 @@ func loadCipherSuitesAndMinVersion(configPath string) ([]uint16, uint16, error) return ciphers, minVersion, nil } -func loadTlsProfile(profilePath string) (*v1alpha1.TlsProfile, error) { +func loadTlsProfile(profilePath string) (*v1.TlsProfile, error) { file, err := os.Open(profilePath) if err != nil { return nil, fmt.Errorf("error opening file: %w", err) @@ -184,7 +184,7 @@ func loadTlsProfile(profilePath string) (*v1alpha1.TlsProfile, error) { // It's ok to ignore error on close, because the file is opened of reading defer func() { _ = file.Close() }() - result := &v1alpha1.TlsProfile{} + result := &v1.TlsProfile{} err = yaml.NewYAMLToJSONDecoder(file).Decode(result) if err != nil { return nil, fmt.Errorf("error decoding tls config: %w", err) @@ -214,17 +214,17 @@ outerLoop: return result, nil } -func getMinTlsVersion(version v1alpha1.TLSProtocolVersion) (uint16, error) { +func getMinTlsVersion(version v1.TLSProtocolVersion) (uint16, error) { switch version { case "": return 0, nil - case v1alpha1.VersionTLS10: + case v1.VersionTLS10: return tls.VersionTLS10, nil - case v1alpha1.VersionTLS11: + case v1.VersionTLS11: return tls.VersionTLS11, nil - case v1alpha1.VersionTLS12: + case v1.VersionTLS12: return tls.VersionTLS12, nil - case v1alpha1.VersionTLS13: + case v1.VersionTLS13: return tls.VersionTLS13, nil default: return 0, fmt.Errorf("unsupported TLS version: %s", version) diff --git a/pkg/console/tlsconfig/tlsconfig_test.go b/pkg/console/tlsconfig/tlsconfig_test.go index 8424fbdc..632f508a 100644 --- a/pkg/console/tlsconfig/tlsconfig_test.go +++ b/pkg/console/tlsconfig/tlsconfig_test.go @@ -16,7 +16,7 @@ import ( "k8s.io/client-go/util/cert" "sigs.k8s.io/yaml" - "github.com/kubevirt/vm-console-proxy/api/v1alpha1" + "github.com/kubevirt/vm-console-proxy/api/v1" fakeAuth "github.com/kubevirt/vm-console-proxy/pkg/console/authConfig/fake" "github.com/kubevirt/vm-console-proxy/pkg/filewatch" ) @@ -62,9 +62,9 @@ var _ = Describe("TlsConfig", func() { tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, } - tlsProfile := &v1alpha1.TlsProfile{ + tlsProfile := &v1.TlsProfile{ Ciphers: testCiphersNames, - MinTLSVersion: v1alpha1.VersionTLS12, + MinTLSVersion: v1.VersionTLS12, } tlsProfileYaml, err := yaml.Marshal(tlsProfile) Expect(err).ToNot(HaveOccurred()) @@ -126,8 +126,8 @@ var _ = Describe("TlsConfig", func() { }) It("should use default ciphers, if ciphers are not sepcified", func() { - tlsConfig := &v1alpha1.TlsProfile{ - MinTLSVersion: v1alpha1.VersionTLS12, + tlsConfig := &v1.TlsProfile{ + MinTLSVersion: v1.VersionTLS12, } tlsConfigYaml, err := yaml.Marshal(tlsConfig) Expect(err).ToNot(HaveOccurred()) @@ -144,7 +144,7 @@ var _ = Describe("TlsConfig", func() { }) It("should use default tls version, if MinTLSVersion is not specified", func() { - tlsConfig := &v1alpha1.TlsProfile{ + tlsConfig := &v1.TlsProfile{ Ciphers: testCiphersNames, } tlsConfigYaml, err := yaml.Marshal(tlsConfig) @@ -198,13 +198,13 @@ var _ = Describe("TlsConfig", func() { originalConfig, err := configWatch.GetConfig() Expect(err).ToNot(HaveOccurred()) - tlsProfile := &v1alpha1.TlsProfile{ + tlsProfile := &v1.TlsProfile{ Ciphers: []string{ "TLS_AES_128_GCM_SHA256", "TLS_AES_256_GCM_SHA384", "TLS_CHACHA20_POLY1305_SHA256", }, - MinTLSVersion: v1alpha1.VersionTLS13, + MinTLSVersion: v1.VersionTLS13, } tlsProfileYaml, err := yaml.Marshal(tlsProfile) Expect(err).ToNot(HaveOccurred()) diff --git a/tests/proxy_test.go b/tests/proxy_test.go index faf0c110..f1422857 100644 --- a/tests/proxy_test.go +++ b/tests/proxy_test.go @@ -23,7 +23,7 @@ import ( "k8s.io/utils/pointer" kubevirtcorev1 "kubevirt.io/api/core/v1" - api "github.com/kubevirt/vm-console-proxy/api/v1alpha1" + api "github.com/kubevirt/vm-console-proxy/api/v1" ) var _ = Describe("Kubevirt proxy", func() { diff --git a/tests/tests_suite_test.go b/tests/tests_suite_test.go index 69e233af..7e155d0e 100644 --- a/tests/tests_suite_test.go +++ b/tests/tests_suite_test.go @@ -11,7 +11,7 @@ import ( "testing" "time" - api "github.com/kubevirt/vm-console-proxy/api/v1alpha1" + api "github.com/kubevirt/vm-console-proxy/api/v1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" core "k8s.io/api/core/v1" diff --git a/tests/tlsconfig_test.go b/tests/tlsconfig_test.go index 31e98755..28b6e011 100644 --- a/tests/tlsconfig_test.go +++ b/tests/tlsconfig_test.go @@ -10,7 +10,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - api "github.com/kubevirt/vm-console-proxy/api/v1alpha1" + api "github.com/kubevirt/vm-console-proxy/api/v1" core "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/tests/user-role_test.go b/tests/user-role_test.go index 83e7e683..96e3046c 100644 --- a/tests/user-role_test.go +++ b/tests/user-role_test.go @@ -13,7 +13,7 @@ import ( rbac "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - proxy "github.com/kubevirt/vm-console-proxy/api/v1alpha1" + proxy "github.com/kubevirt/vm-console-proxy/api/v1" ) var _ = Describe("Role for token generation", func() {