Skip to content

Commit fcde8a5

Browse files
committed
Refactor small sections of code and tests
1 parent 4be6382 commit fcde8a5

22 files changed

+93
-105
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,6 @@ init-buildx:
129129

130130
test-integration:
131131
go test -v -timeout 100m sigs.k8s.io/ibm-powervs-block-csi-driver/tests/it -run ^TestIntegration$
132+
133+
test-e2e:
134+
go test -v -timeout 100m sigs.k8s.io/ibm-powervs-block-csi-driver/tests/e2e -run ^TestE2E$

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Please see the compatibility matrix above before you deploy the driver
7676

7777
To deploy the CSI driver:
7878
```sh
79-
kubectl apply -k "https://github.com/kubernetes-sigs/ibm-powervs-block-csi-driver/deploy/kubernetes/overlays/stable/?ref=v0.3.0"
79+
kubectl apply -k "https://github.com/kubernetes-sigs/ibm-powervs-block-csi-driver/deploy/kubernetes/overlays/stable/?ref=v0.6.0"
8080
```
8181

8282
Verify driver is running:
@@ -87,7 +87,7 @@ kubectl get pods -n kube-system
8787
#### Deploy driver with debug mode
8888
To view driver debug logs, run the CSI driver with `-v=5` command line option
8989

90-
To enable powervs debug logs, run the CSI driver with `debug=true` command line option.
90+
To enable PowerVS debug logs, run the CSI driver with `-debug=true` command line option.
9191

9292
## Examples
9393
Make sure you follow the [Prerequisites](README.md#Prerequisites) before the examples:

adhoc-controllers/controllers/nodeupdate_controller.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"fmt"
2222

23-
"github.com/pkg/errors"
2423
corev1 "k8s.io/api/core/v1"
2524
apierrors "k8s.io/apimachinery/pkg/api/errors"
2625
"k8s.io/apimachinery/pkg/runtime"
@@ -63,7 +62,7 @@ func (r *NodeUpdateReconciler) Reconcile(_ context.Context, req ctrl.Request) (c
6362
klog.Infof("PROVIDER-ID: %s", node.Spec.ProviderID)
6463
metadata, err := cloud.TokenizeProviderID(node.Spec.ProviderID)
6564
if err != nil {
66-
return ctrl.Result{}, fmt.Errorf("failed to tokenize the providerID and err: %v", err)
65+
return ctrl.Result{}, fmt.Errorf("failed to tokenize the providerID. err: %v", err)
6766
}
6867

6968
nodeUpdateScope, err := cloud.NewNodeUpdateScope(cloud.NodeUpdateScopeParams{
@@ -73,12 +72,12 @@ func (r *NodeUpdateReconciler) Reconcile(_ context.Context, req ctrl.Request) (c
7372
})
7473

7574
if err != nil {
76-
return ctrl.Result{}, errors.Errorf("failed to create nodeUpdateScope: %+v", err)
75+
return ctrl.Result{}, fmt.Errorf("failed to create nodeUpdateScope: %w", err)
7776
}
7877

7978
instance, err := nodeUpdateScope.Cloud.GetPVMInstanceDetails(nodeUpdateScope.InstanceId)
8079
if err != nil {
81-
klog.Infof("Unable to fetch Instance Details %v", err)
80+
klog.Errorf("unable to fetch instance details. err: %v", err)
8281
return ctrl.Result{}, nil
8382
}
8483

@@ -92,8 +91,8 @@ func (r *NodeUpdateReconciler) Reconcile(_ context.Context, req ctrl.Request) (c
9291
} else {
9392
err := r.getOrUpdate(nodeUpdateScope)
9493
if err != nil {
95-
klog.Infof("unable to update instance StoragePoolAffinity %v", err)
96-
return ctrl.Result{}, errors.Wrapf(err, "failed to reconcile VSI for IBMPowerVSMachine %s/%s", node.Namespace, node.Name)
94+
klog.Errorf("unable to update instance StoragePoolAffinity. err: %v", err)
95+
return ctrl.Result{}, fmt.Errorf("failed to reconcile VSI for IBMPowerVSMachine %s/%s. err: %w", node.Namespace, node.Name, err)
9796
}
9897
}
9998
default:
@@ -107,10 +106,7 @@ func (r *NodeUpdateReconciler) Reconcile(_ context.Context, req ctrl.Request) (c
107106
}
108107

109108
func (r *NodeUpdateReconciler) getOrUpdate(scope *cloud.NodeUpdateScope) error {
110-
if err := scope.Cloud.UpdateStoragePoolAffinity(scope.InstanceId); err != nil {
111-
return err
112-
}
113-
return nil
109+
return scope.Cloud.UpdateStoragePoolAffinity(scope.InstanceId)
114110
}
115111

116112
// SetupWithManager sets up the controller with the Manager.

adhoc-controllers/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ func init() {
4949
}
5050

5151
func main() {
52-
var metricsAddr string
53-
var enableLeaderElection bool
54-
var probeAddr string
55-
var webhookPort int
52+
var (
53+
metricsAddr, probeAddr string
54+
enableLeaderElection bool
55+
webhookPort int
56+
)
5657

5758
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8081", "The address the metric endpoint binds to.")
5859
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8082", "The address the probe endpoint binds to.")

cmd/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ func main() {
3939
driver.WithCloudConfig(options.ServerOptions.Cloudconfig),
4040
)
4141
if err != nil {
42-
klog.Fatalln(err)
42+
klog.Fatalf("unable to create CSI driver. err: %v", err)
4343
}
4444
if err := drv.Run(); err != nil {
45-
klog.Fatalln(err)
45+
klog.Fatalf("failed to run the CSI driver. err: %v", err)
4646
}
4747
}

cmd/options.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ func GetOptions(fs *flag.FlagSet) *Options {
8989
}
9090

9191
if err := fs.Parse(args); err != nil {
92-
klog.Fatal(err)
92+
klog.Fatalf("Error while parsing flag options. err: %v", err)
9393
}
9494

9595
if *version {
9696
info, err := driver.GetVersionJSON()
9797
if err != nil {
98-
klog.Fatalln(err)
98+
klog.Fatalf("error while retriving the CSI driver version. err: %v", err)
9999
}
100-
klog.Infoln(info)
100+
klog.Info(info)
101101
osExit(0)
102102
}
103103

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ require (
1212
github.com/kubernetes-csi/csi-test v2.2.0+incompatible
1313
github.com/onsi/ginkgo/v2 v2.19.0
1414
github.com/onsi/gomega v1.33.1
15-
github.com/pkg/errors v0.9.1
1615
go.uber.org/mock v0.4.0
1716
golang.org/x/sys v0.22.0
1817
google.golang.org/grpc v1.65.0
@@ -95,6 +94,7 @@ require (
9594
github.com/opencontainers/go-digest v1.0.0 // indirect
9695
github.com/opencontainers/selinux v1.11.0 // indirect
9796
github.com/opentracing/opentracing-go v1.2.0 // indirect
97+
github.com/pkg/errors v0.9.1 // indirect
9898
github.com/prometheus/client_golang v1.17.0 // indirect
9999
github.com/prometheus/client_model v0.6.1 // indirect
100100
github.com/prometheus/common v0.44.0 // indirect

pkg/cloud/cloud_interface.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
type Cloud interface {
2424
CreateDisk(volumeName string, diskOptions *DiskOptions) (disk *Disk, err error)
25-
DeleteDisk(volumeID string) (success bool, err error)
25+
DeleteDisk(volumeID string) (err error)
2626
AttachDisk(volumeID string, nodeID string) (err error)
2727
DetachDisk(volumeID string, nodeID string) (err error)
2828
ResizeDisk(volumeID string, reqSize int64) (newSize int64, err error)
@@ -33,5 +33,5 @@ type Cloud interface {
3333
GetPVMInstanceByID(instanceID string) (instance *PVMInstance, err error)
3434
GetPVMInstanceDetails(instanceID string) (*models.PVMInstance, error)
3535
UpdateStoragePoolAffinity(instanceID string) error
36-
IsAttached(volumeID string, nodeID string) (attached bool, err error)
36+
IsAttached(volumeID string, nodeID string) (err error)
3737
}

pkg/cloud/metadata.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ func TokenizeProviderID(providerID string) (*Metadata, error) {
8787

8888
// Get New Metadata Service
8989
func NewMetadataService(k8sAPIClient KubernetesAPIClient, kubeconfig string) (MetadataService, error) {
90-
klog.Infof("retrieving instance data from kubernetes API")
90+
klog.Info("Retrieving instance data from Kubernetes API")
9191
clientset, err := k8sAPIClient(kubeconfig)
9292
if err != nil {
93-
klog.Warningf("error creating kubernetes api client: %v", err)
93+
klog.Errorf("error creating Kubernetes API client: %v", err)
9494
return nil, fmt.Errorf("an error occured during creation of k8s API client: %w", err)
9595
}
9696
klog.Info("kubernetes API is available")

pkg/cloud/mocks/mock_cloud.go

Lines changed: 6 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)