Skip to content

Commit fe2f103

Browse files
Merge pull request #33 from aws/fix/add_golint_fix_lint_errors
Fix/add golint fix lint errors
2 parents 43c84d3 + ba6ca8f commit fe2f103

25 files changed

+214
-212
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ linters:
2222
enable:
2323
- gosec
2424
- goheader
25+
- revive
2526

2627
run:
2728
issues-exit-code: 1

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ vet: ## Run go vet on the whole project.
109109
go vet ./...
110110

111111
.PHONY: lint
112-
lint: bin/golangci-lint ## Run linting for the project.
112+
lint: bin/golangci-lint generate-mocks ## Run linting for the project.
113113
go fmt ./...
114114
go vet ./...
115115
golangci-lint run -v --timeout 360s ./...

api/v1beta1/cloudstackcluster_webhook.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package v1beta1
1919
import (
2020
"fmt"
2121

22-
"github.com/aws/cluster-api-provider-cloudstack/pkg/webhook_utilities"
22+
"github.com/aws/cluster-api-provider-cloudstack/pkg/webhookutil"
2323
"k8s.io/apimachinery/pkg/api/errors"
2424
"k8s.io/apimachinery/pkg/runtime"
2525
"k8s.io/apimachinery/pkg/util/validation/field"
@@ -67,10 +67,10 @@ func (r *CloudStackCluster) ValidateCreate() error {
6767
}
6868

6969
// Zone and Network are required fields
70-
errorList = webhook_utilities.EnsureFieldExists(r.Spec.Zone, "Zone", errorList)
71-
errorList = webhook_utilities.EnsureFieldExists(r.Spec.Network, "Network", errorList)
70+
errorList = webhookutil.EnsureFieldExists(r.Spec.Zone, "Zone", errorList)
71+
errorList = webhookutil.EnsureFieldExists(r.Spec.Network, "Network", errorList)
7272

73-
return webhook_utilities.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
73+
return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
7474
}
7575

7676
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
@@ -94,20 +94,20 @@ func (r *CloudStackCluster) ValidateUpdate(old runtime.Object) error {
9494
}
9595

9696
// No spec fields may be changed
97-
errorList = webhook_utilities.EnsureStringFieldsAreEqual(spec.Zone, oldSpec.Zone, "zone", errorList)
98-
errorList = webhook_utilities.EnsureStringFieldsAreEqual(spec.Network, oldSpec.Network, "network", errorList)
97+
errorList = webhookutil.EnsureStringFieldsAreEqual(spec.Zone, oldSpec.Zone, "zone", errorList)
98+
errorList = webhookutil.EnsureStringFieldsAreEqual(spec.Network, oldSpec.Network, "network", errorList)
9999
if oldSpec.ControlPlaneEndpoint.Host != "" { // Need to allow one time endpoint setting via CAPC cluster controller.
100-
errorList = webhook_utilities.EnsureStringFieldsAreEqual(
100+
errorList = webhookutil.EnsureStringFieldsAreEqual(
101101
spec.ControlPlaneEndpoint.Host, oldSpec.ControlPlaneEndpoint.Host, "controlplaneendpointhost", errorList)
102-
errorList = webhook_utilities.EnsureStringFieldsAreEqual(
102+
errorList = webhookutil.EnsureStringFieldsAreEqual(
103103
string(spec.ControlPlaneEndpoint.Port), string(oldSpec.ControlPlaneEndpoint.Port), "controlplaneendpointport", errorList)
104104
}
105105
if spec.IdentityRef != nil && oldSpec.IdentityRef != nil {
106-
errorList = webhook_utilities.EnsureStringFieldsAreEqual(spec.IdentityRef.Kind, oldSpec.IdentityRef.Kind, "identityRef.Kind", errorList)
107-
errorList = webhook_utilities.EnsureStringFieldsAreEqual(spec.IdentityRef.Name, oldSpec.IdentityRef.Name, "identityRef.Name", errorList)
106+
errorList = webhookutil.EnsureStringFieldsAreEqual(spec.IdentityRef.Kind, oldSpec.IdentityRef.Kind, "identityRef.Kind", errorList)
107+
errorList = webhookutil.EnsureStringFieldsAreEqual(spec.IdentityRef.Name, oldSpec.IdentityRef.Name, "identityRef.Name", errorList)
108108
}
109109

110-
return webhook_utilities.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
110+
return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
111111
}
112112

113113
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type

api/v1beta1/cloudstackcluster_webhook_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var _ = Describe("CloudStackCluster webhooks", func() {
3131
clusterKind = "CloudStackCluster"
3232
clusterName = "test-cluster"
3333
clusterNamespace = "default"
34-
clusterId = "0"
34+
clusterID = "0"
3535
identitySecretName = "IdentitySecret"
3636
zone = "Zone"
3737
network = "Network"
@@ -48,7 +48,7 @@ var _ = Describe("CloudStackCluster webhooks", func() {
4848
ObjectMeta: metav1.ObjectMeta{
4949
Name: clusterName,
5050
Namespace: clusterNamespace,
51-
UID: clusterId,
51+
UID: clusterID,
5252
},
5353
Spec: CloudStackClusterSpec{
5454
IdentityRef: &CloudStackIdentityReference{
@@ -74,7 +74,7 @@ var _ = Describe("CloudStackCluster webhooks", func() {
7474
ObjectMeta: metav1.ObjectMeta{
7575
Name: clusterName,
7676
Namespace: clusterNamespace,
77-
UID: clusterId,
77+
UID: clusterID,
7878
},
7979
Spec: CloudStackClusterSpec{
8080
IdentityRef: &CloudStackIdentityReference{
@@ -99,7 +99,7 @@ var _ = Describe("CloudStackCluster webhooks", func() {
9999
ObjectMeta: metav1.ObjectMeta{
100100
Name: clusterName,
101101
Namespace: clusterNamespace,
102-
UID: clusterId,
102+
UID: clusterID,
103103
},
104104
Spec: CloudStackClusterSpec{
105105
IdentityRef: &CloudStackIdentityReference{
@@ -129,7 +129,7 @@ var _ = Describe("CloudStackCluster webhooks", func() {
129129
ObjectMeta: metav1.ObjectMeta{
130130
Name: clusterName,
131131
Namespace: clusterNamespace,
132-
UID: clusterId,
132+
UID: clusterID,
133133
},
134134
Spec: CloudStackClusterSpec{
135135
IdentityRef: &CloudStackIdentityReference{

api/v1beta1/cloudstackmachine_webhook.go

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

23-
"github.com/aws/cluster-api-provider-cloudstack/pkg/webhook_utilities"
23+
"github.com/aws/cluster-api-provider-cloudstack/pkg/webhookutil"
2424
"k8s.io/apimachinery/pkg/api/errors"
2525
"k8s.io/apimachinery/pkg/runtime"
2626
"k8s.io/apimachinery/pkg/util/validation/field"
@@ -63,10 +63,10 @@ func (r *CloudStackMachine) ValidateCreate() error {
6363
errorList = append(errorList, field.Forbidden(field.NewPath("spec", "identityRef", "kind"), "must be a Secret"))
6464
}
6565

66-
errorList = webhook_utilities.EnsureFieldExists(r.Spec.Offering, "Offering", errorList)
67-
errorList = webhook_utilities.EnsureFieldExists(r.Spec.Template, "Template", errorList)
66+
errorList = webhookutil.EnsureFieldExists(r.Spec.Offering, "Offering", errorList)
67+
errorList = webhookutil.EnsureFieldExists(r.Spec.Template, "Template", errorList)
6868

69-
return webhook_utilities.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
69+
return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
7070
}
7171

7272
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
@@ -81,23 +81,23 @@ func (r *CloudStackMachine) ValidateUpdate(old runtime.Object) error {
8181
}
8282
oldSpec := oldMachine.Spec
8383

84-
errorList = webhook_utilities.EnsureStringFieldsAreEqual(r.Spec.Offering, oldSpec.Offering, "offering", errorList)
85-
errorList = webhook_utilities.EnsureStringFieldsAreEqual(r.Spec.SSHKey, oldSpec.SSHKey, "sshkey", errorList)
86-
errorList = webhook_utilities.EnsureStringFieldsAreEqual(r.Spec.Template, oldSpec.Template, "template", errorList)
87-
errorList = webhook_utilities.EnsureStringStringMapFieldsAreEqual(&r.Spec.Details, &oldSpec.Details, "details", errorList)
84+
errorList = webhookutil.EnsureStringFieldsAreEqual(r.Spec.Offering, oldSpec.Offering, "offering", errorList)
85+
errorList = webhookutil.EnsureStringFieldsAreEqual(r.Spec.SSHKey, oldSpec.SSHKey, "sshkey", errorList)
86+
errorList = webhookutil.EnsureStringFieldsAreEqual(r.Spec.Template, oldSpec.Template, "template", errorList)
87+
errorList = webhookutil.EnsureStringStringMapFieldsAreEqual(&r.Spec.Details, &oldSpec.Details, "details", errorList)
8888
if r.Spec.IdentityRef != nil && oldSpec.IdentityRef != nil {
89-
errorList = webhook_utilities.EnsureStringFieldsAreEqual(
89+
errorList = webhookutil.EnsureStringFieldsAreEqual(
9090
r.Spec.IdentityRef.Kind, oldSpec.IdentityRef.Kind, "identityRef.Kind", errorList)
91-
errorList = webhook_utilities.EnsureStringFieldsAreEqual(
91+
errorList = webhookutil.EnsureStringFieldsAreEqual(
9292
r.Spec.IdentityRef.Name, oldSpec.IdentityRef.Name, "identityRef.Name", errorList)
9393
}
94-
errorList = webhook_utilities.EnsureStringFieldsAreEqual(r.Spec.Affinity, oldSpec.Affinity, "affinity", errorList)
94+
errorList = webhookutil.EnsureStringFieldsAreEqual(r.Spec.Affinity, oldSpec.Affinity, "affinity", errorList)
9595

9696
if !reflect.DeepEqual(r.Spec.AffinityGroupIds, oldSpec.AffinityGroupIds) { // Equivalent to other Ensure funcs.
9797
errorList = append(errorList, field.Forbidden(field.NewPath("spec", "AffinityGroupIds"), "AffinityGroupIds"))
9898
}
9999

100-
return webhook_utilities.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
100+
return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
101101
}
102102

103103
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type

api/v1beta1/cloudstackmachinetemplate_webhook.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"reflect"
2222
"strings"
2323

24-
"github.com/aws/cluster-api-provider-cloudstack/pkg/webhook_utilities"
24+
"github.com/aws/cluster-api-provider-cloudstack/pkg/webhookutil"
2525
"k8s.io/apimachinery/pkg/api/errors"
2626
"k8s.io/apimachinery/pkg/runtime"
2727
"k8s.io/apimachinery/pkg/util/validation/field"
@@ -76,10 +76,10 @@ func (r *CloudStackMachineTemplate) ValidateCreate() error {
7676
"AffinityGroupIds cannot be specified when Affinity is specified as anything but `no`"))
7777
}
7878

79-
errorList = webhook_utilities.EnsureFieldExists(spec.Offering, "Offering", errorList)
80-
errorList = webhook_utilities.EnsureFieldExists(spec.Template, "Template", errorList)
79+
errorList = webhookutil.EnsureFieldExists(spec.Offering, "Offering", errorList)
80+
errorList = webhookutil.EnsureFieldExists(spec.Template, "Template", errorList)
8181

82-
return webhook_utilities.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
82+
return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
8383
}
8484

8585
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
@@ -97,25 +97,25 @@ func (r *CloudStackMachineTemplate) ValidateUpdate(old runtime.Object) error {
9797
}
9898
oldSpec := oldMachineTemplate.Spec.Spec.Spec
9999

100-
errorList = webhook_utilities.EnsureStringFieldsAreEqual(spec.Offering, oldSpec.Offering, "offering", errorList)
101-
errorList = webhook_utilities.EnsureStringFieldsAreEqual(spec.SSHKey, oldSpec.SSHKey, "sshkey", errorList)
102-
errorList = webhook_utilities.EnsureStringFieldsAreEqual(spec.Template, oldSpec.Template, "template", errorList)
103-
errorList = webhook_utilities.EnsureStringStringMapFieldsAreEqual(&spec.Details, &oldSpec.Details, "details", errorList)
100+
errorList = webhookutil.EnsureStringFieldsAreEqual(spec.Offering, oldSpec.Offering, "offering", errorList)
101+
errorList = webhookutil.EnsureStringFieldsAreEqual(spec.SSHKey, oldSpec.SSHKey, "sshkey", errorList)
102+
errorList = webhookutil.EnsureStringFieldsAreEqual(spec.Template, oldSpec.Template, "template", errorList)
103+
errorList = webhookutil.EnsureStringStringMapFieldsAreEqual(&spec.Details, &oldSpec.Details, "details", errorList)
104104

105-
errorList = webhook_utilities.EnsureStringFieldsAreEqual(spec.Affinity, oldSpec.Affinity, "affinity", errorList)
105+
errorList = webhookutil.EnsureStringFieldsAreEqual(spec.Affinity, oldSpec.Affinity, "affinity", errorList)
106106

107107
if !reflect.DeepEqual(spec.AffinityGroupIds, oldSpec.AffinityGroupIds) { // Equivalent to other Ensure funcs.
108108
errorList = append(errorList, field.Forbidden(field.NewPath("spec", "AffinityGroupIds"), "AffinityGroupIds"))
109109
}
110110

111111
if spec.IdentityRef != nil && oldSpec.IdentityRef != nil {
112-
errorList = webhook_utilities.EnsureStringFieldsAreEqual(
112+
errorList = webhookutil.EnsureStringFieldsAreEqual(
113113
spec.IdentityRef.Kind, oldSpec.IdentityRef.Kind, "identityRef.Kind", errorList)
114-
errorList = webhook_utilities.EnsureStringFieldsAreEqual(
114+
errorList = webhookutil.EnsureStringFieldsAreEqual(
115115
spec.IdentityRef.Name, oldSpec.IdentityRef.Name, "identityRef.Name", errorList)
116116
}
117117

118-
return webhook_utilities.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
118+
return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
119119
}
120120

121121
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type

api/v1beta1/groupversion_info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// package v1beta1 contains API Schema definitions for the infrastructure v1beta1 API group
17+
// Package v1beta1 contains API Schema definitions for the infrastructure v1beta1 API group
1818
//+kubebuilder:object:generate=true
1919
//+groupName=infrastructure.cluster.x-k8s.io
2020
package v1beta1

config/webhook/manifests.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
---
23
apiVersion: admissionregistration.k8s.io/v1
34
kind: MutatingWebhookConfiguration
@@ -45,6 +46,7 @@ webhooks:
4546
resources:
4647
- cloudstackmachines
4748
sideEffects: None
49+
4850
---
4951
apiVersion: admissionregistration.k8s.io/v1
5052
kind: ValidatingWebhookConfiguration

controllers/cloudstackcluster_controller.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,17 @@ func (r *CloudStackClusterReconciler) Reconcile(ctx context.Context, req ctrl.Re
9494
}
9595

9696
// Setup patcher. This ensures modifications to the csCluster copy fetched above are patched into the origin.
97-
if patchHelper, err := patch.NewHelper(csCluster, r.Client); err != nil {
97+
patchHelper, err := patch.NewHelper(csCluster, r.Client)
98+
if err != nil {
9899
return ctrl.Result{}, err
99-
} else {
100-
defer func() {
101-
if err = patchHelper.Patch(ctx, csCluster); err != nil {
102-
msg := "error patching CloudStackCluster %s/%s"
103-
err = errors.Wrapf(err, msg, csCluster.Namespace, csCluster.Name)
104-
retErr = multierror.Append(retErr, err)
105-
}
106-
}()
107100
}
101+
defer func() {
102+
if err = patchHelper.Patch(ctx, csCluster); err != nil {
103+
msg := "error patching CloudStackCluster %s/%s"
104+
err = errors.Wrapf(err, msg, csCluster.Namespace, csCluster.Name)
105+
retErr = multierror.Append(retErr, err)
106+
}
107+
}()
108108

109109
// Delete Cluster Resources if deletion timestamp present.
110110
if !csCluster.DeletionTimestamp.IsZero() {

controllers/cloudstackmachine_controller.go

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type CloudStackMachineReconciler struct {
5454
CS cloud.Client
5555
}
5656

57-
const RequeueTimeout = 5 * time.Second
57+
const requeueTimeout = 5 * time.Second
5858

5959
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=cloudstackmachines,verbs=get;list;watch;create;update;patch;delete
6060
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=cloudstackmachines/status,verbs=get;update;patch
@@ -82,32 +82,32 @@ func (r *CloudStackMachineReconciler) Reconcile(ctx context.Context, req ctrl.Re
8282
}
8383

8484
// Setup patcher. This ensures modifications to the csMachine copy fetched above are patched into the origin.
85-
if patchHelper, err := patch.NewHelper(csMachine, r.Client); err != nil {
85+
patchHelper, err := patch.NewHelper(csMachine, r.Client)
86+
if err != nil {
8687
return ctrl.Result{}, err
87-
} else {
88-
defer func() { // If there was no error on return, but the patch fails, set the error accordingly.
89-
if err = patchHelper.Patch(ctx, csMachine); err != nil {
90-
msg := "error patching CloudStackMachine %s/%s"
91-
err = errors.Wrapf(err, msg, csMachine.Namespace, csMachine.Name)
92-
retErr = multierror.Append(retErr, err)
93-
}
94-
}()
9588
}
89+
defer func() { // If there was no error on return, but the patch fails, set the error accordingly.
90+
if err = patchHelper.Patch(ctx, csMachine); err != nil {
91+
msg := "error patching CloudStackMachine %s/%s"
92+
err = errors.Wrapf(err, msg, csMachine.Namespace, csMachine.Name)
93+
retErr = multierror.Append(retErr, err)
94+
}
95+
}()
9696

9797
// Fetch the CAPI Machine.
9898
capiMachine, err := util.GetOwnerMachine(ctx, r.Client, csMachine.ObjectMeta)
9999
if err != nil {
100100
return ctrl.Result{}, err
101101
} else if capiMachine == nil {
102102
log.Info("Waiting for CAPI cluster controller to set owner reference on CloudStack machine.")
103-
return ctrl.Result{RequeueAfter: RequeueTimeout}, nil
103+
return ctrl.Result{RequeueAfter: requeueTimeout}, nil
104104
}
105105

106106
// Fetch the CAPI Cluster.
107107
cluster, err := util.GetClusterFromMetadata(ctx, r.Client, capiMachine.ObjectMeta)
108108
if err != nil {
109109
log.Info("Machine is missing cluster label or cluster does not exist.")
110-
return ctrl.Result{RequeueAfter: RequeueTimeout}, nil
110+
return ctrl.Result{RequeueAfter: requeueTimeout}, nil
111111
}
112112

113113
// Check if the machine is paused.
@@ -131,13 +131,12 @@ func (r *CloudStackMachineReconciler) Reconcile(ctx context.Context, req ctrl.Re
131131
csCluster); err != nil {
132132
if client.IgnoreNotFound(err) == nil {
133133
log.Info("CloudStackCluster not found.")
134-
return ctrl.Result{RequeueAfter: RequeueTimeout}, nil
135-
} else {
136-
return ctrl.Result{}, err
134+
return ctrl.Result{RequeueAfter: requeueTimeout}, nil
137135
}
136+
return ctrl.Result{}, err
138137
} else if csCluster.Status.ZoneID == "" {
139138
log.Info("CloudStackCluster ZoneId not initialized. Likely not ready.")
140-
return ctrl.Result{RequeueAfter: RequeueTimeout}, nil
139+
return ctrl.Result{RequeueAfter: requeueTimeout}, nil
141140
}
142141

143142
// Reconcile a VM instance for creates/updates
@@ -169,7 +168,7 @@ func (r *CloudStackMachineReconciler) reconcile(
169168

170169
value, ok := secret.Data["value"]
171170
if !ok {
172-
return ctrl.Result{}, errors.New("Bootstrap secret data not ok.")
171+
return ctrl.Result{}, errors.New("bootstrap secret data not ok")
173172
}
174173

175174
// Create VM (or Fetch if present). Will set ready to true.
@@ -190,10 +189,10 @@ func (r *CloudStackMachineReconciler) reconcile(
190189
if err := r.Client.Delete(ctx, capiMachine); err != nil {
191190
return ctrl.Result{}, err
192191
}
193-
return ctrl.Result{RequeueAfter: RequeueTimeout}, nil
192+
return ctrl.Result{RequeueAfter: requeueTimeout}, nil
194193
} else {
195194
log.Info(fmt.Sprintf("Instance not ready, is %s.", csMachine.Status.InstanceState))
196-
return ctrl.Result{RequeueAfter: RequeueTimeout}, nil
195+
return ctrl.Result{RequeueAfter: requeueTimeout}, nil
197196
}
198197

199198
if util.IsControlPlaneMachine(capiMachine) && csCluster.Status.NetworkType != cloud.NetworkTypeShared {
@@ -333,7 +332,7 @@ func (r *CloudStackMachineReconciler) RemoveManagedAffinity(
333332
}
334333
group := &cloud.AffinityGroup{Name: name}
335334
_ = r.CS.FetchAffinityGroup(group)
336-
if group.Id == "" { // Affinity group not found, must have been deleted.
335+
if group.ID == "" { // Affinity group not found, must have been deleted.
337336
return nil
338337
}
339338

0 commit comments

Comments
 (0)