Skip to content

Commit

Permalink
Merge pull request #144 from traas-stack/dev/v0.6.1
Browse files Browse the repository at this point in the history
fix: add flow executor namespace config
  • Loading branch information
KingsonKai committed Jan 8, 2024
2 parents 6ab22e3 + 849b420 commit 87f3854
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 17 deletions.
13 changes: 11 additions & 2 deletions chaosmeta-deploy/templates/chaosmeta-flow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -357,6 +365,7 @@ data:
"resource": {
"cpu": "0",
"memory": "1Gi"
}
},
"namespace": "chaosmeta"
}
}
1 change: 1 addition & 0 deletions chaosmeta-flow-operator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion chaosmeta-flow-operator/Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion chaosmeta-flow-operator/build/yamls/chaosmeta-flow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion chaosmeta-flow-operator/config/chaosmeta-flow.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"resource": {
"cpu": "0",
"memory": "1Gi"
}
},
"namespace": "chaosmeta"
}
}
2 changes: 1 addition & 1 deletion chaosmeta-flow-operator/config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion chaosmeta-flow-operator/config/samples/http_get.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: chaosmeta.io/v1alpha1
kind: LoadTest
metadata:
name: loadtest-sample1
namespace: chaosmeta-flow
namespace: chaosmeta
spec:
flowType: http
duration: 1m
Expand Down
12 changes: 7 additions & 5 deletions chaosmeta-flow-operator/controllers/loadtest_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions chaosmeta-flow-operator/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion chaosmeta-measure-operator/Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 87f3854

Please sign in to comment.