From 22e6528f6388d9f6ed3b71983ca841ea5837f475 Mon Sep 17 00:00:00 2001 From: chaosi-zju Date: Fri, 24 Jan 2025 10:35:18 +0800 Subject: [PATCH] chore: format code about misspell,staticcheck,govet Signed-off-by: chaosi-zju --- cmd/api/app/routes/cluster/handler.go | 2 +- .../routes/clusteroverridepolicy/handler.go | 39 ------------------- .../clusterpropagationpolicy/handler.go | 2 +- cmd/api/app/routes/overridepolicy/handler.go | 2 +- cmd/api/app/routes/overview/misc.go | 2 +- .../app/routes/propagationpolicy/handler.go | 2 +- hack/verify-staticcheck.sh | 2 +- pkg/client/init.go | 4 +- pkg/config/config.go | 2 +- pkg/resource/cronjob/jobs.go | 2 - 10 files changed, 9 insertions(+), 50 deletions(-) diff --git a/cmd/api/app/routes/cluster/handler.go b/cmd/api/app/routes/cluster/handler.go index dc044966..f592cd9d 100644 --- a/cmd/api/app/routes/cluster/handler.go +++ b/cmd/api/app/routes/cluster/handler.go @@ -205,7 +205,7 @@ func handleDeleteCluster(c *gin.Context) { } // make sure the given cluster object has been deleted - err = wait.Poll(1*time.Second, waitDuration, func() (done bool, err error) { + err = wait.PollUntilContextTimeout(ctx, 1*time.Second, waitDuration, true, func(ctx context.Context) (done bool, err error) { _, err = karmadaClient.ClusterV1alpha1().Clusters().Get(ctx, clusterName, metav1.GetOptions{}) if apierrors.IsNotFound(err) { return true, nil diff --git a/cmd/api/app/routes/clusteroverridepolicy/handler.go b/cmd/api/app/routes/clusteroverridepolicy/handler.go index e46d0fde..ede1c92f 100644 --- a/cmd/api/app/routes/clusteroverridepolicy/handler.go +++ b/cmd/api/app/routes/clusteroverridepolicy/handler.go @@ -22,7 +22,6 @@ import ( "github.com/gin-gonic/gin" "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/client-go/util/retry" "k8s.io/klog/v2" "sigs.k8s.io/yaml" @@ -30,7 +29,6 @@ import ( v1 "github.com/karmada-io/dashboard/cmd/api/app/types/api/v1" "github.com/karmada-io/dashboard/cmd/api/app/types/common" "github.com/karmada-io/dashboard/pkg/client" - "github.com/karmada-io/dashboard/pkg/common/errors" "github.com/karmada-io/dashboard/pkg/resource/clusteroverridepolicy" ) @@ -135,43 +133,6 @@ func handlePutClusterOverridePolicy(c *gin.Context) { common.Success(c, "ok") } -func handleDeleteClusterOverridePolicy(c *gin.Context) { - ctx := context.Context(c) - overridepolicyRequest := new(v1.DeleteOverridePolicyRequest) - if err := c.ShouldBind(&overridepolicyRequest); err != nil { - common.Fail(c, err) - return - } - var err error - karmadaClient := client.InClusterKarmadaClient() - if overridepolicyRequest.IsClusterScope { - err = karmadaClient.PolicyV1alpha1().ClusterOverridePolicies().Delete(ctx, overridepolicyRequest.Name, metav1.DeleteOptions{}) - if err != nil { - klog.ErrorS(err, "Failed to delete ClusterOverridePolicy") - common.Fail(c, err) - return - } - } else { - err = karmadaClient.PolicyV1alpha1().OverridePolicies(overridepolicyRequest.Namespace).Delete(ctx, overridepolicyRequest.Name, metav1.DeleteOptions{}) - if err != nil { - klog.ErrorS(err, "Failed to delete OverridePolicy") - common.Fail(c, err) - return - } - err = retry.OnError( - retry.DefaultRetry, - func(err error) bool { - return errors.IsNotFound(err) - }, - func() error { - _, getErr := karmadaClient.PolicyV1alpha1().OverridePolicies(overridepolicyRequest.Namespace).Get(ctx, overridepolicyRequest.Name, metav1.GetOptions{}) - return getErr - }) - } - - common.Success(c, "ok") -} - func init() { r := router.V1() r.GET("/clusteroverridepolicy", handleGetClusterOverridePolicyList) diff --git a/cmd/api/app/routes/clusterpropagationpolicy/handler.go b/cmd/api/app/routes/clusterpropagationpolicy/handler.go index fd4ccfbc..f8bcac01 100644 --- a/cmd/api/app/routes/clusterpropagationpolicy/handler.go +++ b/cmd/api/app/routes/clusterpropagationpolicy/handler.go @@ -157,7 +157,7 @@ func handleDeleteClusterPropagationPolicy(c *gin.Context) { common.Fail(c, err) return } - err = retry.OnError( + _ = retry.OnError( retry.DefaultRetry, func(err error) bool { return errors.IsNotFound(err) diff --git a/cmd/api/app/routes/overridepolicy/handler.go b/cmd/api/app/routes/overridepolicy/handler.go index d1136001..8a0e309f 100644 --- a/cmd/api/app/routes/overridepolicy/handler.go +++ b/cmd/api/app/routes/overridepolicy/handler.go @@ -161,7 +161,7 @@ func handleDeleteOverridePolicy(c *gin.Context) { common.Fail(c, err) return } - err = retry.OnError( + _ = retry.OnError( retry.DefaultRetry, func(err error) bool { return errors.IsNotFound(err) diff --git a/cmd/api/app/routes/overview/misc.go b/cmd/api/app/routes/overview/misc.go index 5032cb25..be781721 100644 --- a/cmd/api/app/routes/overview/misc.go +++ b/cmd/api/app/routes/overview/misc.go @@ -80,7 +80,7 @@ func GetControllerManagerVersionInfo() (*version.Info, error) { return nil, err } var stdout, stderr bytes.Buffer - err = executor.Stream(remotecommand.StreamOptions{ + err = executor.StreamWithContext(context.TODO(), remotecommand.StreamOptions{ Stdout: &stdout, Stderr: &stderr, Tty: false, diff --git a/cmd/api/app/routes/propagationpolicy/handler.go b/cmd/api/app/routes/propagationpolicy/handler.go index 2bb2e893..bdab707a 100644 --- a/cmd/api/app/routes/propagationpolicy/handler.go +++ b/cmd/api/app/routes/propagationpolicy/handler.go @@ -161,7 +161,7 @@ func handleDeletePropagationPolicy(c *gin.Context) { common.Fail(c, err) return } - err = retry.OnError( + _ = retry.OnError( retry.DefaultRetry, func(err error) bool { return errors.IsNotFound(err) diff --git a/hack/verify-staticcheck.sh b/hack/verify-staticcheck.sh index a10741cc..e489a4c8 100755 --- a/hack/verify-staticcheck.sh +++ b/hack/verify-staticcheck.sh @@ -32,7 +32,7 @@ else curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VER} fi -if golangci-lint run --enable-only goimports,gci,whitespace; then +if golangci-lint run --enable-only goimports,gci,whitespace,misspell,staticcheck,govet; then echo 'Congratulations! All Go source files have passed staticcheck.' else echo # print one empty line, separate from warning messages. diff --git a/pkg/client/init.go b/pkg/client/init.go index 1dc534cf..cc67e5af 100644 --- a/pkg/client/init.go +++ b/pkg/client/init.go @@ -129,7 +129,7 @@ func isKubeInitialized() bool { func InitKubeConfig(options ...Option) { builder := newConfigBuilder(options...) - // prefer InClusterConfig, if something wrong, use explict kubeconfig path + // prefer InClusterConfig, if something wrong, use explicit kubeconfig path restConfig, err := rest.InClusterConfig() if err == nil { klog.Infof("InitKubeConfig by InClusterConfig method") @@ -141,7 +141,7 @@ func InitKubeConfig(options ...Option) { kubernetesApiConfig = apiConfig } else { klog.Infof("InClusterConfig error: %+v", err) - klog.Infof("InitKubeConfig by explict kubeconfig path") + klog.Infof("InitKubeConfig by explicit kubeconfig path") restConfig, err = builder.buildRestConfig() if err != nil { klog.Errorf("Could not init client config: %s", err) diff --git a/pkg/config/config.go b/pkg/config/config.go index 70306818..ebdb9408 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -79,7 +79,7 @@ func InitDashboardConfig(k8sClient kubernetes.Interface, stopper <-chan struct{} } onUpdate := func(oldObj, newObj interface{}) { newConfigMap := newObj.(*v1.ConfigMap) - klog.V(2).Info("ConfigMap %s Updated\n", newConfigMap.Name) + klog.V(2).Infof("ConfigMap %s Updated", newConfigMap.Name) var tmpConfig DashboardConfig if err := yaml.Unmarshal([]byte(newConfigMap.Data[GetConfigKey()]), &tmpConfig); err != nil { klog.Errorf("Failed to unmarshal ConfigMap %s: %v", newConfigMap.Name, err) diff --git a/pkg/resource/cronjob/jobs.go b/pkg/resource/cronjob/jobs.go index a4f68b88..b03f3236 100644 --- a/pkg/resource/cronjob/jobs.go +++ b/pkg/resource/cronjob/jobs.go @@ -154,8 +154,6 @@ func filterJobsByState(active bool, jobs []batch.Job) (matchingJobs []batch.Job) matchingJobs = append(matchingJobs, j) } else if !active && j.Status.Active == 0 { matchingJobs = append(matchingJobs, j) - } else { - //sup } } return