Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(lint): update golangci-lint config and fix errors reported by golangci-lint #1537

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
run:
timeout: 2m
skip-files:
- ".*_test\\.go"
skip-dirs:
- vendor/
linters:
enable:
- vet
- deadcode
- govet
- unused
- goimports
- varcheck
- structcheck
- ineffassign
- unconvert
- unparam
issues:
exclude-files:
- ".*_test\\.go"
exclude-dirs:
- vendor/
linters-settings:
goimports:
local-prefixes: github.com/argoproj-labs/argocd-operator
service:
golangci-lint-version: 1.56.2
2 changes: 2 additions & 0 deletions api/v1alpha1/argocd_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (src *ArgoCD) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.ExtraConfig = src.Spec.ExtraConfig
dst.Spec.GATrackingID = src.Spec.GATrackingID
dst.Spec.GAAnonymizeUsers = src.Spec.GAAnonymizeUsers
//nolint:staticcheck
dst.Spec.Grafana = *ConvertAlphaToBetaGrafana(&src.Spec.Grafana)
dst.Spec.HA = *ConvertAlphaToBetaHA(&src.Spec.HA)
dst.Spec.HelpChatURL = src.Spec.HelpChatURL
Expand Down Expand Up @@ -130,6 +131,7 @@ func (dst *ArgoCD) ConvertFrom(srcRaw conversion.Hub) error {
dst.Spec.ExtraConfig = src.Spec.ExtraConfig
dst.Spec.GATrackingID = src.Spec.GATrackingID
dst.Spec.GAAnonymizeUsers = src.Spec.GAAnonymizeUsers
//nolint:staticcheck
dst.Spec.Grafana = *ConvertBetaToAlphaGrafana(&src.Spec.Grafana)
dst.Spec.HA = *ConvertBetaToAlphaHA(&src.Spec.HA)
dst.Spec.HelpChatURL = src.Spec.HelpChatURL
Expand Down
2 changes: 2 additions & 0 deletions controllers/argocd/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ func (r *ReconcileArgoCD) reconcileArgoConfigMap(cr *argoproj.ArgoCD) error {

// reconcileGrafanaConfiguration will ensure that the Grafana configuration ConfigMap is present.
func (r *ReconcileArgoCD) reconcileGrafanaConfiguration(cr *argoproj.ArgoCD) error {
//nolint:staticcheck
if !cr.Spec.Grafana.Enabled {
return nil // Grafana not enabled, do nothing.
}
Expand All @@ -487,6 +488,7 @@ func (r *ReconcileArgoCD) reconcileGrafanaConfiguration(cr *argoproj.ArgoCD) err

// reconcileGrafanaDashboards will ensure that the Grafana dashboards ConfigMap is present.
func (r *ReconcileArgoCD) reconcileGrafanaDashboards(cr *argoproj.ArgoCD) error {
//nolint:staticcheck
if !cr.Spec.Grafana.Enabled {
return nil // Grafana not enabled, do nothing.
}
Expand Down
3 changes: 2 additions & 1 deletion controllers/argocd/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func getArgoServerCommand(cr *argoproj.ArgoCD, useTLSForRedis bool) []string {
if err != nil {
return cmd
}
if cr.Spec.SourceNamespaces != nil && len(cr.Spec.SourceNamespaces) > 0 {
if len(cr.Spec.SourceNamespaces) > 0 {
cmd = append(cmd, "--application-namespaces", fmt.Sprint(strings.Join(cr.Spec.SourceNamespaces, ",")))
}

Expand Down Expand Up @@ -451,6 +451,7 @@ func (r *ReconcileArgoCD) reconcileDeployments(cr *argoproj.ArgoCD, useTLSForRed

// reconcileGrafanaDeployment will ensure the Deployment resource is present for the ArgoCD Grafana component.
func (r *ReconcileArgoCD) reconcileGrafanaDeployment(cr *argoproj.ArgoCD) error {
//nolint:staticcheck
if !cr.Spec.Grafana.Enabled {
return nil // Grafana not enabled, do nothing.
}
Expand Down
2 changes: 2 additions & 0 deletions controllers/argocd/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ func (r *ReconcileArgoCD) reconcileArgoServerGRPCIngress(cr *argoproj.ArgoCD) er
func (r *ReconcileArgoCD) reconcileGrafanaIngress(cr *argoproj.ArgoCD) error {
ingress := newIngressWithSuffix("grafana", cr)
if argoutil.IsObjectFound(r.Client, cr.Namespace, ingress.Name, ingress) {
//nolint:staticcheck
if !cr.Spec.Grafana.Enabled || !cr.Spec.Grafana.Ingress.Enabled {
// Ingress exists but enabled flag has been set to false, delete the Ingress
return r.Client.Delete(context.TODO(), ingress)
Expand All @@ -258,6 +259,7 @@ func (r *ReconcileArgoCD) reconcileGrafanaIngress(cr *argoproj.ArgoCD) error {
return nil // Ingress found and enabled, do nothing
}

//nolint:staticcheck
if !cr.Spec.Grafana.Enabled || !cr.Spec.Grafana.Ingress.Enabled {
return nil // Grafana itself or Ingress not enabled, move along...
}
Expand Down
5 changes: 3 additions & 2 deletions controllers/argocd/networkpolicies.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"fmt"
"reflect"

argoproj "github.com/argoproj-labs/argocd-operator/api/v1beta1"
"github.com/argoproj-labs/argocd-operator/controllers/argoutil"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

argoproj "github.com/argoproj-labs/argocd-operator/api/v1beta1"
"github.com/argoproj-labs/argocd-operator/controllers/argoutil"
)

var (
Expand Down
14 changes: 7 additions & 7 deletions controllers/argocd/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func (r *ReconcileArgoCD) reconcilePrometheusRule(cr *argoproj.ArgoCD) error {
},
Expr: intstr.IntOrString{
Type: intstr.String,
StrVal: fmt.Sprintf("kube_statefulset_status_replicas{statefulset=\"%s\", namespace=\"%s\"} != kube_statefulset_status_replicas_ready{statefulset=\"%s\", namespace=\"%s\"} ", fmt.Sprintf(cr.Name+"-application-controller"), cr.Namespace, fmt.Sprintf(cr.Name+"-application-controller"), cr.Namespace),
StrVal: fmt.Sprintf("kube_statefulset_status_replicas{statefulset=\"%s\", namespace=\"%s\"} != kube_statefulset_status_replicas_ready{statefulset=\"%s\", namespace=\"%s\"} ", cr.Name+"-application-controller", cr.Namespace, cr.Name+"-application-controller", cr.Namespace),
},
For: "1m",
Labels: map[string]string{
Expand All @@ -293,7 +293,7 @@ func (r *ReconcileArgoCD) reconcilePrometheusRule(cr *argoproj.ArgoCD) error {
},
Expr: intstr.IntOrString{
Type: intstr.String,
StrVal: fmt.Sprintf("kube_deployment_status_replicas{deployment=\"%s\", namespace=\"%s\"} != kube_deployment_status_replicas_ready{deployment=\"%s\", namespace=\"%s\"} ", fmt.Sprintf(cr.Name+"-server"), cr.Namespace, fmt.Sprintf(cr.Name+"-server"), cr.Namespace),
StrVal: fmt.Sprintf("kube_deployment_status_replicas{deployment=\"%s\", namespace=\"%s\"} != kube_deployment_status_replicas_ready{deployment=\"%s\", namespace=\"%s\"} ", cr.Name+"-server", cr.Namespace, cr.Name+"-server", cr.Namespace),
},
For: "1m",
Labels: map[string]string{
Expand All @@ -307,7 +307,7 @@ func (r *ReconcileArgoCD) reconcilePrometheusRule(cr *argoproj.ArgoCD) error {
},
Expr: intstr.IntOrString{
Type: intstr.String,
StrVal: fmt.Sprintf("kube_deployment_status_replicas{deployment=\"%s\", namespace=\"%s\"} != kube_deployment_status_replicas_ready{deployment=\"%s\", namespace=\"%s\"} ", fmt.Sprintf(cr.Name+"-repo-server"), cr.Namespace, fmt.Sprintf(cr.Name+"-repo-server"), cr.Namespace),
StrVal: fmt.Sprintf("kube_deployment_status_replicas{deployment=\"%s\", namespace=\"%s\"} != kube_deployment_status_replicas_ready{deployment=\"%s\", namespace=\"%s\"} ", cr.Name+"-repo-server", cr.Namespace, cr.Name+"-repo-server", cr.Namespace),
},
For: "1m",
Labels: map[string]string{
Expand All @@ -321,7 +321,7 @@ func (r *ReconcileArgoCD) reconcilePrometheusRule(cr *argoproj.ArgoCD) error {
},
Expr: intstr.IntOrString{
Type: intstr.String,
StrVal: fmt.Sprintf("kube_deployment_status_replicas{deployment=\"%s\", namespace=\"%s\"} != kube_deployment_status_replicas_ready{deployment=\"%s\", namespace=\"%s\"} ", fmt.Sprintf(cr.Name+"-applicationset-controller"), cr.Namespace, fmt.Sprintf(cr.Name+"-applicationset-controller"), cr.Namespace),
StrVal: fmt.Sprintf("kube_deployment_status_replicas{deployment=\"%s\", namespace=\"%s\"} != kube_deployment_status_replicas_ready{deployment=\"%s\", namespace=\"%s\"} ", cr.Name+"-applicationset-controller", cr.Namespace, cr.Name+"-applicationset-controller", cr.Namespace),
},
For: "5m",
Labels: map[string]string{
Expand All @@ -335,7 +335,7 @@ func (r *ReconcileArgoCD) reconcilePrometheusRule(cr *argoproj.ArgoCD) error {
},
Expr: intstr.IntOrString{
Type: intstr.String,
StrVal: fmt.Sprintf("kube_deployment_status_replicas{deployment=\"%s\", namespace=\"%s\"} != kube_deployment_status_replicas_ready{deployment=\"%s\", namespace=\"%s\"} ", fmt.Sprintf(cr.Name+"-dex-server"), cr.Namespace, fmt.Sprintf(cr.Name+"-dex-server"), cr.Namespace),
StrVal: fmt.Sprintf("kube_deployment_status_replicas{deployment=\"%s\", namespace=\"%s\"} != kube_deployment_status_replicas_ready{deployment=\"%s\", namespace=\"%s\"} ", cr.Name+"-dex-server", cr.Namespace, cr.Name+"-dex-server", cr.Namespace),
},
For: "5m",
Labels: map[string]string{
Expand All @@ -349,7 +349,7 @@ func (r *ReconcileArgoCD) reconcilePrometheusRule(cr *argoproj.ArgoCD) error {
},
Expr: intstr.IntOrString{
Type: intstr.String,
StrVal: fmt.Sprintf("kube_deployment_status_replicas{deployment=\"%s\", namespace=\"%s\"} != kube_deployment_status_replicas_ready{deployment=\"%s\", namespace=\"%s\"} ", fmt.Sprintf(cr.Name+"-notifications-controller"), cr.Namespace, fmt.Sprintf(cr.Name+"-notifications-controller"), cr.Namespace),
StrVal: fmt.Sprintf("kube_deployment_status_replicas{deployment=\"%s\", namespace=\"%s\"} != kube_deployment_status_replicas_ready{deployment=\"%s\", namespace=\"%s\"} ", cr.Name+"-notifications-controller", cr.Namespace, cr.Name+"-notifications-controller", cr.Namespace),
},
For: "5m",
Labels: map[string]string{
Expand All @@ -363,7 +363,7 @@ func (r *ReconcileArgoCD) reconcilePrometheusRule(cr *argoproj.ArgoCD) error {
},
Expr: intstr.IntOrString{
Type: intstr.String,
StrVal: fmt.Sprintf("kube_deployment_status_replicas{deployment=\"%s\", namespace=\"%s\"} != kube_deployment_status_replicas_ready{deployment=\"%s\", namespace=\"%s\"} ", fmt.Sprintf(cr.Name+"-redis"), cr.Namespace, fmt.Sprintf(cr.Name+"-redis"), cr.Namespace),
StrVal: fmt.Sprintf("kube_deployment_status_replicas{deployment=\"%s\", namespace=\"%s\"} != kube_deployment_status_replicas_ready{deployment=\"%s\", namespace=\"%s\"} ", cr.Name+"-redis", cr.Namespace, cr.Name+"-redis", cr.Namespace),
},
For: "5m",
Labels: map[string]string{
Expand Down
2 changes: 1 addition & 1 deletion controllers/argocd/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func TestReconcileArgoCD_reconcileRoleForApplicationSourceNamespaces(t *testing.
assert.NoError(t, createNamespace(r, a.Namespace, ""))
assert.NoError(t, createNamespaceManagedByClusterArgoCDLabel(r, sourceNamespace, a.Namespace))

workloadIdentifier := common.ArgoCDServerComponent
workloadIdentifier := common.ArgoCDServerComponent + "-custom"
expectedRules := policyRuleForServerApplicationSourceNamespaces()
err := r.reconcileRoleForApplicationSourceNamespaces(workloadIdentifier, expectedRules, a)
assert.NoError(t, err)
Expand Down
2 changes: 2 additions & 0 deletions controllers/argocd/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (r *ReconcileArgoCD) reconcileRoutes(cr *argoproj.ArgoCD) error {
func (r *ReconcileArgoCD) reconcileGrafanaRoute(cr *argoproj.ArgoCD) error {
route := newRouteWithSuffix("grafana", cr)
if argoutil.IsObjectFound(r.Client, cr.Namespace, route.Name, route) {
//nolint:staticcheck
if !cr.Spec.Grafana.Enabled || !cr.Spec.Grafana.Route.Enabled {
// Route exists but enabled flag has been set to false, delete the Route
return r.Client.Delete(context.TODO(), route)
Expand All @@ -114,6 +115,7 @@ func (r *ReconcileArgoCD) reconcileGrafanaRoute(cr *argoproj.ArgoCD) error {
return nil // Route found, do nothing
}

//nolint:staticcheck
if !cr.Spec.Grafana.Enabled || !cr.Spec.Grafana.Route.Enabled {
return nil // Grafana itself or Route not enabled, do nothing.
}
Expand Down
2 changes: 2 additions & 0 deletions controllers/argocd/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func newCertificateSecret(suffix string, caCert *x509.Certificate, caKey *rsa.Pr
fmt.Sprintf("%s.%s.svc.cluster.local", cr.ObjectMeta.Name, cr.ObjectMeta.Namespace),
}

//nolint:staticcheck
if cr.Spec.Grafana.Enabled {
log.Info(grafanaDeprecatedWarning)
}
Expand Down Expand Up @@ -366,6 +367,7 @@ func (r *ReconcileArgoCD) reconcileExistingArgoSecret(cr *argoproj.ArgoCD, secre

// reconcileGrafanaSecret will ensure that the Grafana Secret is present.
func (r *ReconcileArgoCD) reconcileGrafanaSecret(cr *argoproj.ArgoCD) error {
//nolint:staticcheck
if !cr.Spec.Grafana.Enabled {
return nil // Grafana not enabled, do nothing.
}
Expand Down
2 changes: 2 additions & 0 deletions controllers/argocd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func newServiceWithSuffix(suffix string, component string, cr *argoproj.ArgoCD)
func (r *ReconcileArgoCD) reconcileGrafanaService(cr *argoproj.ArgoCD) error {
svc := newServiceWithSuffix("grafana", "grafana", cr)
if argoutil.IsObjectFound(r.Client, cr.Namespace, svc.Name, svc) {
//nolint:staticcheck
if !cr.Spec.Grafana.Enabled {
// Service exists but enabled flag has been set to false, delete the Service
return r.Client.Delete(context.TODO(), svc)
Expand All @@ -78,6 +79,7 @@ func (r *ReconcileArgoCD) reconcileGrafanaService(cr *argoproj.ArgoCD) error {
return nil // Service found, do nothing
}

//nolint:staticcheck
if !cr.Spec.Grafana.Enabled {
return nil // Grafana not enabled, do nothing.
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/argocd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func getArgoApplicationControllerCommand(cr *argoproj.ArgoCD, useTLSForRedis boo
cmd = append(cmd, "--status-processors", fmt.Sprint(getArgoServerStatusProcessors(cr)))
cmd = append(cmd, "--kubectl-parallelism-limit", fmt.Sprint(getArgoControllerParellismLimit(cr)))

if cr.Spec.SourceNamespaces != nil && len(cr.Spec.SourceNamespaces) > 0 {
if len(cr.Spec.SourceNamespaces) > 0 {
cmd = append(cmd, "--application-namespaces", fmt.Sprint(strings.Join(cr.Spec.SourceNamespaces, ",")))
}

Expand Down
5 changes: 3 additions & 2 deletions controllers/notificationsconfiguration/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"fmt"
"reflect"

"github.com/argoproj-labs/argocd-operator/api/v1alpha1"
"github.com/argoproj-labs/argocd-operator/controllers/argoutil"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

"github.com/argoproj-labs/argocd-operator/api/v1alpha1"
"github.com/argoproj-labs/argocd-operator/controllers/argoutil"
)

const (
Expand Down
Loading