@@ -31,8 +31,11 @@ public abstract class WorkloadWriter extends KindWriter {
3131 + " labels: \r \n "
3232 + " name: \" #NAME#\" " ;
3333
34- public WorkloadWriter (String name , String namespace , String [] kvs ) throws Exception {
35- super (name , namespace , kvs );
34+ public WorkloadWriter (String [] kvs ) throws Exception {
35+ super (kvs );
36+ if (this .json .get ("spec" ).get ("replicas" ).asInt () == 0 ) {
37+ ((ObjectNode ) json .get ("spec" )).remove ("replicas" );
38+ }
3639 }
3740
3841 static final String MATSER = "nodeSelector:\r \n "
@@ -59,14 +62,41 @@ public WorkloadWriter withContainer(Container container) throws Exception {
5962 + "persistentVolumeClaim:\r \n "
6063 + " claimName: #PVC#" ;
6164
62- public WorkloadWriter withVolume (String name , String pvc ) throws Exception {
65+ public WorkloadWriter withPVCVolume (String name , String pvc ) throws Exception {
6366 ArrayNode volumes = getArrayValue (getObjectValue (
6467 getObjectValue (getObjectValue ("spec" ), "template" ), "spec" ), "volumes" );
6568 ObjectNode v = toObjectNode (VOLUME , new String [] {"#NAME#" , name , "#PVC#" , pvc });
6669 volumes .add (v );
6770 return this ;
6871 }
6972
73+ static final String HOST = "name: #NAME#\r \n "
74+ + "hostPath:\r \n "
75+ + " path: #PATH#" ;
76+
77+ public WorkloadWriter withHostVolume (String name , String path ) throws Exception {
78+ ArrayNode volumes = getArrayValue (getObjectValue (
79+ getObjectValue (getObjectValue ("spec" ), "template" ), "spec" ), "volumes" );
80+ ObjectNode v = toObjectNode (HOST , new String [] {"#NAME#" , name , "#PATH#" , path });
81+ volumes .add (v );
82+ return this ;
83+ }
84+
85+ static final String CONFIGMAP = "name: #NAME#\r \n "
86+ + "configMap:\r \n "
87+ + " name: #CONFIGMAP_NAME#\r \n "
88+ + " items:\r \n "
89+ + " - key: #CONFIGMAP_KEY#\r \n "
90+ + " path: #PATH#" ;
91+
92+ public WorkloadWriter withConfigMapVolume (String name , String cm , String cmKey , String path ) throws Exception {
93+ ArrayNode volumes = getArrayValue (getObjectValue (
94+ getObjectValue (getObjectValue ("spec" ), "template" ), "spec" ), "volumes" );
95+ ObjectNode v = toObjectNode (CONFIGMAP , new String [] {"#NAME#" , name , "#CONFIGMAP_NAME#" , cm , "#CONFIGMAP_KEY#" , cmKey , "#PATH#" , path });
96+ volumes .add (v );
97+ return this ;
98+ }
99+
70100 @ Override
71101 public String getTemplate () {
72102 return TEMPLATE ;
@@ -83,10 +113,22 @@ public static class Container {
83113
84114 Env [] env ;
85115
116+ String [] args ;
117+
86118 Port [] ports ;
87119
88120 VolumeMount [] volumeMounts ;
89121
122+ public Container (String name , String image , String [] args , Env [] env , Port [] ports , VolumeMount [] volumeMounts ) {
123+ super ();
124+ this .name = name ;
125+ this .image = image ;
126+ this .args = args ;
127+ this .env = env ;
128+ this .ports = ports ;
129+ this .volumeMounts = volumeMounts ;
130+ }
131+
90132 public Container (String name , String image , Env [] env , Port [] ports , VolumeMount [] volumeMounts ) {
91133 super ();
92134 this .name = name ;
@@ -143,6 +185,14 @@ public String getImagePullPolicy() {
143185 public void setImagePullPolicy (String imagePullPolicy ) {
144186 this .imagePullPolicy = imagePullPolicy ;
145187 }
188+
189+ public String [] getArgs () {
190+ return args ;
191+ }
192+
193+ public void setArgs (String [] args ) {
194+ this .args = args ;
195+ }
146196
147197 }
148198
0 commit comments