Skip to content

Commit

Permalink
Merge pull request #780 from wzshiming/clean/code
Browse files Browse the repository at this point in the history
Clean up some code
  • Loading branch information
wzshiming authored Aug 23, 2023
2 parents baa0edf + bb435ba commit d8efe2c
Show file tree
Hide file tree
Showing 22 changed files with 734 additions and 380 deletions.
1 change: 1 addition & 0 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
version: v1.51.2
args: --timeout=30m --config=.golangci.yaml
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ linters-settings:
# Use sigs.k8s.io/kwok/pkg/utils/slices, which is a wrapper around slices
- k8s.io/utils/strings/slices: "please use `sigs.k8s.io/kwok/pkg/utils/slices` instead"
gocyclo:
min-complexity: 60
min-complexity: 50
gosec:
excludes:
- G110
Expand Down
12 changes: 12 additions & 0 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,15 @@ const (
RuntimeTypePodman = "podman"
RuntimeTypeBinary = "binary"
)

// The following components is provided.
const (
ComponentEtcd = "etcd"
ComponentKubeApiserver = "kube-apiserver"
ComponentKubeControllerManager = "kube-controller-manager"
ComponentKubeScheduler = "kube-scheduler"
ComponentKwokController = "kwok-controller"
ComponentDashboard = "dashboard"
ComponentPrometheus = "prometheus"
ComponentJaeger = "jaeger"
)
4 changes: 2 additions & 2 deletions pkg/kwok/server/debugging_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ func (s *Server) execInContainer(ctx context.Context, cmd []string, in io.Reader
}

func (s *Server) getExecTarget(podName, podNamespace string, containerName string) (*internalversion.ExecTarget, error) {
pf, has := slices.Find(s.execs.Get(), func(pf *internalversion.Exec) bool {
e, has := slices.Find(s.execs.Get(), func(pf *internalversion.Exec) bool {
return pf.Name == podName && pf.Namespace == podNamespace
})
if has {
exec, found := findContainerInExecs(containerName, pf.Spec.Execs)
exec, found := findContainerInExecs(containerName, e.Spec.Execs)
if found {
return exec, nil
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/kwokctl/components/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package components

import (
"sigs.k8s.io/kwok/pkg/apis/internalversion"
"sigs.k8s.io/kwok/pkg/consts"
"sigs.k8s.io/kwok/pkg/utils/format"
"sigs.k8s.io/kwok/pkg/utils/version"
)
Expand Down Expand Up @@ -101,10 +102,10 @@ func BuildDashboardComponent(conf BuildDashboardComponentConfig) (component inte
}

component = internalversion.Component{
Name: "dashboard",
Name: consts.ComponentDashboard,
Image: conf.Image,
Links: []string{
"kube-apiserver",
consts.ComponentKubeApiserver,
},
WorkDir: conf.Workdir,
Ports: ports,
Expand Down
5 changes: 3 additions & 2 deletions pkg/kwokctl/components/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"runtime"

"sigs.k8s.io/kwok/pkg/apis/internalversion"
"sigs.k8s.io/kwok/pkg/consts"
"sigs.k8s.io/kwok/pkg/log"
"sigs.k8s.io/kwok/pkg/utils/format"
"sigs.k8s.io/kwok/pkg/utils/version"
Expand Down Expand Up @@ -136,10 +137,10 @@ func BuildEtcdComponent(conf BuildEtcdComponentConfig) (component internalversio
envs = append(envs, conf.ExtraEnvs...)

return internalversion.Component{
Name: "etcd",
Name: consts.ComponentEtcd,
Version: conf.Version.String(),
Volumes: volumes,
Command: []string{"etcd"},
Command: []string{consts.ComponentEtcd},
Args: etcdArgs,
Binary: conf.Binary,
Ports: ports,
Expand Down
3 changes: 2 additions & 1 deletion pkg/kwokctl/components/jaeger.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package components

import (
"sigs.k8s.io/kwok/pkg/apis/internalversion"
"sigs.k8s.io/kwok/pkg/consts"
"sigs.k8s.io/kwok/pkg/log"
"sigs.k8s.io/kwok/pkg/utils/format"
"sigs.k8s.io/kwok/pkg/utils/net"
Expand Down Expand Up @@ -70,7 +71,7 @@ func BuildJaegerComponent(conf BuildJaegerComponentConfig) (component internalve
}

return internalversion.Component{
Name: "jaeger",
Name: consts.ComponentJaeger,
Version: conf.Version.String(),
Ports: ports,
Volumes: volumes,
Expand Down
9 changes: 5 additions & 4 deletions pkg/kwokctl/components/kube_apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"strings"

"sigs.k8s.io/kwok/pkg/apis/internalversion"
"sigs.k8s.io/kwok/pkg/consts"
"sigs.k8s.io/kwok/pkg/log"
"sigs.k8s.io/kwok/pkg/utils/format"
"sigs.k8s.io/kwok/pkg/utils/version"
Expand Down Expand Up @@ -257,16 +258,16 @@ func BuildKubeApiserverComponent(conf BuildKubeApiserverComponentConfig) (compon
envs := []internalversion.Env{}
envs = append(envs, conf.ExtraEnvs...)

links := []string{"etcd"}
links := []string{consts.ComponentEtcd}
if conf.TracingConfigPath != "" {
links = append(links, "jaeger")
links = append(links, consts.ComponentJaeger)
}

return internalversion.Component{
Name: "kube-apiserver",
Name: consts.ComponentKubeApiserver,
Version: conf.Version.String(),
Links: links,
Command: []string{"kube-apiserver"},
Command: []string{consts.ComponentKubeApiserver},
Ports: ports,
Volumes: volumes,
Args: kubeApiserverArgs,
Expand Down
6 changes: 3 additions & 3 deletions pkg/kwokctl/components/kube_controller_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ func BuildKubeControllerManagerComponent(conf BuildKubeControllerManagerComponen
envs = append(envs, conf.ExtraEnvs...)

return internalversion.Component{
Name: "kube-controller-manager",
Name: consts.ComponentKubeControllerManager,
Version: conf.Version.String(),
Links: []string{
"kube-apiserver",
consts.ComponentKubeApiserver,
},
Command: []string{"kube-controller-manager"},
Command: []string{consts.ComponentKubeControllerManager},
Volumes: volumes,
Args: kubeControllerManagerArgs,
Ports: ports,
Expand Down
6 changes: 3 additions & 3 deletions pkg/kwokctl/components/kube_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ func BuildKubeSchedulerComponent(conf BuildKubeSchedulerComponentConfig) (compon
envs = append(envs, conf.ExtraEnvs...)

return internalversion.Component{
Name: "kube-scheduler",
Name: consts.ComponentKubeScheduler,
Version: conf.Version.String(),
Links: []string{
"kube-apiserver",
consts.ComponentKubeApiserver,
},
Command: []string{"kube-scheduler"},
Command: []string{consts.ComponentKubeScheduler},
Volumes: volumes,
Args: kubeSchedulerArgs,
Binary: conf.Binary,
Expand Down
5 changes: 3 additions & 2 deletions pkg/kwokctl/components/kwok_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package components

import (
"sigs.k8s.io/kwok/pkg/apis/internalversion"
"sigs.k8s.io/kwok/pkg/consts"
"sigs.k8s.io/kwok/pkg/log"
"sigs.k8s.io/kwok/pkg/utils/format"
"sigs.k8s.io/kwok/pkg/utils/version"
Expand Down Expand Up @@ -124,10 +125,10 @@ func BuildKwokControllerComponent(conf BuildKwokControllerComponentConfig) (comp
envs = append(envs, conf.ExtraEnvs...)

return internalversion.Component{
Name: "kwok-controller",
Name: consts.ComponentKwokController,
Version: conf.Version.String(),
Links: []string{
"kube-apiserver",
consts.ComponentKubeApiserver,
},
Ports: ports,
Command: []string{"kwok"},
Expand Down
15 changes: 8 additions & 7 deletions pkg/kwokctl/components/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package components

import (
"sigs.k8s.io/kwok/pkg/apis/internalversion"
"sigs.k8s.io/kwok/pkg/consts"
"sigs.k8s.io/kwok/pkg/log"
"sigs.k8s.io/kwok/pkg/utils/format"
"sigs.k8s.io/kwok/pkg/utils/version"
Expand Down Expand Up @@ -92,16 +93,16 @@ func BuildPrometheusComponent(conf BuildPrometheusComponentConfig) (component in
envs = append(envs, conf.ExtraEnvs...)

return internalversion.Component{
Name: "prometheus",
Name: consts.ComponentPrometheus,
Version: conf.Version.String(),
Links: []string{
"etcd",
"kube-apiserver",
"kube-controller-manager",
"kube-scheduler",
"kwok-controller",
consts.ComponentEtcd,
consts.ComponentKubeApiserver,
consts.ComponentKubeControllerManager,
consts.ComponentKubeScheduler,
consts.ComponentKwokController,
},
Command: []string{"prometheus"},
Command: []string{consts.ComponentPrometheus},
Ports: ports,
Volumes: volumes,
Args: prometheusArgs,
Expand Down
Loading

0 comments on commit d8efe2c

Please sign in to comment.