diff --git a/99-integration/dubbo-samples-registry-test-nacos-instance/case-configuration.yml b/99-integration/dubbo-samples-registry-test-nacos-instance/case-configuration.yml index 32be324247..194c1d43ca 100644 --- a/99-integration/dubbo-samples-registry-test-nacos-instance/case-configuration.yml +++ b/99-integration/dubbo-samples-registry-test-nacos-instance/case-configuration.yml @@ -26,12 +26,12 @@ services: - MYSQL_PASSWORD=nacos - MYSQL_ALLOW_EMPTY_PASSWORD=yes init: - name: wait-for-mysql - image: busybox - command: - - "/bin/sh" - - "-c" - - "until nc -z nacos-mysql 3306; do sleep 1; done;" + - name: wait-for-mysql + image: busybox + command: + - "/bin/sh" + - "-c" + - "until nc -z nacos-mysql 3306; do sleep 1; done;" expose: - 3306 healthcheck: diff --git a/test/dubbo-scenario-builder/src/main/java/org/apache/dubbo/scenario/builder/ConfigurationImpl.java b/test/dubbo-scenario-builder/src/main/java/org/apache/dubbo/scenario/builder/ConfigurationImpl.java index 213721a7f2..db271f6dbc 100644 --- a/test/dubbo-scenario-builder/src/main/java/org/apache/dubbo/scenario/builder/ConfigurationImpl.java +++ b/test/dubbo-scenario-builder/src/main/java/org/apache/dubbo/scenario/builder/ConfigurationImpl.java @@ -18,8 +18,9 @@ package org.apache.dubbo.scenario.builder; import org.apache.dubbo.scenario.builder.exception.ConfigureFileNotFoundException; -import org.apache.dubbo.scenario.builder.kubernetes.KubernetesService; +import org.apache.dubbo.scenario.builder.kubernetes.InitContainer; import org.apache.dubbo.scenario.builder.kubernetes.KubernetesRunningGenerator; +import org.apache.dubbo.scenario.builder.kubernetes.KubernetesService; import org.apache.dubbo.scenario.builder.vo.CaseConfiguration; import org.apache.dubbo.scenario.builder.vo.ServiceComponent; @@ -41,7 +42,6 @@ import java.util.List; import java.util.Map; import java.util.Properties; -import java.util.Random; import java.util.Set; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -727,18 +727,36 @@ private static KubernetesService getKubernetesService(ServiceComponent dependenc if(dependency.getInit() != null) { Yaml yaml = new Yaml(); - Map initMap = dependency.getInit(); - Map newMap = new LinkedHashMap<>(); - for (Map.Entry entry : initMap.entrySet()) { - if ("command".equals(entry.getKey())) { - dependency.setInitCommand((List) entry.getValue()); - continue; + List> inits = (List>) dependency.getInit(); + for (Map initMap : inits) { + InitContainer initContainer = new InitContainer(); + Map newMap = new LinkedHashMap<>(); + + for (Map.Entry entry : initMap.entrySet()) { + String key = entry.getKey(); + if ("command".equals(key)) { + initContainer.setCommand((List) entry.getValue()); + continue; + } + String val = yaml.dump(entry.getValue()).trim(); + if ("name".equals(key)) { + initContainer.setName(val); + } else if ("image".equals(key)) { + initContainer.setImage(val); + } else { + newMap.put(entry.getKey(), val); + } } - String value = yaml.dump(entry.getValue()); - newMap.put(entry.getKey(), value.trim()); + initContainer.setAttributes(newMap); + List initContainers = service.getInitContainers(); + if (initContainers == null) { + service.setInitContainers(new ArrayList<>()); + initContainers = service.getInitContainers(); + } + initContainers.add(initContainer); } - service.setInit(newMap); - service.setInitCommand(dependency.getInitCommand()); + + } //convert healthcheck to string map diff --git a/test/dubbo-scenario-builder/src/main/java/org/apache/dubbo/scenario/builder/kubernetes/InitContainer.java b/test/dubbo-scenario-builder/src/main/java/org/apache/dubbo/scenario/builder/kubernetes/InitContainer.java index 57488a7574..85cd639635 100644 --- a/test/dubbo-scenario-builder/src/main/java/org/apache/dubbo/scenario/builder/kubernetes/InitContainer.java +++ b/test/dubbo-scenario-builder/src/main/java/org/apache/dubbo/scenario/builder/kubernetes/InitContainer.java @@ -18,6 +18,7 @@ package org.apache.dubbo.scenario.builder.kubernetes; import java.util.List; +import java.util.Map; /** * Such as: @@ -37,6 +38,8 @@ public class InitContainer { private List command; + private Map attributes; + public String getName() { return name; } @@ -60,4 +63,12 @@ public List getCommand() { public void setCommand(List command) { this.command = command; } + + public Map getAttributes() { + return attributes; + } + + public void setAttributes(Map attributes) { + this.attributes = attributes; + } } diff --git a/test/dubbo-scenario-builder/src/main/java/org/apache/dubbo/scenario/builder/kubernetes/KubernetesService.java b/test/dubbo-scenario-builder/src/main/java/org/apache/dubbo/scenario/builder/kubernetes/KubernetesService.java index 1b68f136d3..7f06fded00 100644 --- a/test/dubbo-scenario-builder/src/main/java/org/apache/dubbo/scenario/builder/kubernetes/KubernetesService.java +++ b/test/dubbo-scenario-builder/src/main/java/org/apache/dubbo/scenario/builder/kubernetes/KubernetesService.java @@ -42,9 +42,7 @@ public class KubernetesService { private Map environment; - private Map init; - - private List initCommand; + private List initContainers; public String getName() { return name; @@ -141,19 +139,11 @@ public void setType(String type) { this.type = type; } - public Map getInit() { - return init; - } - - public void setInit(Map init) { - this.init = init; - } - - public List getInitCommand() { - return initCommand; + public List getInitContainers() { + return initContainers; } - public void setInitCommand(List initCommand) { - this.initCommand = initCommand; + public void setInitContainers(List initContainers) { + this.initContainers = initContainers; } } diff --git a/test/dubbo-scenario-builder/src/main/resources/kubernetes-manifest.template b/test/dubbo-scenario-builder/src/main/resources/kubernetes-manifest.template index ce367aa72d..2553d5f9e3 100644 --- a/test/dubbo-scenario-builder/src/main/resources/kubernetes-manifest.template +++ b/test/dubbo-scenario-builder/src/main/resources/kubernetes-manifest.template @@ -63,22 +63,23 @@ spec: labels: app: ${service.name} spec: - <#if service.init??> + <#if service.initContainers??> initContainers: - <#if service.init?has_key("name")> - <#assign nameValue = service.init.name> - <#assign _ = service.init.remove("name")> - - name: ${nameValue} - - <#list service.init as key,value> - ${key}: ${value} - - <#if service.initCommand??> + <#list service.initContainers as initContainer> + - name: ${initContainer.name} + image: ${initContainer.image} + <#if initContainer.command??> command: - <#list service.initCommand as cmd> + <#list initContainer.command as cmd> - "${cmd}" + + + <#if initContainer.attributes??> + <#list initContainer.attributes as key,value> + ${key}: ${value} + + - containers: - name: ${service.name}