diff --git a/images/virtualization-artifact/api/operations/register.go b/images/virtualization-artifact/api/operations/register.go index c4a1e1267..095d1ed80 100644 --- a/images/virtualization-artifact/api/operations/register.go +++ b/images/virtualization-artifact/api/operations/register.go @@ -1,9 +1,10 @@ package operations import ( - virtv2 "github.com/deckhouse/virtualization-controller/api/core/v1alpha2" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" + + virtv2 "github.com/deckhouse/virtualization-controller/api/core/v1alpha2" ) // GroupName is the group name use in this package diff --git a/images/virtualization-artifact/api/operations/v1alpha1/register.go b/images/virtualization-artifact/api/operations/v1alpha1/register.go index 253e7da6d..7d153da36 100644 --- a/images/virtualization-artifact/api/operations/v1alpha1/register.go +++ b/images/virtualization-artifact/api/operations/v1alpha1/register.go @@ -1,10 +1,10 @@ package v1alpha1 import ( - virtv2 "github.com/deckhouse/virtualization-controller/api/core/v1alpha2" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" + virtv2 "github.com/deckhouse/virtualization-controller/api/core/v1alpha2" "github.com/deckhouse/virtualization-controller/api/operations" ) diff --git a/images/virtualization-artifact/cmd/virtualization-api/app/options/options.go b/images/virtualization-artifact/cmd/virtualization-api/app/options/options.go index 607aca652..aa3ef72c9 100644 --- a/images/virtualization-artifact/cmd/virtualization-api/app/options/options.go +++ b/images/virtualization-artifact/cmd/virtualization-api/app/options/options.go @@ -2,7 +2,6 @@ package options import ( "fmt" - rest2 "github.com/deckhouse/virtualization-controller/pkg/apiserver/rest" "net" "strings" @@ -18,6 +17,7 @@ import ( "github.com/deckhouse/virtualization-controller/pkg/apiserver/api" generatedopenapi "github.com/deckhouse/virtualization-controller/pkg/apiserver/api/generated/openapi" + rest2 "github.com/deckhouse/virtualization-controller/pkg/apiserver/rest" "github.com/deckhouse/virtualization-controller/pkg/apiserver/server" vconf "github.com/deckhouse/virtualization-controller/pkg/config" ) diff --git a/images/virtualization-artifact/pkg/apiserver/api/install.go b/images/virtualization-artifact/pkg/apiserver/api/install.go index 6e866e71c..3a3b563b7 100644 --- a/images/virtualization-artifact/pkg/apiserver/api/install.go +++ b/images/virtualization-artifact/pkg/apiserver/api/install.go @@ -1,8 +1,6 @@ package api import ( - rest2 "github.com/deckhouse/virtualization-controller/pkg/apiserver/rest" - "github.com/deckhouse/virtualization-controller/pkg/tls/certManager" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" @@ -14,7 +12,9 @@ import ( "github.com/deckhouse/virtualization-controller/api/operations" "github.com/deckhouse/virtualization-controller/api/operations/install" "github.com/deckhouse/virtualization-controller/api/operations/v1alpha1" + rest2 "github.com/deckhouse/virtualization-controller/pkg/apiserver/rest" "github.com/deckhouse/virtualization-controller/pkg/apiserver/storage" + "github.com/deckhouse/virtualization-controller/pkg/tls/certManager" ) var ( diff --git a/images/virtualization-artifact/pkg/apiserver/rest/console.go b/images/virtualization-artifact/pkg/apiserver/rest/console.go index 60c66db36..1d53ba1ba 100644 --- a/images/virtualization-artifact/pkg/apiserver/rest/console.go +++ b/images/virtualization-artifact/pkg/apiserver/rest/console.go @@ -3,20 +3,17 @@ package rest import ( "context" "fmt" - virtv2 "github.com/deckhouse/virtualization-controller/api/core/v1alpha2" - "github.com/deckhouse/virtualization-controller/api/operations" - "github.com/deckhouse/virtualization-controller/pkg/apiserver/storage" - "github.com/deckhouse/virtualization-controller/pkg/tls/certManager" - "k8s.io/apimachinery/pkg/api/errors" + "net/http" + "net/url" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apiserver/pkg/registry/rest" "k8s.io/client-go/tools/cache" - "net/http" - "net/url" -) -const consoleTemplateURI = "wss://%s/apis/subresources.kubevirt.io/v1/namespaces/%s/virtualmachine/%s/%s" + "github.com/deckhouse/virtualization-controller/api/operations" + "github.com/deckhouse/virtualization-controller/pkg/tls/certManager" +) type ConsoleREST struct { groupResource schema.GroupResource @@ -53,9 +50,6 @@ func (r ConsoleREST) New() runtime.Object { func (r ConsoleREST) Destroy() { } -func (r ConsoleREST) getFetcherVirtualMachine(name, namespace string) (*virtv2.VirtualMachine, *errors.StatusError) { - return storage.FetchVirtualMachine(r.vmLister, name, namespace) -} func (r ConsoleREST) Connect(ctx context.Context, name string, opts runtime.Object, responder rest.Responder) (http.Handler, error) { consoleOpts, ok := opts.(*operations.VirtualMachineConsole) if !ok { diff --git a/images/virtualization-artifact/pkg/apiserver/rest/stream.go b/images/virtualization-artifact/pkg/apiserver/rest/stream.go index faac126ff..2cc8636f1 100644 --- a/images/virtualization-artifact/pkg/apiserver/rest/stream.go +++ b/images/virtualization-artifact/pkg/apiserver/rest/stream.go @@ -5,18 +5,20 @@ import ( "crypto/tls" "crypto/x509" "fmt" - virtv2 "github.com/deckhouse/virtualization-controller/api/core/v1alpha2" - "github.com/deckhouse/virtualization-controller/api/operations" - "github.com/deckhouse/virtualization-controller/pkg/tls/certManager" + "net/http" + "net/url" + "os" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/proxy" "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/rest" "k8s.io/client-go/tools/cache" - "net/http" - "net/url" - "os" + + virtv2 "github.com/deckhouse/virtualization-controller/api/core/v1alpha2" + "github.com/deckhouse/virtualization-controller/api/operations" + "github.com/deckhouse/virtualization-controller/pkg/tls/certManager" ) func streamLocation( diff --git a/images/virtualization-artifact/pkg/apiserver/server/config.go b/images/virtualization-artifact/pkg/apiserver/server/config.go index b750c9bb0..df32f831f 100644 --- a/images/virtualization-artifact/pkg/apiserver/server/config.go +++ b/images/virtualization-artifact/pkg/apiserver/server/config.go @@ -3,14 +3,14 @@ package server import ( "errors" "fmt" - rest2 "github.com/deckhouse/virtualization-controller/pkg/apiserver/rest" - "github.com/deckhouse/virtualization-controller/pkg/tls/certManager/filesystem" genericapiserver "k8s.io/apiserver/pkg/server" "k8s.io/client-go/rest" virtv2 "github.com/deckhouse/virtualization-controller/api/core/v1alpha2" "github.com/deckhouse/virtualization-controller/pkg/apiserver/api" + rest2 "github.com/deckhouse/virtualization-controller/pkg/apiserver/rest" + "github.com/deckhouse/virtualization-controller/pkg/tls/certManager/filesystem" ) var ErrConfigInvalid = errors.New("configuration is invalid") diff --git a/images/virtualization-artifact/pkg/apiserver/server/server.go b/images/virtualization-artifact/pkg/apiserver/server/server.go index b02e6d7eb..c42d8404e 100644 --- a/images/virtualization-artifact/pkg/apiserver/server/server.go +++ b/images/virtualization-artifact/pkg/apiserver/server/server.go @@ -1,9 +1,10 @@ package server import ( - "github.com/deckhouse/virtualization-controller/pkg/tls/certManager" genericapiserver "k8s.io/apiserver/pkg/server" "k8s.io/client-go/tools/cache" + + "github.com/deckhouse/virtualization-controller/pkg/tls/certManager" ) func NewServer( diff --git a/images/virtualization-artifact/pkg/apiserver/storage/util.go b/images/virtualization-artifact/pkg/apiserver/storage/util.go index 732f26cf5..cfc3bbc52 100644 --- a/images/virtualization-artifact/pkg/apiserver/storage/util.go +++ b/images/virtualization-artifact/pkg/apiserver/storage/util.go @@ -1,22 +1,15 @@ package storage -import ( - "fmt" - virtv2 "github.com/deckhouse/virtualization-controller/api/core/v1alpha2" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/client-go/tools/cache" -) - -func FetchVirtualMachine(vmLister cache.GenericLister, name, namespace string) (*virtv2.VirtualMachine, *errors.StatusError) { - obj, err := vmLister.ByNamespace(namespace).Get(name) - if err != nil { - if errors.IsNotFound(err) { - return nil, errors.NewNotFound(virtv2.Resource("virtualmachine"), name) - } - return nil, errors.NewInternalError(fmt.Errorf("unable to retrieve vm [%s]: %v", name, err)) - } - if vm, ok := obj.(*virtv2.VirtualMachine); ok { - return vm, nil - } - return nil, errors.NewInternalError(fmt.Errorf("unable to retrieve vm [%s]: %v", name, err)) -} +// func FetchVirtualMachine(vmLister cache.GenericLister, name, namespace string) (*virtv2.VirtualMachine, *errors.StatusError) { +// obj, err := vmLister.ByNamespace(namespace).Get(name) +// if err != nil { +// if errors.IsNotFound(err) { +// return nil, errors.NewNotFound(virtv2.Resource("virtualmachine"), name) +// } +// return nil, errors.NewInternalError(fmt.Errorf("unable to retrieve vm [%s]: %w", name, err)) +// } +// if vm, ok := obj.(*virtv2.VirtualMachine); ok { +// return vm, nil +// } +// return nil, errors.NewInternalError(fmt.Errorf("unable to retrieve vm [%s]: %w", name, err)) +//} diff --git a/images/virtualization-artifact/pkg/config/load_kubevirt_apiserver_settings.go b/images/virtualization-artifact/pkg/config/load_kubevirt_apiserver_settings.go index 82e092a71..99fbcb6b3 100644 --- a/images/virtualization-artifact/pkg/config/load_kubevirt_apiserver_settings.go +++ b/images/virtualization-artifact/pkg/config/load_kubevirt_apiserver_settings.go @@ -1,9 +1,9 @@ package config import ( - "github.com/deckhouse/virtualization-controller/pkg/apiserver/rest" "os" + "github.com/deckhouse/virtualization-controller/pkg/apiserver/rest" "github.com/deckhouse/virtualization-controller/pkg/common" ) diff --git a/images/virtualization-artifact/pkg/tls/certManager/filesystem/file-cert-manager.go b/images/virtualization-artifact/pkg/tls/certManager/filesystem/file-cert-manager.go index c764f9f0c..13d473fbf 100644 --- a/images/virtualization-artifact/pkg/tls/certManager/filesystem/file-cert-manager.go +++ b/images/virtualization-artifact/pkg/tls/certManager/filesystem/file-cert-manager.go @@ -3,13 +3,15 @@ package filesystem import ( "crypto/tls" "fmt" - "github.com/deckhouse/virtualization-controller/pkg/tls/util" - "github.com/fsnotify/fsnotify" - "k8s.io/klog/v2" "os" "path/filepath" "sync" "time" + + "github.com/fsnotify/fsnotify" + "k8s.io/klog/v2" + + "github.com/deckhouse/virtualization-controller/pkg/tls/util" ) type FileCertificateManager struct { @@ -22,7 +24,7 @@ type FileCertificateManager struct { errorRetryInterval time.Duration } -func NewFileCertificateManager(certBytesPath string, keyBytesPath string) *FileCertificateManager { +func NewFileCertificateManager(certBytesPath, keyBytesPath string) *FileCertificateManager { return &FileCertificateManager{ certBytesPath: certBytesPath, keyBytesPath: keyBytesPath, @@ -109,7 +111,7 @@ func (f *FileCertificateManager) Stop() { func (f *FileCertificateManager) rotateCerts() error { crt, err := f.loadCertificates() if err != nil { - return fmt.Errorf("failed to load the certificate %s and %s", f.certBytesPath, f.keyBytesPath) + return fmt.Errorf("failed to load the certificate %s and %s: %w", f.certBytesPath, f.keyBytesPath, err) } f.certAccessLock.Lock() @@ -134,12 +136,12 @@ func (f *FileCertificateManager) loadCertificates() (serverCrt *tls.Certificate, crt, err := tls.X509KeyPair(certBytes, keyBytes) if err != nil { - return nil, fmt.Errorf("failed to load certificate: %v\n", err) + return nil, fmt.Errorf("failed to load certificate: %w\n", err) } leaf, err := util.ParseCertsPEM(certBytes) if err != nil { - return nil, fmt.Errorf("failed to load leaf certificate: %v\n", err) + return nil, fmt.Errorf("failed to load leaf certificate: %w\n", err) } crt.Leaf = leaf[0] return &crt, nil