Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
Signed-off-by: Yaroslav Borbat <[email protected]>
  • Loading branch information
yaroslavborbat committed Mar 5, 2024
1 parent 415bdfb commit 15fae64
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 54 deletions.
3 changes: 2 additions & 1 deletion images/virtualization-artifact/api/operations/register.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package options

import (
"fmt"
rest2 "github.com/deckhouse/virtualization-controller/pkg/apiserver/rest"
"net"
"strings"

Expand All @@ -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"
)
Expand Down
4 changes: 2 additions & 2 deletions images/virtualization-artifact/pkg/apiserver/api/install.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 (
Expand Down
18 changes: 6 additions & 12 deletions images/virtualization-artifact/pkg/apiserver/rest/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 8 additions & 6 deletions images/virtualization-artifact/pkg/apiserver/rest/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions images/virtualization-artifact/pkg/apiserver/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
33 changes: 13 additions & 20 deletions images/virtualization-artifact/pkg/apiserver/storage/util.go
Original file line number Diff line number Diff line change
@@ -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))
//}
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit 15fae64

Please sign in to comment.