Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
Signed-off-by: Xudong Liu <[email protected]>
  • Loading branch information
XudongLiuHarold committed Jan 30, 2024
1 parent 37441be commit 753b98b
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pkg/cloudprovider/vsphereparavirtual/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
)

type instances struct {
vmClient vmop.VmoperatorV1alpha1Interface
vmClient vmop.V1alpha1Interface
namespace string
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/cloudprovider/vsphereparavirtual/vmoperator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// discoverNodeByProviderID takes a ProviderID and returns a VirtualMachine if one exists, or nil otherwise
// VirtualMachine not found is not an error
func discoverNodeByProviderID(ctx context.Context, providerID string, namespace string, vmClient vmop.VmoperatorV1alpha1Interface) (*vmopv1alpha1.VirtualMachine, error) {
func discoverNodeByProviderID(ctx context.Context, providerID string, namespace string, vmClient vmop.V1alpha1Interface) (*vmopv1alpha1.VirtualMachine, error) {
var discoveredNode *vmopv1alpha1.VirtualMachine = nil

// Adding Retry here because there is no retry in caller from node controller
Expand Down Expand Up @@ -44,7 +44,7 @@ func discoverNodeByProviderID(ctx context.Context, providerID string, namespace

// discoverNodeByName takes a node name and returns a VirtualMachine if one exists, or nil otherwise
// VirtualMachine not found is not an error
func discoverNodeByName(ctx context.Context, name types.NodeName, namespace string, vmClient vmop.VmoperatorV1alpha1Interface) (*vmopv1alpha1.VirtualMachine, error) {
func discoverNodeByName(ctx context.Context, name types.NodeName, namespace string, vmClient vmop.V1alpha1Interface) (*vmopv1alpha1.VirtualMachine, error) {
var discoveredNode *vmopv1alpha1.VirtualMachine = nil

// Adding Retry here because there is no retry in caller from node controller
Expand Down
20 changes: 13 additions & 7 deletions pkg/cloudprovider/vsphereparavirtual/vmoperator/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,45 @@ import (
)

var (
// VirtualMachineServiceGVR has virtualmachineservice resource info.
VirtualMachineServiceGVR = schema.GroupVersionResource{
Group: "vmoperator.vmware.com",
Version: "v1alpha1",
Resource: "virtualmachineservices",
}

// VirtualMachineGVR has virtualmachine resource info.
VirtualMachineGVR = schema.GroupVersionResource{
Group: "vmoperator.vmware.com",
Version: "v1alpha1",
Resource: "virtualmachines",
}
)

type VmoperatorV1alpha1Client struct {
// vmoperatorV1alpha1Client contains the dynamic client for vm operator group
type vmoperatorV1alpha1Client struct {
dynamicClient *dynamic.DynamicClient
}

func (c *VmoperatorV1alpha1Client) VirtualMachines(namespace string) vmoperator.VirtualMachineInterface {
// VirtualMachines retrieves the virtualmachine client
func (c *vmoperatorV1alpha1Client) VirtualMachines(namespace string) vmoperator.VirtualMachineInterface {
return newVirtualMachines(c, namespace)
}

func (c *VmoperatorV1alpha1Client) VirtualMachineServices(namespace string) vmoperator.VirtualMachineServiceInterface {
// VirtualMachineServices retrieves the virtualmachineservice client
func (c *vmoperatorV1alpha1Client) VirtualMachineServices(namespace string) vmoperator.VirtualMachineServiceInterface {
return newVirtualMachineServices(c, namespace)
}

func (c *VmoperatorV1alpha1Client) Client() dynamic.Interface {
// Client retrieves the dynamic client
func (c *vmoperatorV1alpha1Client) Client() dynamic.Interface {
if c == nil {
return nil
}
return c.dynamicClient
}

func NewForConfig(c *rest.Config) (*VmoperatorV1alpha1Client, error) {
// NewForConfig creates a new client for the given config.
func NewForConfig(c *rest.Config) (*vmoperatorV1alpha1Client, error) {
scheme := runtime.NewScheme()
_ = vmopv1alpha1.AddToScheme(scheme)

Expand All @@ -53,7 +59,7 @@ func NewForConfig(c *rest.Config) (*VmoperatorV1alpha1Client, error) {
return nil, err
}

client := &VmoperatorV1alpha1Client{
client := &vmoperatorV1alpha1Client{
dynamicClient: dynamicClient,
}
return client, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,29 @@ import (
"k8s.io/cloud-provider-vsphere/pkg/cloudprovider/vsphereparavirtual/vmoperator"
)

// FakeClient contains the fake dynamic client for vm operator group
type FakeClient struct {
DynamicClient *dynamicfake.FakeDynamicClient
}

// NewFakeClientWrapper creates a FakeClientWrapper
// NewFakeClient creates a FakeClientWrapper
func NewFakeClient(fakeClient *dynamicfake.FakeDynamicClient) *FakeClient {
fcw := FakeClient{}
fcw.DynamicClient = fakeClient
return &fcw
}

// VirtualMachines retrieves the virtualmachine client
func (c *FakeClient) VirtualMachines(namespace string) vmoperator.VirtualMachineInterface {
return newVirtualMachines(c, namespace)
}

// VirtualMachineServices retrieves the virtualmachineservice client
func (c *FakeClient) VirtualMachineServices(namespace string) vmoperator.VirtualMachineServiceInterface {
return newVirtualMachineServices(c, namespace)
}

// Client retrieves the dynamic client
func (c *FakeClient) Client() dynamic.Interface {
if c == nil {
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type virtualMachines struct {
ns string
}

func newVirtualMachines(c vmoperator.VmoperatorV1alpha1Interface, namespace string) *virtualMachines {
func newVirtualMachines(c vmoperator.V1alpha1Interface, namespace string) *virtualMachines {
return &virtualMachines{
client: c.Client(),
ns: namespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type virtualMachineServices struct {
}

// newVirtualMachineServices returns a VirtualMachineServices
func newVirtualMachineServices(c vmoperator.VmoperatorV1alpha1Interface, namespace string) *virtualMachineServices {
func newVirtualMachineServices(c vmoperator.V1alpha1Interface, namespace string) *virtualMachineServices {
return &virtualMachineServices{
client: c.Client(),
ns: namespace,
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloudprovider/vsphereparavirtual/vmoperator/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
vmopv1alpha1 "github.com/vmware-tanzu/vm-operator-api/api/v1alpha1"
)

// VmoperatorV1alpha1Interface has methods to work with Vmoperator V1alpha1 resources.
type VmoperatorV1alpha1Interface interface {
// V1alpha1Interface has methods to work with Vmoperator V1alpha1 resources.
type V1alpha1Interface interface {
Client() dynamic.Interface
VirtualMachines(namespace string) VirtualMachineInterface
VirtualMachineServices(namespace string) VirtualMachineServiceInterface
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/vsphereparavirtual/vmservice/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type VMService interface {

// vmService takes care of mapping of LB type of service to VM service in supervisor cluster
type vmService struct {
vmClient vmop.VmoperatorV1alpha1Interface
vmClient vmop.V1alpha1Interface
namespace string
ownerReference *metav1.OwnerReference
}
4 changes: 2 additions & 2 deletions pkg/cloudprovider/vsphereparavirtual/vmservice/vmservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ var (

// GetVmopClient gets a vm-operator-api client
// This is separate from NewVMService so that a fake client can be injected for testing
func GetVmopClient(config *rest.Config) (vmop.VmoperatorV1alpha1Interface, error) {
func GetVmopClient(config *rest.Config) (vmop.V1alpha1Interface, error) {
return vmopclient.NewForConfig(config)
}

// NewVMService creates a vmService object
func NewVMService(vmClient vmop.VmoperatorV1alpha1Interface, ns string, ownerRef *metav1.OwnerReference) VMService {
func NewVMService(vmClient vmop.V1alpha1Interface, ns string, ownerRef *metav1.OwnerReference) VMService {
return &vmService{
vmClient: vmClient,
namespace: ns,
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/vsphereparavirtual/zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

type zones struct {
vmClient vmop.VmoperatorV1alpha1Interface
vmClient vmop.V1alpha1Interface
namespace string
}

Expand Down

0 comments on commit 753b98b

Please sign in to comment.