Skip to content

Commit

Permalink
refactor: move env to _const.
Browse files Browse the repository at this point in the history
  • Loading branch information
joyceliu committed Nov 13, 2024
1 parent 4f4b733 commit b5915d9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func isLocalIP(ipAddr string) bool {

func commandShell() string {
// find command interpreter in env. default /bin/bash
sl, ok := os.LookupEnv("SHELL")
sl, ok := os.LookupEnv(_const.ENV_SHELL)
if !ok {
return "/bin/bash"
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/const/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,14 @@ const ( // === From runtime ===
// VariableItem for "loop" argument when run a task.
VariableItem = "item"
)

const ( // === From env ===
// ENV_SHELL which shell operator use in local connector.
ENV_SHELL = "SHELL"
// ENV_EXECUTOR_SERVICEACCOUNT use to run pipeline pod.
ENV_EXECUTOR_SERVICEACCOUNT = "EXECUTOR_SERVICEACCOUNT"
// ENV_EXECUTOR_IMAGE which image use in pipeline pod.
ENV_EXECUTOR_IMAGE = "EXECUTOR_IMAGE"
// ENV_EXECUTOR_IMAGE_PULLPOLICY which imagePolicy use in pipeline pod.
ENV_EXECUTOR_IMAGE_PULLPOLICY = "EXECUTOR_IMAGE_PULLPOLICY"
)
9 changes: 5 additions & 4 deletions pkg/controllers/pipeline_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
ctrlfinalizer "sigs.k8s.io/controller-runtime/pkg/finalizer"

kkcorev1 "github.com/kubesphere/kubekey/v4/pkg/apis/core/v1"
_const "github.com/kubesphere/kubekey/v4/pkg/const"
)

const (
Expand Down Expand Up @@ -199,7 +200,7 @@ func (r *PipelineReconciler) dealRunningPipeline(ctx context.Context, pipeline *
// checkServiceAccount when ServiceAccount is not exist, create it.
func (r *PipelineReconciler) checkServiceAccount(ctx context.Context, pipeline kkcorev1.Pipeline) error {
// get ServiceAccount name for executor pod
saName, ok := os.LookupEnv("EXECUTOR_SERVICEACCOUNT")
saName, ok := os.LookupEnv(_const.ENV_EXECUTOR_SERVICEACCOUNT)
if !ok {
saName = defaultServiceAccount
}
Expand Down Expand Up @@ -257,17 +258,17 @@ func (r *PipelineReconciler) checkServiceAccount(ctx context.Context, pipeline k
// GenerateJobSpec for pipeline
func (r *PipelineReconciler) GenerateJobSpec(pipeline kkcorev1.Pipeline) batchv1.JobSpec {
// get ServiceAccount name for executor pod
saName, ok := os.LookupEnv("EXECUTOR_SERVICEACCOUNT")
saName, ok := os.LookupEnv(_const.ENV_EXECUTOR_SERVICEACCOUNT)
if !ok {
saName = defaultServiceAccount
}
// get image from env
image, ok := os.LookupEnv("EXECUTOR_IMAGE")
image, ok := os.LookupEnv(_const.ENV_EXECUTOR_IMAGE)
if !ok {
image = defaultExecutorImage
}
// get image from env
imagePullPolicy, ok := os.LookupEnv("EXECUTOR_IMAGE_PULLPOLICY")
imagePullPolicy, ok := os.LookupEnv(_const.ENV_EXECUTOR_IMAGE_PULLPOLICY)
if !ok {
imagePullPolicy = defaultPullPolicy
}
Expand Down

0 comments on commit b5915d9

Please sign in to comment.