Skip to content

Commit

Permalink
chore: enable gofumpt linter
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgb committed Dec 31, 2024
1 parent 0918d33 commit becb4fb
Show file tree
Hide file tree
Showing 62 changed files with 150 additions and 163 deletions.
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ linters:
- gocritic
#- gocyclo
#- godot
#- gofumpt
- gofumpt
#- gosec
- gosimple
- govet
Expand Down
1 change: 0 additions & 1 deletion cmd/gitops-server/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ func runCmd(cmd *cobra.Command, args []string) error {

mux.Handle("/health/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := w.Write([]byte("ok"))

if err != nil {
log.Error(err, "error writing health check")
}
Expand Down
1 change: 0 additions & 1 deletion cmd/gitops/check/oidcconfig/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ gitops check oidc-config --skip-secret --client-id=CID --client-secret=SEC --iss
ClaimUsername: claimUsernameFlag,
ClaimGroups: claimGroupsFlag,
}, log, kubeClient)

if err != nil {
return fmt.Errorf("failed getting claims: %w", err)
}
Expand Down
3 changes: 0 additions & 3 deletions cmd/gitops/get/bcrypt/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func hashCommandRunE() func(*cobra.Command, []string) error {
return func(cmd *cobra.Command, args []string) error {
file := os.Stdin
stats, err := file.Stat()

if err != nil {
return err
}
Expand All @@ -41,7 +40,6 @@ func hashCommandRunE() func(*cobra.Command, []string) error {

if (stats.Mode() & os.ModeCharDevice) == 0 {
p, err = io.ReadAll(os.Stdin)

if err != nil {
return err
}
Expand All @@ -58,7 +56,6 @@ func hashCommandRunE() func(*cobra.Command, []string) error {
}

secret, err := bcrypt.GenerateFromPassword(p, bcrypt.DefaultCost)

if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/gitops/root/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func init() {
}

func RootCmd() *cobra.Command {
var rootCmd = &cobra.Command{
rootCmd := &cobra.Command{
Use: "gitops",
SilenceUsage: true,
SilenceErrors: true,
Expand Down
10 changes: 6 additions & 4 deletions cmd/gitops/version/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (
)

// Version is the current wego version
var Version = "v0.0.0"
var GitCommit = ""
var Branch = ""
var BuildTime = ""
var (
Version = "v0.0.0"
GitCommit = ""
Branch = ""
BuildTime = ""
)

var Cmd = &cobra.Command{
Use: "version",
Expand Down
2 changes: 1 addition & 1 deletion core/clustersmngr/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (c *clustersClient) ClusteredList(ctx context.Context, clist ClusteredObjec

wg.Add(1)

go func(clusterName string, nsName string, c client.Client, optsWithNamespace ...client.ListOption) {
go func(clusterName, nsName string, c client.Client, optsWithNamespace ...client.ListOption) {
defer wg.Done()

list := clist.NewList()
Expand Down
2 changes: 1 addition & 1 deletion core/clustersmngr/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestClientClusteredListPagination(t *testing.T) {

clusterName := "mycluster"

createKust := func(name string, nsName string) {
createKust := func(name, nsName string) {
kust := &kustomizev1.Kustomization{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand Down
1 change: 0 additions & 1 deletion core/clustersmngr/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func getEnvDuration(key string, defaultDuration time.Duration) time.Duration {
}

d, err := time.ParseDuration(val)

// on error return the default duration
if err != nil {
return defaultDuration
Expand Down
1 change: 0 additions & 1 deletion core/clustersmngr/cluster/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ func TestMain(m *testing.M) {
"../../manifests/crds",
"../../tools/testcrds",
})

if err != nil {
panic(err)
}
Expand Down
5 changes: 1 addition & 4 deletions core/clustersmngr/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ const (
usersClientResolution = 30 * time.Second
)

var (
usersClientsTTL = getEnvDuration("WEAVE_GITOPS_USERS_CLIENTS_TTL", 30*time.Minute)
)
var usersClientsTTL = getEnvDuration("WEAVE_GITOPS_USERS_CLIENTS_TTL", 30*time.Minute)

func getEnvDuration(key string, defaultDuration time.Duration) time.Duration {
val := os.Getenv(key)
Expand All @@ -45,7 +43,6 @@ func getEnvDuration(key string, defaultDuration time.Duration) time.Duration {
}

d, err := time.ParseDuration(val)

// on error return the default duration
if err != nil {
return defaultDuration
Expand Down
1 change: 0 additions & 1 deletion core/clustersmngr/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func TestMain(m *testing.M) {
"../../manifests/crds",
"../../tools/testcrds",
})

if err != nil {
panic(err)
}
Expand Down
6 changes: 4 additions & 2 deletions core/fluxsync/fluxsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

var k8sPollInterval = 2 * time.Second
var k8sTimeout = 1 * time.Minute
var (
k8sPollInterval = 2 * time.Second
k8sTimeout = 1 * time.Minute
)

// RequestReconciliation sets the annotations of an object so that the flux controller(s) will force a reconciliation.
// Take straight from the flux CLI source:
Expand Down
3 changes: 2 additions & 1 deletion core/nsaccess/nsaccess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ func createRole(t *testing.T, cl client.Client, key types.NamespacedName, rules

binding := &rbacv1.RoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: "test-role-binding", Namespace: key.Namespace},
Name: "test-role-binding", Namespace: key.Namespace,
},
Subjects: []rbacv1.Subject{
{
Kind: "User",
Expand Down
1 change: 0 additions & 1 deletion core/server/fluxruntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ ItemsLoop:
tenant := GetTenant(obj.GetNamespace(), msg.ClusterName, clusterUserNamespaces)

obj, err := coretypes.K8sObjectToProto(&obj, msg.ClusterName, tenant, nil, "")

if err != nil {
respErrors = *multierror.Append(fmt.Errorf("error converting objects: %w", err), respErrors.Errors...)
continue
Expand Down
3 changes: 2 additions & 1 deletion core/server/fluxruntime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ func TestListRuntimeCrds(t *testing.T) {
}, Spec: apiextensions.CustomResourceDefinitionSpec{
Group: "group",
Names: apiextensions.CustomResourceDefinitionNames{Plural: "policies", Kind: "kind"},
Versions: []apiextensions.CustomResourceDefinitionVersion{}}},
Versions: []apiextensions.CustomResourceDefinitionVersion{},
}},
},
func(res *pb.ListRuntimeCrdsResponse) {
g.Expect(res.Crds).To(HaveLen(2))
Expand Down
1 change: 0 additions & 1 deletion core/server/helm_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func getHelmReleaseInventory(ctx context.Context, helmRelease helmv2.HelmRelease
}

objects, err := getHelmReleaseObjects(ctx, k8sClient, &helmRelease)

if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion core/server/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func getHelmReleaseObjects(ctx context.Context, k8sClient client.Client, helmRel
return nil, err
}

var magicGzip = []byte{0x1f, 0x8b, 0x08}
magicGzip := []byte{0x1f, 0x8b, 0x08}
if bytes.Equal(byteData[0:3], magicGzip) {
r, err := gzip.NewReader(bytes.NewReader(byteData))
if err != nil {
Expand Down
3 changes: 0 additions & 3 deletions core/server/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ func (cs *coreServer) sessionObjectsCreated(ctx context.Context, clusterName, ob
Kind: automationKind,
ClusterName: clusterName,
})

if err != nil {
return false, err
}
Expand All @@ -213,7 +212,6 @@ func (cs *coreServer) sessionObjectsCreated(ctx context.Context, clusterName, ob
Kind: "Bucket",
ClusterName: clusterName,
})

if err != nil {
return false, err
}
Expand Down Expand Up @@ -268,7 +266,6 @@ func (cs *coreServer) GetObject(ctx context.Context, msg *pb.GetObjectRequest) (
tenant := GetTenant(obj.GetNamespace(), msg.ClusterName, clusterUserNamespaces)

res, err := types.K8sObjectToProto(obj, msg.ClusterName, tenant, inventory, "")

if err != nil {
return nil, fmt.Errorf("converting object to proto: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions core/server/policy_violations.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func (cs *coreServer) ListPolicyValidations(ctx context.Context, m *pb.ListPolic
}

labelSelector, err := k8sLabels.ValidatedSelectorFromSet(map[string]string{
"pac.weave.works/type": validationType})

"pac.weave.works/type": validationType,
})
if err != nil {
return nil, fmt.Errorf("error building selector for events query: %v", err)
}
Expand Down Expand Up @@ -134,8 +134,8 @@ func (cs *coreServer) GetPolicyValidation(ctx context.Context, m *pb.GetPolicyVa

selector, err := k8sLabels.ValidatedSelectorFromSet(map[string]string{
"pac.weave.works/type": validationType,
"pac.weave.works/id": m.ValidationId})

"pac.weave.works/id": m.ValidationId,
})
if err != nil {
return nil, fmt.Errorf("error building selector for events query: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions core/server/primarykinds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func TestVersionRank(t *testing.T) {
gvk2 schema.GroupVersionKind
expected int
}{

{schema.GroupVersionKind{Version: "v1"}, schema.GroupVersionKind{Version: "v1alpha1"}, 1},
{schema.GroupVersionKind{Version: "v1"}, schema.GroupVersionKind{Version: "v1beta1"}, 1},
{schema.GroupVersionKind{Version: "v1"}, schema.GroupVersionKind{Version: "v1beta2"}, 1},
Expand Down Expand Up @@ -70,7 +69,8 @@ func TestGetPrimaryKinds(t *testing.T) {
{Group: "core", Version: "v2", Kind: "Pod"}: reflect.TypeOf(PodV2{}),
{Group: "core", Version: "v1alpha1", Kind: "Node"}: reflect.TypeOf(NodeV1a1{}),
{Group: "core", Version: "v1beta2", Kind: "Node"}: reflect.TypeOf(NodeV1b2{}),
{Group: "core", Version: "v1beta1", Kind: "Node"}: reflect.TypeOf(NodeV1b1{})},
{Group: "core", Version: "v1beta1", Kind: "Node"}: reflect.TypeOf(NodeV1b1{}),
},
}

primaryKinds, err := getPrimaryKinds(scheme)
Expand Down
7 changes: 4 additions & 3 deletions core/server/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ import (
"github.com/weaveworks/weave-gitops/pkg/testutils"
)

var k8sEnv *testutils.K8sTestEnv
var nsChecker nsaccessfakes.FakeChecker
var (
k8sEnv *testutils.K8sTestEnv
nsChecker nsaccessfakes.FakeChecker
)

func TestMain(m *testing.M) {
var err error
k8sEnv, err = testutils.StartK8sTestEnvironment([]string{
"../../manifests/crds",
"../../tools/testcrds",
})

if err != nil {
fmt.Fprintf(os.Stderr, "Failed to start test environment: %v\n", err)
os.Exit(1)
Expand Down
6 changes: 4 additions & 2 deletions core/server/suspend.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import (
"github.com/weaveworks/weave-gitops/pkg/server/auth"
)

const SuspendedByAnnotation = "metadata.weave.works/suspended-by"
const SuspendedCommentAnnotation = "metadata.weave.works/suspended-comment"
const (
SuspendedByAnnotation = "metadata.weave.works/suspended-by"
SuspendedCommentAnnotation = "metadata.weave.works/suspended-comment"
)

func (cs *coreServer) ToggleSuspendResource(ctx context.Context, msg *pb.ToggleSuspendResourceRequest) (*pb.ToggleSuspendResourceResponse, error) {
principal := auth.Principal(ctx)
Expand Down
7 changes: 4 additions & 3 deletions core/server/suspend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,17 @@ func TestSuspend_Suspend(t *testing.T) {
md := metadata.Pairs(MetadataUserKey, "anne", MetadataGroupsKey, "system:masters")
outgoingCtx := metadata.NewOutgoingContext(ctx, md)
_, err = c.ToggleSuspendResource(outgoingCtx, &api.ToggleSuspendResourceRequest{

Objects: []*api.ObjectRef{{
Kind: sourcev1.GitRepositoryKind,
Name: "fakeName",
Namespace: "fakeNamespace",
ClusterName: "Default",
}, {Kind: sourcev1.GitRepositoryKind,
}, {
Kind: sourcev1.GitRepositoryKind,
Name: "fakeName2",
Namespace: "fakeNamespace2",
ClusterName: "Default2"}},
ClusterName: "Default2",
}},
Suspend: true,
})

Expand Down
Loading

0 comments on commit becb4fb

Please sign in to comment.