Skip to content

Commit

Permalink
chore(lint): Lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hrak committed Feb 27, 2025
1 parent 74fee38 commit 2c5a9f2
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 44 deletions.
20 changes: 10 additions & 10 deletions api/v1beta3/cloudstackcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var (
)

// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (r *CloudStackClusterWebhook) Default(ctx context.Context, objRaw runtime.Object) error {
func (r *CloudStackClusterWebhook) Default(_ context.Context, objRaw runtime.Object) error {
obj, ok := objRaw.(*CloudStackCluster)
if !ok {
return apierrors.NewBadRequest(fmt.Sprintf("expected a CloudStackCluster but got a %T", objRaw))
Expand All @@ -64,7 +64,7 @@ func (r *CloudStackClusterWebhook) Default(ctx context.Context, objRaw runtime.O
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *CloudStackClusterWebhook) ValidateCreate(ctx context.Context, objRaw runtime.Object) (admission.Warnings, error) {
func (r *CloudStackClusterWebhook) ValidateCreate(_ context.Context, objRaw runtime.Object) (admission.Warnings, error) {
obj, ok := objRaw.(*CloudStackCluster)
if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a CloudStackCluster but got a %T", objRaw))
Expand All @@ -76,18 +76,18 @@ func (r *CloudStackClusterWebhook) ValidateCreate(ctx context.Context, objRaw ru
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *CloudStackClusterWebhook) ValidateUpdate(ctx context.Context, oldRaw runtime.Object, newRaw runtime.Object) (admission.Warnings, error) {
old, ok := oldRaw.(*CloudStackCluster)
func (r *CloudStackClusterWebhook) ValidateUpdate(_ context.Context, oldRaw runtime.Object, newRaw runtime.Object) (admission.Warnings, error) {
oldObj, ok := oldRaw.(*CloudStackCluster)
if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a CloudStackCluster but got a %T", oldRaw))
}
new, ok := newRaw.(*CloudStackCluster)
newObj, ok := newRaw.(*CloudStackCluster)
if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a CloudStackCluster but got a %T", newRaw))
}
spec := new.Spec
spec := newObj.Spec

oldSpec := old.Spec
oldSpec := oldObj.Spec

errorList := field.ErrorList(nil)

Expand All @@ -103,18 +103,18 @@ func (r *CloudStackClusterWebhook) ValidateUpdate(ctx context.Context, oldRaw ru
"controlplaneendpoint.port", errorList)
}

if annotations.IsExternallyManaged(old) && !annotations.IsExternallyManaged(new) {
if annotations.IsExternallyManaged(oldObj) && !annotations.IsExternallyManaged(newObj) {
errorList = append(errorList,
field.Forbidden(field.NewPath("metadata", "annotations"),
"removal of externally managed (managed-by) annotation is not allowed"),
)
}

return nil, webhookutil.AggregateObjErrors(new.GroupVersionKind().GroupKind(), new.Name, errorList)
return nil, webhookutil.AggregateObjErrors(newObj.GroupVersionKind().GroupKind(), newObj.Name, errorList)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *CloudStackClusterWebhook) ValidateDelete(ctx context.Context, _ runtime.Object) (admission.Warnings, error) {
func (r *CloudStackClusterWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
return nil, nil
}

Expand Down
11 changes: 6 additions & 5 deletions api/v1beta3/cloudstackclustertemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
"sigs.k8s.io/cluster-api-provider-cloudstack/pkg/webhookutil"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

"sigs.k8s.io/cluster-api-provider-cloudstack/pkg/webhookutil"
)

const cloudStackClusterTemplateImmutableMsg = "CloudStackClusterTemplate spec.template.spec field is immutable. Please create new resource instead."
Expand All @@ -47,7 +48,7 @@ func (r *CloudStackClusterTemplateWebhook) SetupWebhookWithManager(mgr ctrl.Mana
var _ webhook.CustomDefaulter = &CloudStackClusterTemplateWebhook{}

// Default implements webhook.CustomDefaulter so a webhook will be registered for the type.
func (r *CloudStackClusterTemplateWebhook) Default(ctx context.Context, objRaw runtime.Object) error {
func (r *CloudStackClusterTemplateWebhook) Default(_ context.Context, objRaw runtime.Object) error {
obj, ok := objRaw.(*CloudStackClusterTemplate)
if !ok {
return apierrors.NewBadRequest(fmt.Sprintf("expected a CloudStackClusterTemplate but got a %T", objRaw))
Expand All @@ -62,7 +63,7 @@ func (r *CloudStackClusterTemplateWebhook) Default(ctx context.Context, objRaw r
var _ webhook.CustomValidator = &CloudStackClusterTemplateWebhook{}

// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type.
func (r *CloudStackClusterTemplateWebhook) ValidateCreate(ctx context.Context, objRaw runtime.Object) (admission.Warnings, error) {
func (r *CloudStackClusterTemplateWebhook) ValidateCreate(_ context.Context, objRaw runtime.Object) (admission.Warnings, error) {
obj, ok := objRaw.(*CloudStackClusterTemplate)
if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a CloudStackClusterTemplate but got a %T", objRaw))
Expand All @@ -73,7 +74,7 @@ func (r *CloudStackClusterTemplateWebhook) ValidateCreate(ctx context.Context, o
}

// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type.
func (r *CloudStackClusterTemplateWebhook) ValidateUpdate(ctx context.Context, oldRaw runtime.Object, newRaw runtime.Object) (admission.Warnings, error) {
func (r *CloudStackClusterTemplateWebhook) ValidateUpdate(_ context.Context, oldRaw runtime.Object, newRaw runtime.Object) (admission.Warnings, error) {
var allErrs field.ErrorList
newObj, ok := newRaw.(*CloudStackClusterTemplate)
if !ok {
Expand All @@ -93,6 +94,6 @@ func (r *CloudStackClusterTemplateWebhook) ValidateUpdate(ctx context.Context, o
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *CloudStackClusterTemplateWebhook) ValidateDelete(ctx context.Context, _ runtime.Object) (admission.Warnings, error) {
func (r *CloudStackClusterTemplateWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
return nil, nil
}
2 changes: 1 addition & 1 deletion api/v1beta3/cloudstackclustertemplate_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestCloudStackClusterTemplateFeatureGateEnabled(t *testing.T) {
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Run(tt.name, func(_ *testing.T) {
webhook := &CloudStackClusterTemplateWebhook{}
warnings, err := webhook.ValidateCreate(ctx, tt.template)
if tt.wantError {
Expand Down
48 changes: 24 additions & 24 deletions api/v1beta3/cloudstackmachine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (r *CloudStackMachineWebhook) SetupWebhookWithManager(mgr ctrl.Manager) err
var _ webhook.CustomValidator = &CloudStackMachineWebhook{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *CloudStackMachineWebhook) ValidateCreate(ctx context.Context, objRaw runtime.Object) (admission.Warnings, error) {
func (r *CloudStackMachineWebhook) ValidateCreate(_ context.Context, objRaw runtime.Object) (admission.Warnings, error) {
obj, ok := objRaw.(*CloudStackMachine)
if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a CloudStackMachine but got a %T", objRaw))
Expand All @@ -63,44 +63,44 @@ func (r *CloudStackMachineWebhook) ValidateCreate(ctx context.Context, objRaw ru
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *CloudStackMachineWebhook) ValidateUpdate(ctx context.Context, oldRaw runtime.Object, newRaw runtime.Object) (admission.Warnings, error) {
old, ok := oldRaw.(*CloudStackMachine)
func (r *CloudStackMachineWebhook) ValidateUpdate(_ context.Context, oldRaw runtime.Object, newRaw runtime.Object) (admission.Warnings, error) {
oldObj, ok := oldRaw.(*CloudStackMachine)
if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a CloudStackMachine but got a %T", oldRaw))
}
new, ok := newRaw.(*CloudStackMachine)
newObj, ok := newRaw.(*CloudStackMachine)
if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a CloudStackMachine but got a %T", newRaw))
}
var errorList field.ErrorList

oldSpec := old.Spec

errorList = webhookutil.EnsureEqualStrings(new.Spec.Offering.ID, oldSpec.Offering.ID, "offering", errorList)
errorList = webhookutil.EnsureEqualStrings(new.Spec.Offering.Name, oldSpec.Offering.Name, "offering", errorList)
if new.Spec.DiskOffering != nil {
errorList = webhookutil.EnsureEqualStrings(new.Spec.DiskOffering.ID, oldSpec.DiskOffering.ID, "diskOffering", errorList)
errorList = webhookutil.EnsureEqualStrings(new.Spec.DiskOffering.Name, oldSpec.DiskOffering.Name, "diskOffering", errorList)
errorList = webhookutil.EnsureIntFieldsAreNotNegative(new.Spec.DiskOffering.CustomSize, "customSizeInGB", errorList)
errorList = webhookutil.EnsureEqualStrings(new.Spec.DiskOffering.MountPath, oldSpec.DiskOffering.MountPath, "mountPath", errorList)
errorList = webhookutil.EnsureEqualStrings(new.Spec.DiskOffering.Device, oldSpec.DiskOffering.Device, "device", errorList)
errorList = webhookutil.EnsureEqualStrings(new.Spec.DiskOffering.Filesystem, oldSpec.DiskOffering.Filesystem, "filesystem", errorList)
errorList = webhookutil.EnsureEqualStrings(new.Spec.DiskOffering.Label, oldSpec.DiskOffering.Label, "label", errorList)
oldSpec := oldObj.Spec

errorList = webhookutil.EnsureEqualStrings(newObj.Spec.Offering.ID, oldSpec.Offering.ID, "offering", errorList)
errorList = webhookutil.EnsureEqualStrings(newObj.Spec.Offering.Name, oldSpec.Offering.Name, "offering", errorList)
if newObj.Spec.DiskOffering != nil {
errorList = webhookutil.EnsureEqualStrings(newObj.Spec.DiskOffering.ID, oldSpec.DiskOffering.ID, "diskOffering", errorList)
errorList = webhookutil.EnsureEqualStrings(newObj.Spec.DiskOffering.Name, oldSpec.DiskOffering.Name, "diskOffering", errorList)
errorList = webhookutil.EnsureIntFieldsAreNotNegative(newObj.Spec.DiskOffering.CustomSize, "customSizeInGB", errorList)
errorList = webhookutil.EnsureEqualStrings(newObj.Spec.DiskOffering.MountPath, oldSpec.DiskOffering.MountPath, "mountPath", errorList)
errorList = webhookutil.EnsureEqualStrings(newObj.Spec.DiskOffering.Device, oldSpec.DiskOffering.Device, "device", errorList)
errorList = webhookutil.EnsureEqualStrings(newObj.Spec.DiskOffering.Filesystem, oldSpec.DiskOffering.Filesystem, "filesystem", errorList)
errorList = webhookutil.EnsureEqualStrings(newObj.Spec.DiskOffering.Label, oldSpec.DiskOffering.Label, "label", errorList)
}
errorList = webhookutil.EnsureEqualStrings(new.Spec.SSHKey, oldSpec.SSHKey, "sshkey", errorList)
errorList = webhookutil.EnsureEqualStrings(new.Spec.Template.ID, oldSpec.Template.ID, "template", errorList)
errorList = webhookutil.EnsureEqualStrings(new.Spec.Template.Name, oldSpec.Template.Name, "template", errorList)
errorList = webhookutil.EnsureEqualMapStringString(new.Spec.Details, oldSpec.Details, "details", errorList)
errorList = webhookutil.EnsureEqualStrings(new.Spec.Affinity, oldSpec.Affinity, "affinity", errorList)
errorList = webhookutil.EnsureEqualStrings(newObj.Spec.SSHKey, oldSpec.SSHKey, "sshkey", errorList)
errorList = webhookutil.EnsureEqualStrings(newObj.Spec.Template.ID, oldSpec.Template.ID, "template", errorList)
errorList = webhookutil.EnsureEqualStrings(newObj.Spec.Template.Name, oldSpec.Template.Name, "template", errorList)
errorList = webhookutil.EnsureEqualMapStringString(newObj.Spec.Details, oldSpec.Details, "details", errorList)
errorList = webhookutil.EnsureEqualStrings(newObj.Spec.Affinity, oldSpec.Affinity, "affinity", errorList)

if !reflect.DeepEqual(new.Spec.AffinityGroupIDs, oldSpec.AffinityGroupIDs) { // Equivalent to other Ensure funcs.
if !reflect.DeepEqual(newObj.Spec.AffinityGroupIDs, oldSpec.AffinityGroupIDs) { // Equivalent to other Ensure funcs.
errorList = append(errorList, field.Forbidden(field.NewPath("spec", "AffinityGroupIDs"), "AffinityGroupIDs"))
}

return nil, webhookutil.AggregateObjErrors(new.GroupVersionKind().GroupKind(), new.Name, errorList)
return nil, webhookutil.AggregateObjErrors(newObj.GroupVersionKind().GroupKind(), newObj.Name, errorList)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *CloudStackMachineWebhook) ValidateDelete(ctx context.Context, _ runtime.Object) (admission.Warnings, error) {
func (r *CloudStackMachineWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
return nil, nil
}
6 changes: 3 additions & 3 deletions api/v1beta3/cloudstackmachinetemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (r *CloudStackMachineTemplateWebhook) SetupWebhookWithManager(mgr ctrl.Mana
var _ webhook.CustomValidator = &CloudStackMachineTemplateWebhook{}

// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type.
func (r *CloudStackMachineTemplateWebhook) ValidateCreate(ctx context.Context, objRaw runtime.Object) (admission.Warnings, error) {
func (r *CloudStackMachineTemplateWebhook) ValidateCreate(_ context.Context, objRaw runtime.Object) (admission.Warnings, error) {
obj, ok := objRaw.(*CloudStackMachineTemplate)
if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a CloudStackMachineTemplate but got a %T", objRaw))
Expand Down Expand Up @@ -76,7 +76,7 @@ func (r *CloudStackMachineTemplateWebhook) ValidateCreate(ctx context.Context, o
}

// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type.
func (r *CloudStackMachineTemplateWebhook) ValidateUpdate(ctx context.Context, oldRaw runtime.Object, newRaw runtime.Object) (admission.Warnings, error) {
func (r *CloudStackMachineTemplateWebhook) ValidateUpdate(_ context.Context, oldRaw runtime.Object, newRaw runtime.Object) (admission.Warnings, error) {
obj, ok := newRaw.(*CloudStackMachineTemplate)
if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a CloudStackMachineTemplate but got a %T", newRaw))
Expand All @@ -96,6 +96,6 @@ func (r *CloudStackMachineTemplateWebhook) ValidateUpdate(ctx context.Context, o
}

// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type.
func (r *CloudStackMachineTemplateWebhook) ValidateDelete(ctx context.Context, _ runtime.Object) (admission.Warnings, error) {
func (r *CloudStackMachineTemplateWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
return nil, nil
}
1 change: 0 additions & 1 deletion api/v1beta3/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

//+kubebuilder:scaffold:imports
admissionv1 "k8s.io/api/admission/v1"
apimachineryruntime "k8s.io/apimachinery/pkg/runtime"
Expand Down

0 comments on commit 2c5a9f2

Please sign in to comment.