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

refactor: move env to _const. #2455

Merged
merged 1 commit into from
Nov 13, 2024
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 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
Loading