Skip to content

Commit

Permalink
api: Increase API version to v1
Browse files Browse the repository at this point in the history
The current API is good enough to be v1.

Signed-off-by: Andrej Krejcir <[email protected]>
  • Loading branch information
akrejcir committed Jul 26, 2024
1 parent 2c49be9 commit 379805f
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions api/v1alpha1/constants.go → api/v1/constants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package v1alpha1
package v1

const (
Group = "token.kubevirt.io"
Version = "v1alpha1"
Version = "v1"
)
2 changes: 1 addition & 1 deletion api/v1alpha1/types.go → api/v1/types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v1alpha1
package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
4 changes: 2 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions manifests/api_service.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion manifests/config_map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ kind: ConfigMap
metadata:
name: vm-console-proxy
data:
tls-profile-v1alpha1.yaml: "{}"
tls-profile-v1.yaml: "{}"
4 changes: 2 additions & 2 deletions pkg/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -26,7 +26,7 @@ const (
keyName = "tls.key"

configDir = "/config"
TlsProfileFile = "tls-profile-v1alpha1.yaml"
TlsProfileFile = "tls-profile-v1.yaml"
)

func Run() error {
Expand Down
4 changes: 2 additions & 2 deletions pkg/console/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/console/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
16 changes: 8 additions & 8 deletions pkg/console/tlsconfig/tlsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -176,15 +176,15 @@ 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)
}
// 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)
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions pkg/console/tlsconfig/tlsconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand All @@ -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)
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/tlsconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion tests/user-role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 379805f

Please sign in to comment.