@@ -102,7 +102,7 @@ func (r *DockerInfrastructureProviderReconciler) Reconcile(req ctrl.Request) (_
102102 }
103103 }()
104104
105- b , err := json .Marshal (schema )
105+ b , err := json .Marshal (r . generateSchema ( ctx ) )
106106 if err != nil {
107107 return ctrl.Result {}, err
108108 }
@@ -118,70 +118,83 @@ func (r *DockerInfrastructureProviderReconciler) Reconcile(req ctrl.Request) (_
118118 return ctrl.Result {}, nil
119119}
120120
121- const OpenAPISchemaSecretName = "config-schema"
122-
123- var schema = spec.Schema {
124- SchemaProps : spec.SchemaProps {
125- Type : spec.StringOrArray {"object" },
126- Title : "Docker Worker Config" ,
127- Properties : map [string ]spec.Schema {
128- "apiVersion" : {
129- SchemaProps : spec.SchemaProps {
130- Type : spec.StringOrArray {"string" },
131- Default : v1alpha1 .GroupVersion .String (),
121+ const (
122+ OpenAPISchemaSecretName = "config-schema"
123+ defaultClusterName = "cinder"
124+ )
125+
126+ func (r * DockerInfrastructureProviderReconciler ) generateSchema (ctx context.Context ) spec.Schema {
127+ clusterName := defaultClusterName
128+ var nodes corev1.NodeList
129+ if err := r .List (ctx , & nodes , client.HasLabels {"node-role.kubernetes.io/master" }); err == nil {
130+ for _ , n := range nodes .Items {
131+ clusterName = n .Name
132+ break
133+ }
134+ }
135+ return spec.Schema {
136+ SchemaProps : spec.SchemaProps {
137+ Type : spec.StringOrArray {"object" },
138+ Title : "Docker Worker Config" ,
139+ Properties : map [string ]spec.Schema {
140+ "apiVersion" : {
141+ SchemaProps : spec.SchemaProps {
142+ Type : spec.StringOrArray {"string" },
143+ Default : v1alpha1 .GroupVersion .String (),
144+ },
132145 },
133- },
134- "kind" : {
135- SchemaProps : spec.SchemaProps {
136- Type : spec. StringOrArray { "string" } ,
137- Default : "DockerMachine" ,
146+ "kind" : {
147+ SchemaProps : spec. SchemaProps {
148+ Type : spec.StringOrArray { "string" },
149+ Default : "DockerMachine" ,
150+ } ,
138151 },
139- },
140- "metadata" : {
141- SchemaProps : spec.SchemaProps {
142- Type : spec. StringOrArray { "object" } ,
143- Title : "Metadata" ,
144- Properties : map [ string ]spec. Schema {
145- "name" : {
146- SchemaProps : spec.SchemaProps {
147- Type : spec. StringOrArray { "string" },
152+ "metadata" : {
153+ SchemaProps : spec. SchemaProps {
154+ Type : spec.StringOrArray { "object" },
155+ Title : "Metadata" ,
156+ Properties : map [ string ]spec. Schema {
157+ "name" : {
158+ SchemaProps : spec. SchemaProps {
159+ Type : spec.StringOrArray { "string" },
160+ },
148161 },
149162 },
163+ Required : []string {"name" },
150164 },
151- Required : []string {"name" },
152165 },
153- },
154- "spec" : {
155- SchemaProps : spec.SchemaProps {
156- Type : spec. StringOrArray { "object" } ,
157- Title : "Docker Worker Config" ,
158- Properties : map [ string ]spec. Schema {
159- "image" : {
160- SchemaProps : spec.SchemaProps {
161- Type : spec. StringOrArray { "string" } ,
162- Description : "container image to use" ,
163- Default : cinderapi . DefaultNodeImage ,
166+ "spec" : {
167+ SchemaProps : spec. SchemaProps {
168+ Type : spec.StringOrArray { "object" },
169+ Title : "Docker Worker Config" ,
170+ Properties : map [ string ]spec. Schema {
171+ "image" : {
172+ SchemaProps : spec. SchemaProps {
173+ Type : spec.StringOrArray { "string" },
174+ Description : "container image to use" ,
175+ Default : cinderapi . DefaultNodeImage ,
176+ } ,
164177 },
165- },
166- "containerName" : {
167- SchemaProps : spec.SchemaProps {
168- Type : spec. StringOrArray { "string" } ,
169- Description : "container name " ,
170- Default : "cinder-worker" ,
178+ "containerName" : {
179+ SchemaProps : spec. SchemaProps {
180+ Type : spec.StringOrArray { "string" },
181+ Description : "container name" ,
182+ Default : "cinder-worker " ,
183+ } ,
171184 },
172- },
173- "clusterName" : {
174- SchemaProps : spec.SchemaProps {
175- Type : spec. StringOrArray { "string" } ,
176- Description : "cluster name" ,
177- Default : "cinder" ,
185+ "clusterName" : {
186+ SchemaProps : spec. SchemaProps {
187+ Type : spec.StringOrArray { "string" },
188+ Description : "cluster name" ,
189+ Default : clusterName ,
190+ } ,
178191 },
179192 },
193+ Required : []string {"image" , "clusterName" },
180194 },
181- Required : []string {"image" , "clusterName" },
182195 },
183196 },
197+ Required : []string {"apiVersion" , "kind" },
184198 },
185- Required : []string {"apiVersion" , "kind" },
186- },
199+ }
187200}
0 commit comments