Skip to content
This repository has been archived by the owner on Nov 20, 2021. It is now read-only.

Commit

Permalink
Set schema clusterName default by node name (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktravis authored Oct 27, 2020
1 parent c7e3643 commit c1fab95
Showing 1 changed file with 66 additions and 53 deletions.
119 changes: 66 additions & 53 deletions controllers/dockerinfrastructureprovider_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (r *DockerInfrastructureProviderReconciler) Reconcile(req ctrl.Request) (_
}
}()

b, err := json.Marshal(schema)
b, err := json.Marshal(r.generateSchema(ctx))
if err != nil {
return ctrl.Result{}, err
}
Expand All @@ -118,70 +118,83 @@ func (r *DockerInfrastructureProviderReconciler) Reconcile(req ctrl.Request) (_
return ctrl.Result{}, nil
}

const OpenAPISchemaSecretName = "config-schema"

var schema = spec.Schema{
SchemaProps: spec.SchemaProps{
Type: spec.StringOrArray{"object"},
Title: "Docker Worker Config",
Properties: map[string]spec.Schema{
"apiVersion": {
SchemaProps: spec.SchemaProps{
Type: spec.StringOrArray{"string"},
Default: v1alpha1.GroupVersion.String(),
const (
OpenAPISchemaSecretName = "config-schema"
defaultClusterName = "cinder"
)

func (r *DockerInfrastructureProviderReconciler) generateSchema(ctx context.Context) spec.Schema {
clusterName := defaultClusterName
var nodes corev1.NodeList
if err := r.List(ctx, &nodes, client.HasLabels{"node-role.kubernetes.io/master"}); err == nil {
for _, n := range nodes.Items {
clusterName = n.Name
break
}
}
return spec.Schema{
SchemaProps: spec.SchemaProps{
Type: spec.StringOrArray{"object"},
Title: "Docker Worker Config",
Properties: map[string]spec.Schema{
"apiVersion": {
SchemaProps: spec.SchemaProps{
Type: spec.StringOrArray{"string"},
Default: v1alpha1.GroupVersion.String(),
},
},
},
"kind": {
SchemaProps: spec.SchemaProps{
Type: spec.StringOrArray{"string"},
Default: "DockerMachine",
"kind": {
SchemaProps: spec.SchemaProps{
Type: spec.StringOrArray{"string"},
Default: "DockerMachine",
},
},
},
"metadata": {
SchemaProps: spec.SchemaProps{
Type: spec.StringOrArray{"object"},
Title: "Metadata",
Properties: map[string]spec.Schema{
"name": {
SchemaProps: spec.SchemaProps{
Type: spec.StringOrArray{"string"},
"metadata": {
SchemaProps: spec.SchemaProps{
Type: spec.StringOrArray{"object"},
Title: "Metadata",
Properties: map[string]spec.Schema{
"name": {
SchemaProps: spec.SchemaProps{
Type: spec.StringOrArray{"string"},
},
},
},
Required: []string{"name"},
},
Required: []string{"name"},
},
},
"spec": {
SchemaProps: spec.SchemaProps{
Type: spec.StringOrArray{"object"},
Title: "Docker Worker Config",
Properties: map[string]spec.Schema{
"image": {
SchemaProps: spec.SchemaProps{
Type: spec.StringOrArray{"string"},
Description: "container image to use",
Default: cinderapi.DefaultNodeImage,
"spec": {
SchemaProps: spec.SchemaProps{
Type: spec.StringOrArray{"object"},
Title: "Docker Worker Config",
Properties: map[string]spec.Schema{
"image": {
SchemaProps: spec.SchemaProps{
Type: spec.StringOrArray{"string"},
Description: "container image to use",
Default: cinderapi.DefaultNodeImage,
},
},
},
"containerName": {
SchemaProps: spec.SchemaProps{
Type: spec.StringOrArray{"string"},
Description: "container name",
Default: "cinder-worker",
"containerName": {
SchemaProps: spec.SchemaProps{
Type: spec.StringOrArray{"string"},
Description: "container name",
Default: "cinder-worker",
},
},
},
"clusterName": {
SchemaProps: spec.SchemaProps{
Type: spec.StringOrArray{"string"},
Description: "cluster name",
Default: "cinder",
"clusterName": {
SchemaProps: spec.SchemaProps{
Type: spec.StringOrArray{"string"},
Description: "cluster name",
Default: clusterName,
},
},
},
Required: []string{"image", "clusterName"},
},
Required: []string{"image", "clusterName"},
},
},
Required: []string{"apiVersion", "kind"},
},
Required: []string{"apiVersion", "kind"},
},
}
}

0 comments on commit c1fab95

Please sign in to comment.