Skip to content

Commit

Permalink
run: gofumpt -w -extra .
Browse files Browse the repository at this point in the history
Enable gofumpt in golangci

Signed-off-by: Furkan <furkan.turkal@trendyol.com>
  • Loading branch information
Dentrax committed Sep 30, 2022
1 parent 7c7e1b9 commit f80910f
Show file tree
Hide file tree
Showing 56 changed files with 154 additions and 115 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ linters:
disable-all: true
enable:
- gofmt
- gofumpt
- gosimple
- gocyclo
- misspell
- govet

linters-settings:
gofumpt:
extra-rules: true
goimports:
local-prefixes: sigs.k8s.io/descheduler
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ LDFLAGS=-ldflags "-X ${LDFLAG_LOCATION}.version=${VERSION} -X ${LDFLAG_LOCATION}
GOLANGCI_VERSION := v1.49.0
HAS_GOLANGCI := $(shell ls _output/bin/golangci-lint 2> /dev/null)

GOFUMPT_VERSION := v0.4.0
HAS_GOFUMPT := $(shell command -v gofumpt 2> /dev/null)

# REGISTRY is the container registry to push
# into. The default is to push to the staging
# registry, not production.
Expand Down Expand Up @@ -137,6 +140,12 @@ ifndef HAS_GOLANGCI
endif
./_output/bin/golangci-lint run

fmt:
ifndef HAS_GOFUMPT
go install mvdan.cc/gofumpt@${GOFUMPT_VERSION}
endif
gofumpt -w -extra .

# helm

ensure-helm-install:
Expand Down
1 change: 0 additions & 1 deletion cmd/descheduler/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (
// NewDeschedulerCommand creates a *cobra.Command object with default parameters
func NewDeschedulerCommand(out io.Writer) *cobra.Command {
s, err := options.NewDeschedulerServer()

if err != nil {
klog.ErrorS(err, "unable to initialize server")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/descheduler/app/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func NewVersionCommand() *cobra.Command {
var versionCmd = &cobra.Command{
versionCmd := &cobra.Command{
Use: "version",
Short: "Version of descheduler",
Long: `Prints the version of descheduler.`,
Expand Down
7 changes: 7 additions & 0 deletions docs/contributor-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ make test-unit
make test-e2e
```

## Format Code

After making changes in the code base, ensure that the code is formatted correctly:

```
make fmt
```

## Build Helm Package locally

Expand Down
12 changes: 8 additions & 4 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ type DeschedulerPolicy struct {
MaxNoOfPodsToEvictPerNamespace *uint
}

type StrategyName string
type StrategyList map[StrategyName]DeschedulerStrategy
type (
StrategyName string
StrategyList map[StrategyName]DeschedulerStrategy
)

type DeschedulerStrategy struct {
// Enabled or disabled
Expand Down Expand Up @@ -93,8 +95,10 @@ type StrategyParameters struct {
ExcludedTaints []string
}

type Percentage float64
type ResourceThresholds map[v1.ResourceName]Percentage
type (
Percentage float64
ResourceThresholds map[v1.ResourceName]Percentage
)

type NodeResourceUtilizationThresholds struct {
UseDeviationThresholds bool
Expand Down
6 changes: 4 additions & 2 deletions pkg/api/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ var (
)

// GroupName is the group name used in this package
const GroupName = "descheduler"
const GroupVersion = "v1alpha1"
const (
GroupName = "descheduler"
GroupVersion = "v1alpha1"
)

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: GroupVersion}
Expand Down
12 changes: 8 additions & 4 deletions pkg/api/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ type DeschedulerPolicy struct {
MaxNoOfPodsToEvictPerNamespace *int `json:"maxNoOfPodsToEvictPerNamespace,omitempty"`
}

type StrategyName string
type StrategyList map[StrategyName]DeschedulerStrategy
type (
StrategyName string
StrategyList map[StrategyName]DeschedulerStrategy
)

type DeschedulerStrategy struct {
// Enabled or disabled
Expand Down Expand Up @@ -90,8 +92,10 @@ type StrategyParameters struct {
ExcludedTaints []string `json:"excludedTaints,omitempty"`
}

type Percentage float64
type ResourceThresholds map[v1.ResourceName]Percentage
type (
Percentage float64
ResourceThresholds map[v1.ResourceName]Percentage
)

type NodeResourceUtilizationThresholds struct {
UseDeviationThresholds bool `json:"useDeviationThresholds,omitempty"`
Expand Down
6 changes: 4 additions & 2 deletions pkg/apis/componentconfig/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ var (
)

// GroupName is the group name use in this package
const GroupName = "deschedulercomponentconfig"
const GroupVersion = "v1alpha1"
const (
GroupName = "deschedulercomponentconfig"
GroupVersion = "v1alpha1"
)

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: GroupVersion}
Expand Down
2 changes: 1 addition & 1 deletion pkg/descheduler/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"k8s.io/client-go/tools/clientcmd"
)

func CreateClient(kubeconfig string, userAgt string) (clientset.Interface, error) {
func CreateClient(kubeconfig, userAgt string) (clientset.Interface, error) {
var cfg *rest.Config
if len(kubeconfig) != 0 {
master, err := GetMasterFromKubeconfig(kubeconfig)
Expand Down
10 changes: 6 additions & 4 deletions pkg/descheduler/evictions/evictions.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ import (
)

// nodePodEvictedCount keeps count of pods evicted on node
type nodePodEvictedCount map[string]uint
type namespacePodEvictCount map[string]uint
type (
nodePodEvictedCount map[string]uint
namespacePodEvictCount map[string]uint
)

type PodEvictor struct {
client clientset.Interface
Expand All @@ -59,8 +61,8 @@ func NewPodEvictor(
metricsEnabled bool,
eventRecorder events.EventRecorder,
) *PodEvictor {
var nodePodCount = make(nodePodEvictedCount)
var namespacePodCount = make(namespacePodEvictCount)
nodePodCount := make(nodePodEvictedCount)
namespacePodCount := make(namespacePodEvictCount)
for _, node := range nodes {
// Initialize podsEvicted till now with 0.
nodePodCount[node.Name] = 0
Expand Down
6 changes: 3 additions & 3 deletions pkg/descheduler/evictions/evictions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestPodTypes(t *testing.T) {
p1.ObjectMeta.OwnerReferences = test.GetReplicaSetOwnerRefList()
// The following 4 pods won't get evicted.
// A daemonset.
//p2.Annotations = test.GetDaemonSetAnnotation()
// p2.Annotations = test.GetDaemonSetAnnotation()
p2.ObjectMeta.OwnerReferences = test.GetDaemonSetOwnerRefList()
// A pod with local storage.
p3.ObjectMeta.OwnerReferences = test.GetNormalPodOwnerRefList()
Expand All @@ -91,7 +91,8 @@ func TestPodTypes(t *testing.T) {
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{Path: "somePath"},
EmptyDir: &v1.EmptyDirVolumeSource{
SizeLimit: resource.NewQuantity(int64(10), resource.BinarySI)},
SizeLimit: resource.NewQuantity(int64(10), resource.BinarySI),
},
},
},
}
Expand All @@ -111,5 +112,4 @@ func TestPodTypes(t *testing.T) {
if utils.IsDaemonsetPod(ownerRefList) || utils.IsPodWithLocalStorage(p1) || utils.IsCriticalPriorityPod(p1) || utils.IsMirrorPod(p1) || utils.IsStaticPod(p1) {
t.Errorf("Expected p1 to be a normal pod.")
}

}
3 changes: 2 additions & 1 deletion pkg/descheduler/leaderelection.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ package descheduler
import (
"context"
"fmt"
"os"

"k8s.io/apimachinery/pkg/util/uuid"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/leaderelection"
"k8s.io/client-go/tools/leaderelection/resourcelock"
componentbaseconfig "k8s.io/component-base/config"
"k8s.io/klog/v2"
"os"
)

// NewLeaderElection starts the leader election code loop
Expand Down
5 changes: 1 addition & 4 deletions pkg/descheduler/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func TestReadyNodes(t *testing.T) {
if IsReady(node5) {
t.Errorf("Expected %v to be not ready", node5.Name)
}

}

func TestReadyNodesWithNodeSelector(t *testing.T) {
Expand Down Expand Up @@ -111,11 +110,9 @@ func TestIsNodeUnschedulable(t *testing.T) {
t.Errorf("Test %#v failed", test.description)
}
}

}

func TestPodFitsCurrentNode(t *testing.T) {

nodeLabelKey := "kubernetes.io/desiredNode"
nodeLabelValue := "yes"

Expand Down Expand Up @@ -756,7 +753,7 @@ func TestPodFitsAnyOtherNode(t *testing.T) {
}

// createResourceList builds a small resource list of core resources
func createResourceList(cpu int64, memory int64, ephemeralStorage int64) v1.ResourceList {
func createResourceList(cpu, memory, ephemeralStorage int64) v1.ResourceList {
resourceList := make(map[v1.ResourceName]resource.Quantity)
resourceList[v1.ResourceCPU] = *resource.NewMilliQuantity(cpu, resource.DecimalSI)
resourceList[v1.ResourceMemory] = *resource.NewQuantity(memory, resource.DecimalSI)
Expand Down
4 changes: 1 addition & 3 deletions pkg/descheduler/strategies/validation/strategyparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import (
"sigs.k8s.io/descheduler/pkg/api"
)

var (
thresholdPriority int32 = 1000
)
var thresholdPriority int32 = 1000

func TestValidStrategyParams(t *testing.T) {
ctx := context.Background()
Expand Down
7 changes: 7 additions & 0 deletions pkg/framework/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,31 @@ var _ framework.Handle = &HandleImpl{}
func (hi *HandleImpl) ClientSet() clientset.Interface {
return hi.ClientsetImpl
}

func (hi *HandleImpl) GetPodsAssignedToNodeFunc() podutil.GetPodsAssignedToNodeFunc {
return hi.GetPodsAssignedToNodeFuncImpl
}

func (hi *HandleImpl) SharedInformerFactory() informers.SharedInformerFactory {
return hi.SharedInformerFactoryImpl
}

func (hi *HandleImpl) Evictor() framework.Evictor {
return hi
}

func (hi *HandleImpl) Filter(pod *v1.Pod) bool {
return hi.EvictorFilterImpl.Filter(pod)
}

func (hi *HandleImpl) PreEvictionFilter(pod *v1.Pod) bool {
return hi.EvictorFilterImpl.PreEvictionFilter(pod)
}

func (hi *HandleImpl) Evict(ctx context.Context, pod *v1.Pod, opts evictions.EvictOptions) bool {
return hi.PodEvictorImpl.EvictPod(ctx, pod, opts)
}

func (hi *HandleImpl) NodeLimitExceeded(node *v1.Node) bool {
return hi.PodEvictorImpl.NodeLimitExceeded(node)
}
12 changes: 6 additions & 6 deletions pkg/framework/plugins/defaultevictor/defaultevictor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ func TestDefaultEvictorPreEvictionFilter(t *testing.T) {
}

for _, test := range testCases {

t.Run(test.description, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -474,7 +473,8 @@ func TestDefaultEvictorFilter(t *testing.T) {
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{Path: "somePath"},
EmptyDir: &v1.EmptyDirVolumeSource{
SizeLimit: resource.NewQuantity(int64(10), resource.BinarySI)},
SizeLimit: resource.NewQuantity(int64(10), resource.BinarySI),
},
},
},
}
Expand All @@ -494,7 +494,8 @@ func TestDefaultEvictorFilter(t *testing.T) {
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{Path: "somePath"},
EmptyDir: &v1.EmptyDirVolumeSource{
SizeLimit: resource.NewQuantity(int64(10), resource.BinarySI)},
SizeLimit: resource.NewQuantity(int64(10), resource.BinarySI),
},
},
},
}
Expand All @@ -515,7 +516,8 @@ func TestDefaultEvictorFilter(t *testing.T) {
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{Path: "somePath"},
EmptyDir: &v1.EmptyDirVolumeSource{
SizeLimit: resource.NewQuantity(int64(10), resource.BinarySI)},
SizeLimit: resource.NewQuantity(int64(10), resource.BinarySI),
},
},
},
}
Expand Down Expand Up @@ -706,7 +708,6 @@ func TestDefaultEvictorFilter(t *testing.T) {
}

for _, test := range testCases {

t.Run(test.description, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -758,7 +759,6 @@ func TestDefaultEvictorFilter(t *testing.T) {
if (result) != test.result {
t.Errorf("Filter should return for pod %s %t, but it returns %t", test.pods[0].Name, test.result, result)
}

})
}
}
3 changes: 2 additions & 1 deletion pkg/framework/plugins/defaultevictor/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ limitations under the License.
package defaultevictor

import (
"testing"

"github.com/google/go-cmp/cmp"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/utils/pointer"
"sigs.k8s.io/descheduler/pkg/api"
"testing"
)

func TestSetDefaults_DefaultEvictorArgs(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/framework/plugins/nodeutilization/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ limitations under the License.
package nodeutilization

import (
"testing"

"github.com/google/go-cmp/cmp"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"sigs.k8s.io/descheduler/pkg/api"
"testing"
)

func TestSetDefaults_LowNodeUtilizationArgs(t *testing.T) {
Expand Down
Loading

0 comments on commit f80910f

Please sign in to comment.