Skip to content

Commit 60d2fad

Browse files
committed
chore: format code about revive stuttering check
Signed-off-by: chaosi-zju <[email protected]>
1 parent 7449a76 commit 60d2fad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+335
-336
lines changed

.golangci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ linters-settings:
7070
- name: dot-imports
7171
- name: errorf
7272
- name: exported
73-
arguments: ["disableStutteringCheck"] # TODO Temporarily disable stuttering check
7473
- name: var-declaration
7574
- name: blank-imports
7675
- name: indent-error-flow

cmd/api/app/routes/namespace/handler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func handleCreateNamespace(c *gin.Context) {
3434
common.Fail(c, err)
3535
return
3636
}
37-
spec := &ns.NamespaceSpec{
37+
spec := &ns.Spec{
3838
Name: createNamespaceRequest.Name,
3939
SkipAutoPropagation: createNamespaceRequest.SkipAutoPropagation,
4040
}

cmd/api/app/routes/overview/misc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func GetControllerManagerInfo() (*v1.KarmadaInfo, error) {
161161
}
162162

163163
// GetMemberClusterInfo returns the status of member clusters.
164-
func GetMemberClusterInfo(ds *dataselect.DataSelectQuery) (*v1.MemberClusterStatus, error) {
164+
func GetMemberClusterInfo(ds *dataselect.Query) (*v1.MemberClusterStatus, error) {
165165
karmadaClient := client.InClusterKarmadaClient()
166166
result, err := cluster.GetClusterList(karmadaClient, ds)
167167
if err != nil {

cmd/api/app/types/common/request.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ func parseSortPathParameter(request *gin.Context) *dataselect.SortQuery {
5050
return dataselect.NewSortQuery(strings.Split(request.Query("sortBy"), ","))
5151
}
5252

53-
// ParseDataSelectPathParameter parses query parameters of the request and returns a DataSelectQuery object
54-
func ParseDataSelectPathParameter(request *gin.Context) *dataselect.DataSelectQuery {
53+
// ParseDataSelectPathParameter parses query parameters of the request and returns a Query object
54+
func ParseDataSelectPathParameter(request *gin.Context) *dataselect.Query {
5555
paginationQuery := parsePaginationPathParameter(request)
5656
sortQuery := parseSortPathParameter(request)
5757
filterQuery := parseFilterPathParameter(request)

hack/verify-staticcheck.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ else
3232
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VER}
3333
fi
3434

35-
if golangci-lint run --enable-only goimports,gci,whitespace,misspell,staticcheck,govet,errcheck,gosimple,ineffassign,unused,gocyclo,gosec,revive; then
35+
if golangci-lint run; then
3636
echo 'Congratulations! All Go source files have passed staticcheck.'
3737
else
3838
echo # print one empty line, separate from warning messages.

pkg/dataselect/dataselect.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type DataSelector struct {
4343
// GenericDataList hold generic data cells that are being selected.
4444
GenericDataList []DataCell
4545
// DataSelectQuery holds instructions for data select.
46-
DataSelectQuery *DataSelectQuery
46+
DataSelectQuery *Query
4747
}
4848

4949
// Implementation of sort.Interface so that we can use built-in sort function (sort.Sort) for sorting SelectableData
@@ -74,13 +74,13 @@ func (s DataSelector) Less(i, j int) bool {
7474
return false
7575
}
7676

77-
// Sort sorts the data inside as instructed by DataSelectQuery and returns itself to allow method chaining.
77+
// Sort sorts the data inside as instructed by Query and returns itself to allow method chaining.
7878
func (s *DataSelector) Sort() *DataSelector {
7979
sort.Sort(*s)
8080
return s
8181
}
8282

83-
// Filter the data inside as instructed by DataSelectQuery and returns itself to allow method chaining.
83+
// Filter the data inside as instructed by Query and returns itself to allow method chaining.
8484
func (s *DataSelector) Filter() *DataSelector {
8585
filteredList := []DataCell{}
8686

@@ -102,7 +102,7 @@ func (s *DataSelector) Filter() *DataSelector {
102102
return s
103103
}
104104

105-
// Paginate paginates the data inside as instructed by DataSelectQuery and returns itself to allow method chaining.
105+
// Paginate paginates the data inside as instructed by Query and returns itself to allow method chaining.
106106
func (s *DataSelector) Paginate() *DataSelector {
107107
pQuery := s.DataSelectQuery.PaginationQuery
108108
dataList := s.GenericDataList
@@ -122,17 +122,17 @@ func (s *DataSelector) Paginate() *DataSelector {
122122
return s
123123
}
124124

125-
// GenericDataSelect takes a list of GenericDataCells and DataSelectQuery and returns selected data as instructed by dsQuery.
126-
func GenericDataSelect(dataList []DataCell, dsQuery *DataSelectQuery) []DataCell {
125+
// GenericDataSelect takes a list of GenericDataCells and Query and returns selected data as instructed by dsQuery.
126+
func GenericDataSelect(dataList []DataCell, dsQuery *Query) []DataCell {
127127
SelectableData := DataSelector{
128128
GenericDataList: dataList,
129129
DataSelectQuery: dsQuery,
130130
}
131131
return SelectableData.Sort().Paginate().GenericDataList
132132
}
133133

134-
// GenericDataSelectWithFilter takes a list of GenericDataCells and DataSelectQuery and returns selected data as instructed by dsQuery.
135-
func GenericDataSelectWithFilter(dataList []DataCell, dsQuery *DataSelectQuery) ([]DataCell, int) {
134+
// GenericDataSelectWithFilter takes a list of GenericDataCells and Query and returns selected data as instructed by dsQuery.
135+
func GenericDataSelectWithFilter(dataList []DataCell, dsQuery *Query) ([]DataCell, int) {
136136
SelectableData := DataSelector{
137137
GenericDataList: dataList,
138138
DataSelectQuery: dsQuery,

pkg/dataselect/dataselect_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func TestSort(t *testing.T) {
143143
for _, testCase := range testCases {
144144
selectableData := DataSelector{
145145
GenericDataList: getDataCellList(),
146-
DataSelectQuery: &DataSelectQuery{SortQuery: testCase.SortQuery},
146+
DataSelectQuery: &Query{SortQuery: testCase.SortQuery},
147147
}
148148
sortedData := fromCells(selectableData.Sort().GenericDataList)
149149
order := getOrder(sortedData)
@@ -210,7 +210,7 @@ func TestPagination(t *testing.T) {
210210
for _, testCase := range testCases {
211211
selectableData := DataSelector{
212212
GenericDataList: getDataCellList(),
213-
DataSelectQuery: &DataSelectQuery{PaginationQuery: testCase.PaginationQuery},
213+
DataSelectQuery: &Query{PaginationQuery: testCase.PaginationQuery},
214214
}
215215
paginatedData := fromCells(selectableData.Paginate().GenericDataList)
216216
order := getOrder(paginatedData)

pkg/dataselect/dataselectquery.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
package dataselect
1616

17-
// DataSelectQuery is options for GenericDataSelect which takes []GenericDataCell and returns selected data.
17+
// Query is options for GenericDataSelect which takes []GenericDataCell and returns selected data.
1818
// Can be extended to include any kind of selection - for example filtering.
1919
// Currently included only Pagination and Sort options.
20-
type DataSelectQuery struct {
20+
type Query struct {
2121
// PaginationQuery holds options for pagination of data select.
2222
PaginationQuery *PaginationQuery
2323
// SortQuery holds options for sort functionality of data select.
@@ -72,9 +72,9 @@ var NoFilter = &FilterQuery{
7272
// NoDataSelect is an option for no data select (same data will be returned).
7373
var NoDataSelect = NewDataSelectQuery(NoPagination, NoSort, NoFilter)
7474

75-
// NewDataSelectQuery creates DataSelectQuery object from simpler data select queries.
76-
func NewDataSelectQuery(paginationQuery *PaginationQuery, sortQuery *SortQuery, filterQuery *FilterQuery) *DataSelectQuery {
77-
return &DataSelectQuery{
75+
// NewDataSelectQuery creates Query object from simpler data select queries.
76+
func NewDataSelectQuery(paginationQuery *PaginationQuery, sortQuery *SortQuery, filterQuery *FilterQuery) *Query {
77+
return &Query{
7878
PaginationQuery: paginationQuery,
7979
SortQuery: sortQuery,
8080
FilterQuery: filterQuery,

pkg/resource/cluster/cluster.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,25 @@ import (
3232

3333
// Cluster the definition of a cluster.
3434
type Cluster struct {
35-
ObjectMeta types.ObjectMeta `json:"objectMeta"`
36-
TypeMeta types.TypeMeta `json:"typeMeta"`
37-
Ready metav1.ConditionStatus `json:"ready"`
38-
KubernetesVersion string `json:"kubernetesVersion,omitempty"`
39-
SyncMode v1alpha1.ClusterSyncMode `json:"syncMode"`
40-
NodeSummary *v1alpha1.NodeSummary `json:"nodeSummary,omitempty"`
41-
AllocatedResources ClusterAllocatedResources `json:"allocatedResources"`
35+
ObjectMeta types.ObjectMeta `json:"objectMeta"`
36+
TypeMeta types.TypeMeta `json:"typeMeta"`
37+
Ready metav1.ConditionStatus `json:"ready"`
38+
KubernetesVersion string `json:"kubernetesVersion,omitempty"`
39+
SyncMode v1alpha1.ClusterSyncMode `json:"syncMode"`
40+
NodeSummary *v1alpha1.NodeSummary `json:"nodeSummary,omitempty"`
41+
AllocatedResources AllocatedResources `json:"allocatedResources"`
4242
}
4343

44-
// ClusterList contains a list of clusters.
45-
type ClusterList struct {
44+
// List contains a list of clusters.
45+
type List struct {
4646
ListMeta types.ListMeta `json:"listMeta"`
4747
Clusters []Cluster `json:"clusters"`
4848
// List of non-critical errors, that occurred during resource retrieval.
4949
Errors []error `json:"errors"`
5050
}
5151

5252
// GetClusterList returns a list of all Nodes in the cluster.
53-
func GetClusterList(client karmadaclientset.Interface, dsQuery *dataselect.DataSelectQuery) (*ClusterList, error) {
53+
func GetClusterList(client karmadaclientset.Interface, dsQuery *dataselect.Query) (*List, error) {
5454
clusters, err := client.ClusterV1alpha1().Clusters().List(context.TODO(), helpers.ListEverything)
5555
nonCriticalErrors, criticalError := errors.ExtractErrors(err)
5656
if criticalError != nil {
@@ -59,8 +59,8 @@ func GetClusterList(client karmadaclientset.Interface, dsQuery *dataselect.DataS
5959
return toClusterList(client, clusters.Items, nonCriticalErrors, dsQuery), nil
6060
}
6161

62-
func toClusterList(_ karmadaclientset.Interface, clusters []v1alpha1.Cluster, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *ClusterList {
63-
clusterList := &ClusterList{
62+
func toClusterList(_ karmadaclientset.Interface, clusters []v1alpha1.Cluster, nonCriticalErrors []error, dsQuery *dataselect.Query) *List {
63+
clusterList := &List{
6464
Clusters: make([]Cluster, 0),
6565
ListMeta: types.ListMeta{TotalItems: len(clusters)},
6666
Errors: nonCriticalErrors,
@@ -78,7 +78,7 @@ func toClusterList(_ karmadaclientset.Interface, clusters []v1alpha1.Cluster, no
7878
}
7979

8080
func toCluster(cluster *v1alpha1.Cluster) Cluster {
81-
allocatedResources, err := getclusterAllocatedResources(cluster)
81+
allocatedResources, err := getAllocatedResources(cluster)
8282
if err != nil {
8383
log.Printf("Couldn't get allocated resources of %s cluster: %s\n", cluster.Name, err)
8484
}

pkg/resource/cluster/common.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import (
2222
"github.com/karmada-io/dashboard/pkg/dataselect"
2323
)
2424

25-
// ClusterCell is a cell representation of Cluster object.
26-
type ClusterCell v1alpha1.Cluster
25+
// Cell is a cell representation of Cluster object.
26+
type Cell v1alpha1.Cluster
2727

2828
// GetProperty returns value of a given property.
29-
func (c ClusterCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue {
29+
func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue {
3030
switch name {
3131
case dataselect.NameProperty:
3232
return dataselect.StdComparableString(c.ObjectMeta.Name)
@@ -43,15 +43,15 @@ func (c ClusterCell) GetProperty(name dataselect.PropertyName) dataselect.Compar
4343
func toCells(std []v1alpha1.Cluster) []dataselect.DataCell {
4444
cells := make([]dataselect.DataCell, len(std))
4545
for i := range std {
46-
cells[i] = ClusterCell(std[i])
46+
cells[i] = Cell(std[i])
4747
}
4848
return cells
4949
}
5050

5151
func fromCells(cells []dataselect.DataCell) []v1alpha1.Cluster {
5252
std := make([]v1alpha1.Cluster, len(cells))
5353
for i := range std {
54-
std[i] = v1alpha1.Cluster(cells[i].(ClusterCell))
54+
std[i] = v1alpha1.Cluster(cells[i].(Cell))
5555
}
5656
return std
5757
}

pkg/resource/cluster/detail.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2929
)
3030

31-
// ClusterAllocatedResources is the resource summary of a cluster.
32-
type ClusterAllocatedResources struct {
31+
// AllocatedResources is the resource summary of a cluster.
32+
type AllocatedResources struct {
3333
// CPUCapacity is specified node CPU capacity in milicores.
3434
CPUCapacity int64 `json:"cpuCapacity"`
3535
CPUFraction float64 `json:"cpuFraction"`
@@ -48,9 +48,9 @@ type ClusterAllocatedResources struct {
4848
PodFraction float64 `json:"podFraction"`
4949
}
5050

51-
func getclusterAllocatedResources(cluster *v1alpha1.Cluster) (ClusterAllocatedResources, error) {
51+
func getAllocatedResources(cluster *v1alpha1.Cluster) (AllocatedResources, error) {
5252
if cluster.Status.ResourceSummary == nil {
53-
return ClusterAllocatedResources{}, nil
53+
return AllocatedResources{}, nil
5454
}
5555
allocatableCPU := cluster.Status.ResourceSummary.Allocatable.Cpu()
5656
allocatedCPU := cluster.Status.ResourceSummary.Allocated.Cpu()
@@ -78,7 +78,7 @@ func getclusterAllocatedResources(cluster *v1alpha1.Cluster) (ClusterAllocatedRe
7878
if podCapacity > 0 {
7979
podFraction = float64(allocatedPod.Value()) / float64(podCapacity) * 100
8080
}
81-
return ClusterAllocatedResources{
81+
return AllocatedResources{
8282
CPUCapacity: allocatableCPU.Value(),
8383
CPUFraction: cpuFraction,
8484
MemoryCapacity: allocatedMemory.Value(),
@@ -89,20 +89,20 @@ func getclusterAllocatedResources(cluster *v1alpha1.Cluster) (ClusterAllocatedRe
8989
}, nil
9090
}
9191

92-
// ClusterDetail is the detailed information of a cluster.
93-
type ClusterDetail struct {
92+
// Detail is the detailed information of a cluster.
93+
type Detail struct {
9494
Cluster `json:",inline"`
9595
Taints []corev1.Taint `json:"taints,omitempty"`
9696
}
9797

9898
// GetClusterDetail gets details of cluster.
99-
func GetClusterDetail(client karmadaclientset.Interface, clusterName string) (*ClusterDetail, error) {
99+
func GetClusterDetail(client karmadaclientset.Interface, clusterName string) (*Detail, error) {
100100
log.Printf("Getting details of %s cluster", clusterName)
101101
cluster, err := client.ClusterV1alpha1().Clusters().Get(context.TODO(), clusterName, metav1.GetOptions{})
102102
if err != nil {
103103
return nil, err
104104
}
105-
return &ClusterDetail{
105+
return &Detail{
106106
Cluster: toCluster(cluster),
107107
Taints: cluster.Spec.Taints,
108108
}, nil

pkg/resource/clusteroverridepolicy/common.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import (
2222
"github.com/karmada-io/dashboard/pkg/dataselect"
2323
)
2424

25-
// ClusterOverridePolicyCell wraps v1alpha1.ClusterOverridePolicy for data selection.
26-
type ClusterOverridePolicyCell v1alpha1.ClusterOverridePolicy
25+
// Cell wraps v1alpha1.ClusterOverridePolicy for data selection.
26+
type Cell v1alpha1.ClusterOverridePolicy
2727

2828
// GetProperty returns a property of the cluster override policy cell.
29-
func (c ClusterOverridePolicyCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue {
29+
func (c Cell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue {
3030
switch name {
3131
case dataselect.NameProperty:
3232
return dataselect.StdComparableString(c.ObjectMeta.Name)
@@ -41,15 +41,15 @@ func (c ClusterOverridePolicyCell) GetProperty(name dataselect.PropertyName) dat
4141
func toCells(std []v1alpha1.ClusterOverridePolicy) []dataselect.DataCell {
4242
cells := make([]dataselect.DataCell, len(std))
4343
for i := range std {
44-
cells[i] = ClusterOverridePolicyCell(std[i])
44+
cells[i] = Cell(std[i])
4545
}
4646
return cells
4747
}
4848

4949
func fromCells(cells []dataselect.DataCell) []v1alpha1.ClusterOverridePolicy {
5050
std := make([]v1alpha1.ClusterOverridePolicy, len(cells))
5151
for i := range std {
52-
std[i] = v1alpha1.ClusterOverridePolicy(cells[i].(ClusterOverridePolicyCell))
52+
std[i] = v1alpha1.ClusterOverridePolicy(cells[i].(Cell))
5353
}
5454
return std
5555
}

pkg/resource/clusteroverridepolicy/detail.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import (
2626
"github.com/karmada-io/dashboard/pkg/common/errors"
2727
)
2828

29-
// ClusterOverridePolicyDetail contains clusterPropagationPolicy details and non-critical errors.
30-
type ClusterOverridePolicyDetail struct {
29+
// Detail contains clusterPropagationPolicy details and non-critical errors.
30+
type Detail struct {
3131
// Extends list item structure.
3232
ClusterOverridePolicy `json:",inline"`
3333

@@ -36,7 +36,7 @@ type ClusterOverridePolicyDetail struct {
3636
}
3737

3838
// GetClusterOverridePolicyDetail gets clusterPropagationPolicy details.
39-
func GetClusterOverridePolicyDetail(client karmadaclientset.Interface, name string) (*ClusterOverridePolicyDetail, error) {
39+
func GetClusterOverridePolicyDetail(client karmadaclientset.Interface, name string) (*Detail, error) {
4040
overridepolicyData, err := client.PolicyV1alpha1().ClusterOverridePolicies().Get(context.TODO(), name, metaV1.GetOptions{})
4141
if err != nil {
4242
return nil, err
@@ -51,8 +51,8 @@ func GetClusterOverridePolicyDetail(client karmadaclientset.Interface, name stri
5151
return &propagationpolicy, nil
5252
}
5353

54-
func toOverridePolicyDetail(clusterOverridepolicy *v1alpha1.ClusterOverridePolicy, nonCriticalErrors []error) ClusterOverridePolicyDetail {
55-
return ClusterOverridePolicyDetail{
54+
func toOverridePolicyDetail(clusterOverridepolicy *v1alpha1.ClusterOverridePolicy, nonCriticalErrors []error) Detail {
55+
return Detail{
5656
ClusterOverridePolicy: toClusterOverridePolicy(clusterOverridepolicy),
5757
Errors: nonCriticalErrors,
5858
}

pkg/resource/clusteroverridepolicy/list.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828
"github.com/karmada-io/dashboard/pkg/dataselect"
2929
)
3030

31-
// ClusterOverridePolicyList contains a list of overriders in the karmada control-plane.
32-
type ClusterOverridePolicyList struct {
31+
// List contains a list of overriders in the karmada control-plane.
32+
type List struct {
3333
ListMeta types.ListMeta `json:"listMeta"`
3434

3535
// Unordered list of clusterOverridePolicies.
@@ -49,7 +49,7 @@ type ClusterOverridePolicy struct {
4949
}
5050

5151
// GetClusterOverridePolicyList returns a list of all overiders in the karmada control-plance.
52-
func GetClusterOverridePolicyList(client karmadaclientset.Interface, dsQuery *dataselect.DataSelectQuery) (*ClusterOverridePolicyList, error) {
52+
func GetClusterOverridePolicyList(client karmadaclientset.Interface, dsQuery *dataselect.Query) (*List, error) {
5353
clusterOverridePolicies, err := client.PolicyV1alpha1().ClusterOverridePolicies().List(context.TODO(), helpers.ListEverything)
5454
nonCriticalErrors, criticalError := errors.ExtractErrors(err)
5555
if criticalError != nil {
@@ -59,8 +59,8 @@ func GetClusterOverridePolicyList(client karmadaclientset.Interface, dsQuery *da
5959
return toClusterOverridePolicyList(clusterOverridePolicies.Items, nonCriticalErrors, dsQuery), nil
6060
}
6161

62-
func toClusterOverridePolicyList(clusterOverridePolicies []v1alpha1.ClusterOverridePolicy, nonCriticalErrors []error, dsQuery *dataselect.DataSelectQuery) *ClusterOverridePolicyList {
63-
overridepolicyList := &ClusterOverridePolicyList{
62+
func toClusterOverridePolicyList(clusterOverridePolicies []v1alpha1.ClusterOverridePolicy, nonCriticalErrors []error, dsQuery *dataselect.Query) *List {
63+
overridepolicyList := &List{
6464
ClusterOverridePolicies: make([]ClusterOverridePolicy, 0),
6565
ListMeta: types.ListMeta{TotalItems: len(clusterOverridePolicies)},
6666
}

0 commit comments

Comments
 (0)