From 849b420aba160d2b9bc1bbdd6281e6f363a5b2a4 Mon Sep 17 00:00:00 2001 From: KingsonKai <562419972@qq.com> Date: Mon, 8 Jan 2024 19:23:34 +0800 Subject: [PATCH] fix: add flow executor namespace config --- chaosmeta-deploy/templates/chaosmeta-flow.yaml | 13 +++++++++++-- chaosmeta-flow-operator/Dockerfile | 1 + chaosmeta-flow-operator/Makefile | 2 +- .../build/yamls/chaosmeta-flow.yaml | 2 +- chaosmeta-flow-operator/config/chaosmeta-flow.json | 3 ++- .../config/manager/kustomization.yaml | 2 +- .../config/samples/http_get.yaml | 2 +- .../controllers/loadtest_controller.go | 12 +++++++----- chaosmeta-flow-operator/pkg/config/config.go | 5 +++-- chaosmeta-measure-operator/Makefile | 2 +- .../build/yamls/chaosmeta-measure.yaml | 2 +- .../config/manager/kustomization.yaml | 2 +- 12 files changed, 31 insertions(+), 17 deletions(-) diff --git a/chaosmeta-deploy/templates/chaosmeta-flow.yaml b/chaosmeta-deploy/templates/chaosmeta-flow.yaml index a8b2d8d..54a3792 100644 --- a/chaosmeta-deploy/templates/chaosmeta-flow.yaml +++ b/chaosmeta-deploy/templates/chaosmeta-flow.yaml @@ -250,7 +250,7 @@ spec: - --leader-elect command: - /manager - image: registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-flow-controller:v0.0.5 + image: registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-flow-controller:v0.0.6 env: - name: DEFAULTNAMESPACE valueFrom: @@ -285,10 +285,18 @@ spec: capabilities: drop: - ALL + volumeMounts: + - mountPath: /workspace/config/chaosmeta-flow.json + name: config-volume + subPath: chaosmeta-flow.json securityContext: runAsNonRoot: true serviceAccountName: chaosmeta-flow-controller-manager terminationGracePeriodSeconds: 10 + volumes: + - configMap: + name: chaosmeta-flow-config + name: config-volume --- apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration @@ -357,6 +365,7 @@ data: "resource": { "cpu": "0", "memory": "1Gi" - } + }, + "namespace": "chaosmeta" } } diff --git a/chaosmeta-flow-operator/Dockerfile b/chaosmeta-flow-operator/Dockerfile index a1b863f..fcce88b 100644 --- a/chaosmeta-flow-operator/Dockerfile +++ b/chaosmeta-flow-operator/Dockerfile @@ -17,6 +17,7 @@ COPY api/ api/ COPY controllers/ controllers/ COPY config/executor config/executor COPY config/chaosmeta-flow.json config/chaosmeta-flow.json +COPY pkg/ pkg/ # Build # the GOARCH has not a default value to allow the binary be built according to the host where the command diff --git a/chaosmeta-flow-operator/Makefile b/chaosmeta-flow-operator/Makefile index f822660..563e90d 100644 --- a/chaosmeta-flow-operator/Makefile +++ b/chaosmeta-flow-operator/Makefile @@ -1,6 +1,6 @@ # Image URL to use all building/pushing image targets -IMG ?= registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-flow-controller:v0.0.5 +IMG ?= registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-flow-controller:v0.0.6 # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. ENVTEST_K8S_VERSION = 1.25.0 diff --git a/chaosmeta-flow-operator/build/yamls/chaosmeta-flow.yaml b/chaosmeta-flow-operator/build/yamls/chaosmeta-flow.yaml index 10799f9..91e57c6 100644 --- a/chaosmeta-flow-operator/build/yamls/chaosmeta-flow.yaml +++ b/chaosmeta-flow-operator/build/yamls/chaosmeta-flow.yaml @@ -313,7 +313,7 @@ spec: - --leader-elect command: - /manager - image: registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-flow-controller:v0.0.5 + image: registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-flow-controller:v0.0.6 livenessProbe: httpGet: path: /healthz diff --git a/chaosmeta-flow-operator/config/chaosmeta-flow.json b/chaosmeta-flow-operator/config/chaosmeta-flow.json index fc93a29..398a910 100644 --- a/chaosmeta-flow-operator/config/chaosmeta-flow.json +++ b/chaosmeta-flow-operator/config/chaosmeta-flow.json @@ -4,6 +4,7 @@ "resource": { "cpu": "0", "memory": "1Gi" - } + }, + "namespace": "chaosmeta" } } \ No newline at end of file diff --git a/chaosmeta-flow-operator/config/manager/kustomization.yaml b/chaosmeta-flow-operator/config/manager/kustomization.yaml index 7297691..a8fae7b 100644 --- a/chaosmeta-flow-operator/config/manager/kustomization.yaml +++ b/chaosmeta-flow-operator/config/manager/kustomization.yaml @@ -5,4 +5,4 @@ kind: Kustomization images: - name: controller newName: registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-flow-controller - newTag: v0.0.5 + newTag: v0.0.6 diff --git a/chaosmeta-flow-operator/config/samples/http_get.yaml b/chaosmeta-flow-operator/config/samples/http_get.yaml index 5ddc44f..2843a56 100644 --- a/chaosmeta-flow-operator/config/samples/http_get.yaml +++ b/chaosmeta-flow-operator/config/samples/http_get.yaml @@ -2,7 +2,7 @@ apiVersion: chaosmeta.io/v1alpha1 kind: LoadTest metadata: name: loadtest-sample1 - namespace: chaosmeta-flow + namespace: chaosmeta spec: flowType: http duration: 1m diff --git a/chaosmeta-flow-operator/controllers/loadtest_controller.go b/chaosmeta-flow-operator/controllers/loadtest_controller.go index d96e82a..ddeb2f1 100644 --- a/chaosmeta-flow-operator/controllers/loadtest_controller.go +++ b/chaosmeta-flow-operator/controllers/loadtest_controller.go @@ -296,9 +296,6 @@ func loadConfig(ctx context.Context, ins *v1alpha1.LoadTest) string { func loadJob(ctx context.Context, ins *v1alpha1.LoadTest, configFileStr string) (*batchv1.Job, error) { mainConfig := config.GetGlobalConfig() - logger := log.FromContext(ctx) - logger.Info(fmt.Sprintf("read config: image: %s, cpu: %s, mem: %s", mainConfig.Executor.Image, mainConfig.Executor.Resource.CPU, mainConfig.Executor.Resource.Memory)) - yamlStr := strings.ReplaceAll(v1alpha1.JobYamlStr, "@INITIAL_CONFIG@", configFileStr) cpuCore := strconv.Itoa(ins.Spec.Parallelism / ins.Spec.Source / 2) @@ -318,11 +315,16 @@ func loadJob(ctx context.Context, ins *v1alpha1.LoadTest, configFileStr string) return nil, fmt.Errorf("convert yaml to job instance error: %s", err.Error()) } + targetNs := ins.Namespace + if mainConfig.Executor.Namespace != "" { + targetNs = mainConfig.Executor.Namespace + } + job.Spec.Template.Spec.Containers[0].Image = mainConfig.Executor.Image job.Name = ins.Name job.Spec.Template.Name = ins.Name - job.Namespace = ins.Namespace - job.Spec.Template.Namespace = ins.Namespace + job.Namespace = targetNs + job.Spec.Template.Namespace = targetNs replicas := int32(ins.Spec.Source) job.Spec.Completions = &replicas job.Spec.Parallelism = &replicas diff --git a/chaosmeta-flow-operator/pkg/config/config.go b/chaosmeta-flow-operator/pkg/config/config.go index ed7f0fd..79a40f7 100644 --- a/chaosmeta-flow-operator/pkg/config/config.go +++ b/chaosmeta-flow-operator/pkg/config/config.go @@ -58,8 +58,9 @@ type MainConfig struct { } type ExecutorConfig struct { - Image string `json:"image"` - Resource ResourceConfig `json:"resource"` + Image string `json:"image"` + Resource ResourceConfig `json:"resource"` + Namespace string `json:"namespace"` } type ResourceConfig struct { diff --git a/chaosmeta-measure-operator/Makefile b/chaosmeta-measure-operator/Makefile index ab84ab6..04c33ba 100644 --- a/chaosmeta-measure-operator/Makefile +++ b/chaosmeta-measure-operator/Makefile @@ -1,6 +1,6 @@ # Image URL to use all building/pushing image targets -IMG ?= registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-measure-controller:v0.0.6 +IMG ?= registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-measure-controller:v0.0.7 # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. ENVTEST_K8S_VERSION = 1.25.0 diff --git a/chaosmeta-measure-operator/build/yamls/chaosmeta-measure.yaml b/chaosmeta-measure-operator/build/yamls/chaosmeta-measure.yaml index 05314b4..89d6e9e 100644 --- a/chaosmeta-measure-operator/build/yamls/chaosmeta-measure.yaml +++ b/chaosmeta-measure-operator/build/yamls/chaosmeta-measure.yaml @@ -333,7 +333,7 @@ spec: - --leader-elect command: - /manager - image: registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-measure-controller:v0.0.6 + image: registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-measure-controller:v0.0.7 livenessProbe: httpGet: path: /healthz diff --git a/chaosmeta-measure-operator/config/manager/kustomization.yaml b/chaosmeta-measure-operator/config/manager/kustomization.yaml index dbb69e3..25c8b62 100644 --- a/chaosmeta-measure-operator/config/manager/kustomization.yaml +++ b/chaosmeta-measure-operator/config/manager/kustomization.yaml @@ -5,4 +5,4 @@ kind: Kustomization images: - name: controller newName: registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-measure-controller - newTag: v0.0.6 + newTag: v0.0.7