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: format code about misspell,staticcheck,govet #181

Merged
merged 1 commit into from
Jan 24, 2025
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
2 changes: 1 addition & 1 deletion cmd/api/app/routes/cluster/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 0 additions & 39 deletions cmd/api/app/routes/clusteroverridepolicy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ 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"

"github.com/karmada-io/dashboard/cmd/api/app/router"
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"
)

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/api/app/routes/clusterpropagationpolicy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/api/app/routes/overridepolicy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/api/app/routes/overview/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
chaosi-zju marked this conversation as resolved.
Show resolved Hide resolved
Stdout: &stdout,
Stderr: &stderr,
Tty: false,
Expand Down
2 changes: 1 addition & 1 deletion cmd/api/app/routes/propagationpolicy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion hack/verify-staticcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
chaosi-zju marked this conversation as resolved.
Show resolved Hide resolved
restConfig, err := rest.InClusterConfig()
if err == nil {
klog.Infof("InitKubeConfig by InClusterConfig method")
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions pkg/resource/cronjob/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down