Skip to content

Commit

Permalink
lint: upgrade golangci-lint to v1.54.2
Browse files Browse the repository at this point in the history
  • Loading branch information
KevFan committed Aug 28, 2023
1 parent 9aaccdb commit 4dfd272
Show file tree
Hide file tree
Showing 29 changed files with 83 additions and 112 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ run-lint: $(GOLANGCI-LINT) ## Run lint tests
$(GOLANGCI-LINT) run

$(GOLANGCI-LINT):
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(PROJECT_PATH)/bin v1.50.1
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(PROJECT_PATH)/bin v1.54.2

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI-LINT) ## Download golangci-lint locally if necessary.
Expand Down
6 changes: 3 additions & 3 deletions controllers/authpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (r *AuthPolicyReconciler) deleteResources(ctx context.Context, ap *api.Auth

// remove direct back ref
if targetNetworkObject != nil {
if err := r.deleteNetworkResourceDirectBackReference(ctx, ap, targetNetworkObject); err != nil {
if err := r.deleteNetworkResourceDirectBackReference(ctx, targetNetworkObject); err != nil {
return err
}
}
Expand All @@ -186,8 +186,8 @@ func (r *AuthPolicyReconciler) reconcileNetworkResourceDirectBackReference(ctx c
return r.ReconcileTargetBackReference(ctx, client.ObjectKeyFromObject(ap), targetNetworkObject, common.AuthPolicyBackRefAnnotation)
}

func (r *AuthPolicyReconciler) deleteNetworkResourceDirectBackReference(ctx context.Context, ap *api.AuthPolicy, targetNetworkObject client.Object) error {
return r.DeleteTargetBackReference(ctx, client.ObjectKeyFromObject(ap), targetNetworkObject, common.AuthPolicyBackRefAnnotation)
func (r *AuthPolicyReconciler) deleteNetworkResourceDirectBackReference(ctx context.Context, targetNetworkObject client.Object) error {
return r.DeleteTargetBackReference(ctx, targetNetworkObject, common.AuthPolicyBackRefAnnotation)
}

// SetupWithManager sets up the controller with the Manager.
Expand Down
4 changes: 2 additions & 2 deletions controllers/authpolicy_istio_authorization_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ func (r *AuthPolicyReconciler) deleteIstioAuthorizationPolicies(ctx context.Cont
}

for _, gw := range gwDiffObj.GatewaysWithInvalidPolicyRef {
listOptions := &client.ListOptions{LabelSelector: labels.SelectorFromSet(labels.Set(istioAuthorizationPolicyLabels(client.ObjectKeyFromObject(gw.Gateway), client.ObjectKeyFromObject(ap))))}
listOptions := &client.ListOptions{LabelSelector: labels.SelectorFromSet(istioAuthorizationPolicyLabels(client.ObjectKeyFromObject(gw.Gateway), client.ObjectKeyFromObject(ap)))}
iapList := &istio.AuthorizationPolicyList{}
if err := r.Client().List(ctx, iapList, listOptions); err != nil {
return err
}

for _, iap := range iapList.Items {
// it's OK to just go ahead and delete because we only create one IAP per target network object,
// and a network object can be target by no more than one AuthPolicy
// and a network object can be targeted by no more than one AuthPolicy
if err := r.DeleteResource(ctx, iap); err != nil && !apierrors.IsNotFound(err) {
logger.Error(err, "failed to delete IstioAuthorizationPolicy")
return err
Expand Down
2 changes: 1 addition & 1 deletion controllers/authpolicy_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1"
"github.com/kuadrant/kuadrant-operator/pkg/common"
"k8s.io/apimachinery/pkg/api/errors"
meta "k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down
2 changes: 1 addition & 1 deletion controllers/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
meta "k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
Expand Down
28 changes: 7 additions & 21 deletions controllers/kuadrant_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,7 @@ func (r *KuadrantReconciler) Reconcile(eventCtx context.Context, req ctrl.Reques
logger.V(1).Error(gwErr, "Reconciling cluster gateways failed")
}

specResult, specErr := r.reconcileSpec(ctx, kObj)
if specErr == nil && specResult.Requeue {
logger.V(1).Info("Reconciling spec not finished. Requeueing.")
return specResult, nil
}
specErr := r.reconcileSpec(ctx, kObj)

statusResult, statusErr := r.reconcileStatus(ctx, kObj, specErr)

Expand Down Expand Up @@ -356,20 +352,16 @@ func (r *KuadrantReconciler) registerServiceMeshMember(ctx context.Context, kObj
return r.ReconcileResource(ctx, &maistrav1.ServiceMeshMember{}, member, reconcilers.CreateOnlyMutator)
}

func (r *KuadrantReconciler) reconcileSpec(ctx context.Context, kObj *kuadrantv1beta1.Kuadrant) (ctrl.Result, error) {
func (r *KuadrantReconciler) reconcileSpec(ctx context.Context, kObj *kuadrantv1beta1.Kuadrant) error {
if err := r.registerExternalAuthorizer(ctx, kObj); err != nil {
return ctrl.Result{}, err
return err
}

if err := r.reconcileLimitador(ctx, kObj); err != nil {
return ctrl.Result{}, err
}

if err := r.reconcileAuthorino(ctx, kObj); err != nil {
return ctrl.Result{}, err
return err
}

return ctrl.Result{}, nil
return r.reconcileAuthorino(ctx, kObj)
}

func controlPlaneProviderName() string {
Expand Down Expand Up @@ -430,10 +422,7 @@ func (r *KuadrantReconciler) reconcileClusterGateways(ctx context.Context, kObj
}
}

if err := errGroup.Wait(); err != nil {
return err
}
return nil
return errGroup.Wait()
}

func (r *KuadrantReconciler) removeAnnotationFromGateways(ctx context.Context, kObj *kuadrantv1beta1.Kuadrant) error {
Expand Down Expand Up @@ -461,10 +450,7 @@ func (r *KuadrantReconciler) removeAnnotationFromGateways(ctx context.Context, k
})
}

if err := errGroup.Wait(); err != nil {
return err
}
return nil
return errGroup.Wait()
}

func (r *KuadrantReconciler) reconcileLimitador(ctx context.Context, kObj *kuadrantv1beta1.Kuadrant) error {
Expand Down
4 changes: 2 additions & 2 deletions controllers/kuadrant_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
meta "k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -88,7 +88,7 @@ func (r *KuadrantReconciler) readyCondition(ctx context.Context, kObj *kuadrantv

if specErr != nil {
cond.Status = metav1.ConditionFalse
cond.Reason = "ReconcilliationError"
cond.Reason = "ReconciliationError"
cond.Message = specErr.Error()
return cond, nil
}
Expand Down
6 changes: 3 additions & 3 deletions controllers/ratelimitpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (r *RateLimitPolicyReconciler) deleteResources(ctx context.Context, rlp *ku

// remove direct back ref
if targetNetworkObject != nil {
if err := r.deleteNetworkResourceDirectBackReference(ctx, rlp, targetNetworkObject); err != nil {
if err := r.deleteNetworkResourceDirectBackReference(ctx, targetNetworkObject); err != nil {
return err
}
}
Expand All @@ -225,8 +225,8 @@ func (r *RateLimitPolicyReconciler) reconcileNetworkResourceDirectBackReference(
return r.ReconcileTargetBackReference(ctx, client.ObjectKeyFromObject(policy), targetNetworkObject, common.RateLimitPolicyBackRefAnnotation)
}

func (r *RateLimitPolicyReconciler) deleteNetworkResourceDirectBackReference(ctx context.Context, rlp *kuadrantv1beta2.RateLimitPolicy, targetNetworkObject client.Object) error {
return r.DeleteTargetBackReference(ctx, client.ObjectKeyFromObject(rlp), targetNetworkObject, common.RateLimitPolicyBackRefAnnotation)
func (r *RateLimitPolicyReconciler) deleteNetworkResourceDirectBackReference(ctx context.Context, targetNetworkObject client.Object) error {
return r.DeleteTargetBackReference(ctx, targetNetworkObject, common.RateLimitPolicyBackRefAnnotation)
}

// SetupWithManager sets up the controller with the Manager.
Expand Down
6 changes: 3 additions & 3 deletions controllers/ratelimitpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ func testBuildBasicGateway(gwName, ns string) *gatewayapiv1beta1.Gateway {
Annotations: map[string]string{"networking.istio.io/service-type": string(corev1.ServiceTypeClusterIP)},
},
Spec: gatewayapiv1beta1.GatewaySpec{
GatewayClassName: gatewayapiv1beta1.ObjectName("istio"),
GatewayClassName: "istio",
Listeners: []gatewayapiv1beta1.Listener{
{
Name: gatewayapiv1beta1.SectionName("default"),
Name: "default",
Port: gatewayapiv1beta1.PortNumber(80),
Protocol: gatewayapiv1beta1.ProtocolType("HTTP"),
Protocol: "HTTP",
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion controllers/ratelimitpolicy_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/go-logr/logr"
apierrors "k8s.io/apimachinery/pkg/api/errors"
meta "k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down
7 changes: 3 additions & 4 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
// TODO: move the const to a proper place, or get it from config
const (
KuadrantRateLimitClusterName = "kuadrant-rate-limiting-service"
HTTPRouteKind = "HTTPRoute"
RateLimitPoliciesBackRefAnnotation = "kuadrant.io/ratelimitpolicies"
RateLimitPolicyBackRefAnnotation = "kuadrant.io/ratelimitpolicy"
AuthPoliciesBackRefAnnotation = "kuadrant.io/authpolicies"
Expand Down Expand Up @@ -238,7 +237,7 @@ func UnMarshallObjectKey(keyStr string) (client.ObjectKey, error) {
return client.ObjectKey{Namespace: keyStr[:namespaceEndIndex], Name: keyStr[namespaceEndIndex+1:]}, nil
}

// HostnamesToStrings converts []gatewayapi_v1alpha2.Hostname to []string
// HostnamesToStrings converts []gatewayapiv1beta1.Hostname to []string
func HostnamesToStrings(hostnames []gatewayapiv1beta1.Hostname) []string {
return Map(hostnames, func(hostname gatewayapiv1beta1.Hostname) string {
return string(hostname)
Expand All @@ -249,8 +248,8 @@ func HostnamesToStrings(hostnames []gatewayapiv1beta1.Hostname) []string {
// is a subset of at least one of the domains.
// Domains and subdomains may be prefixed with a wildcard label (*.).
// The wildcard label must appear by itself as the first label.
// When one of the subdomains is not a subset of any of the domains, it returns false and
// the subdomain not being subset of any of the domains
// When one of the subdomains is not a subset of the domains, it returns false and
// the subdomain not being subset of the domains
func ValidSubdomains(domains, subdomains []string) (bool, string) {
for _, subdomain := range subdomains {
validSubdomain := false
Expand Down
10 changes: 4 additions & 6 deletions pkg/common/gatewayapi_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ func TestGetGatewayWorkloadSelector(t *testing.T) {
scheme := runtime.NewScheme()
_ = corev1.AddToScheme(scheme)
_ = gatewayapiv1beta1.AddToScheme(scheme)
k8sClient := fake.NewFakeClientWithScheme(scheme, gateway, service)
k8sClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(gateway, service).Build()

var selector map[string]string
var err error
Expand Down Expand Up @@ -1136,7 +1136,7 @@ func TestGetGatewayWorkloadSelectorWithoutHostnameAddress(t *testing.T) {
scheme := runtime.NewScheme()
_ = corev1.AddToScheme(scheme)
_ = gatewayapiv1beta1.AddToScheme(scheme)
k8sClient := fake.NewFakeClientWithScheme(scheme, gateway, service)
k8sClient := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(gateway, service).Build()

var selector map[string]string
var err error
Expand All @@ -1157,7 +1157,7 @@ func (p *FakePolicy) GetTargetRef() gatewayapiv1alpha2.PolicyTargetReference {
}

func (p *FakePolicy) GetWrappedNamespace() gatewayapiv1beta1.Namespace {
return gatewayapiv1beta1.Namespace("")
return ""
}

func (p *FakePolicy) GetRulesHostnames() []string {
Expand Down Expand Up @@ -1193,9 +1193,7 @@ func TestValidateHierarchicalRules(t *testing.T) {
)

if err := ValidateHierarchicalRules(&policy2, gateway); err.Error() != expectedError.Error() {
t.Fatal("the error message does not match the expected error one")
fmt.Println(expectedError.Error())
fmt.Println(err.Error())
t.Fatal("the error message does not match the expected error one", expectedError.Error(), err.Error())
}

}
Expand Down
1 change: 0 additions & 1 deletion pkg/common/istio_utils_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build unit
// +build unit

package common

Expand Down
7 changes: 2 additions & 5 deletions pkg/common/k8s_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ import (
)

const (
DeleteTagAnnotation = "kuadrant.io/delete"
ReadyStatusConditionType = "Ready"
DeleteTagAnnotation = "kuadrant.io/delete"
)

// ObjectInfo generates a string representation of the provided Kubernetes object, including its kind and name.
Expand Down Expand Up @@ -80,9 +79,7 @@ func IsObjectTaggedToDelete(obj client.Object) bool {
// condition type.
func StatusConditionsMarshalJSON(input []metav1.Condition) ([]byte, error) {
conds := make([]metav1.Condition, 0, len(input))
for idx := range input {
conds = append(conds, input[idx])
}
conds = append(conds, input...)

sort.Slice(conds, func(a, b int) bool {
return conds[a].Type < conds[b].Type
Expand Down
1 change: 0 additions & 1 deletion pkg/common/k8s_utils_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build unit
// +build unit

package common

Expand Down
1 change: 0 additions & 1 deletion pkg/common/mesh_config_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build unit
// +build unit

package common

Expand Down
1 change: 0 additions & 1 deletion pkg/common/yaml_decoder_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build unit
// +build unit

package common

Expand Down
6 changes: 2 additions & 4 deletions pkg/istio/mesh_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,8 @@ func (w *OSSMControlPlaneWrapper) SetMeshConfig(config *istiomeshv1alpha1.MeshCo
if err != nil {
return err
}
if err := w.config.Spec.TechPreview.SetField("meshConfig", meshConfigStruct.AsMap()); err != nil {
return err
}
return nil

return w.config.Spec.TechPreview.SetField("meshConfig", meshConfigStruct.AsMap())
}

// meshConfigFromStruct Builds the Istio/OSSM MeshConfig from a compatible structure:
Expand Down
9 changes: 5 additions & 4 deletions pkg/istio/mesh_config_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build unit
// +build unit

package istio

Expand Down Expand Up @@ -172,7 +171,8 @@ func TestOSSMControlPlaneWrapper_GetConfigObject(t *testing.T) {
func TestOSSMControlPlaneWrapper_GetMeshConfig(t *testing.T) {
ossmControlPlane := &maistrav2.ServiceMeshControlPlane{}
ossmControlPlane.Spec.TechPreview = maistrav1.NewHelmValues(nil)
ossmControlPlane.Spec.TechPreview.SetField("meshConfig", getStubbedMeshConfigStruct().AsMap())
err := ossmControlPlane.Spec.TechPreview.SetField("meshConfig", getStubbedMeshConfigStruct().AsMap())
assert.NilError(t, err)

wrapper := NewOSSMControlPlaneWrapper(ossmControlPlane)
meshConfig, _ := wrapper.GetMeshConfig()
Expand All @@ -185,12 +185,13 @@ func TestOSSMControlPlaneWrapper_SetMeshConfig(t *testing.T) {
ossmControlPlane := &maistrav2.ServiceMeshControlPlane{}
ossmControlPlane.Spec.TechPreview = maistrav1.NewHelmValues(nil)
emptyConfig := &structpb.Struct{}
ossmControlPlane.Spec.TechPreview.SetField("meshConfig", emptyConfig.AsMap())
err := ossmControlPlane.Spec.TechPreview.SetField("meshConfig", emptyConfig.AsMap())
assert.NilError(t, err)

wrapper := NewOSSMControlPlaneWrapper(ossmControlPlane)

stubbedMeshConfig := getStubbedMeshConfig()
err := wrapper.SetMeshConfig(stubbedMeshConfig)
err = wrapper.SetMeshConfig(stubbedMeshConfig)
assert.NilError(t, err)

meshConfig, _ := wrapper.GetMeshConfig()
Expand Down
1 change: 0 additions & 1 deletion pkg/log/log_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build unit
// +build unit

/*
Copyright 2021 Red Hat, Inc.
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconcilers/base_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
// MutateFn is a function which mutates the existing object into it's desired state.
type MutateFn func(existing, desired client.Object) (bool, error)

func CreateOnlyMutator(existing, desired client.Object) (bool, error) {
func CreateOnlyMutator(_, _ client.Object) (bool, error) {
return false, nil
}

Expand Down
Loading

0 comments on commit 4dfd272

Please sign in to comment.