Skip to content

Commit 4bddc60

Browse files
committed
fix: separate fields for contorl-plane and workers
1 parent 42a1894 commit 4bddc60

File tree

15 files changed

+210
-217
lines changed

15 files changed

+210
-217
lines changed

api/v1alpha1/aws_clusterconfig_types.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
package v1alpha1
55

66
import (
7-
"maps"
8-
97
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
108

119
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/variables"
@@ -14,12 +12,10 @@ import (
1412
type AWSSpec struct {
1513
// +optional
1614
Region *Region `json:"region,omitempty"`
17-
18-
AWSWorkerSpec `json:",inline"`
1915
}
2016

2117
func (AWSSpec) VariableSchema() clusterv1.VariableSchema {
22-
schema := clusterv1.VariableSchema{
18+
return clusterv1.VariableSchema{
2319
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
2420
Description: "AWS cluster configuration",
2521
Type: "object",
@@ -29,13 +25,6 @@ func (AWSSpec) VariableSchema() clusterv1.VariableSchema {
2925
Required: []string{"region"},
3026
},
3127
}
32-
33-
maps.Copy(
34-
schema.OpenAPIV3Schema.Properties,
35-
AWSWorkerSpecProperties,
36-
)
37-
38-
return schema
3928
}
4029

4130
type Region string

api/v1alpha1/aws_workerconfig_types.go renamed to api/v1alpha1/aws_node_types.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ package v1alpha1
55

66
import clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
77

8-
type AWSWorkerSpec struct{}
8+
type AWSNodeSpec struct{}
99

10-
var AWSWorkerSpecProperties = map[string]clusterv1.JSONSchemaProps{}
11-
12-
func (AWSWorkerSpec) VariableSchema() clusterv1.VariableSchema {
10+
func (AWSNodeSpec) VariableSchema() clusterv1.VariableSchema {
1311
return clusterv1.VariableSchema{
1412
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
15-
Description: "AWS worker configuration",
13+
Description: "AWS Node configuration",
1614
Type: "object",
17-
Properties: AWSWorkerSpecProperties,
15+
Properties: map[string]clusterv1.JSONSchemaProps{},
1816
},
1917
}
2018
}

api/v1alpha1/clusterconfig_types.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ type ClusterConfigSpec struct {
3737
Docker *DockerSpec `json:"docker,omitempty"`
3838

3939
GenericClusterConfig `json:",inline"`
40+
41+
//+optional
42+
ControlPlane *NodeConfigSpec `json:"controlPlane,omitempty"`
43+
44+
//+optional
45+
Workers *NodeConfigSpec `json:"workers,omitempty"`
4046
}
4147

4248
func (s ClusterConfigSpec) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect.
@@ -48,25 +54,27 @@ func (s ClusterConfigSpec) VariableSchema() clusterv1.VariableSchema { //nolint:
4854
clusterConfigProps.OpenAPIV3Schema.Properties,
4955
map[string]clusterv1.JSONSchemaProps{
5056
"aws": AWSSpec{}.VariableSchema().OpenAPIV3Schema,
57+
"controlPlane": NodeConfigSpec{
58+
AWS: &AWSNodeSpec{},
59+
}.VariableSchema().OpenAPIV3Schema,
60+
"workers": NodeConfigSpec{
61+
AWS: &AWSNodeSpec{},
62+
}.VariableSchema().OpenAPIV3Schema,
5163
},
5264
)
53-
54-
clusterConfigProps.OpenAPIV3Schema.Required = append(
55-
clusterConfigProps.OpenAPIV3Schema.Required,
56-
"aws",
57-
)
5865
case s.Docker != nil:
5966
maps.Copy(
6067
clusterConfigProps.OpenAPIV3Schema.Properties,
6168
map[string]clusterv1.JSONSchemaProps{
6269
"docker": DockerSpec{}.VariableSchema().OpenAPIV3Schema,
70+
"controlPlane": NodeConfigSpec{
71+
Docker: &DockerNodeSpec{},
72+
}.VariableSchema().OpenAPIV3Schema,
73+
"workers": NodeConfigSpec{
74+
Docker: &DockerNodeSpec{},
75+
}.VariableSchema().OpenAPIV3Schema,
6376
},
6477
)
65-
66-
clusterConfigProps.OpenAPIV3Schema.Required = append(
67-
clusterConfigProps.OpenAPIV3Schema.Required,
68-
"docker",
69-
)
7078
}
7179

7280
return clusterConfigProps
@@ -93,7 +101,7 @@ type GenericClusterConfig struct {
93101
Addons *Addons `json:"addons,omitempty"`
94102
}
95103

96-
func (GenericClusterConfig) VariableSchema() clusterv1.VariableSchema {
104+
func (s GenericClusterConfig) VariableSchema() clusterv1.VariableSchema {
97105
return clusterv1.VariableSchema{
98106
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
99107
Description: "Cluster configuration",
@@ -108,6 +116,8 @@ func (GenericClusterConfig) VariableSchema() clusterv1.VariableSchema {
108116
).VariableSchema().
109117
OpenAPIV3Schema,
110118
"imageRegistries": ImageRegistries{}.VariableSchema().OpenAPIV3Schema,
119+
"controlPlane": NodeConfigSpec{}.VariableSchema().OpenAPIV3Schema,
120+
"workers": NodeConfigSpec{}.VariableSchema().OpenAPIV3Schema,
111121
},
112122
},
113123
}

api/v1alpha1/docker_clusterconfig_types.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,17 @@
44
package v1alpha1
55

66
import (
7-
"maps"
8-
97
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
108
)
119

12-
type DockerSpec struct {
13-
DockerWorkerSpec `json:",inline"`
14-
}
10+
type DockerSpec struct{}
1511

1612
func (DockerSpec) VariableSchema() clusterv1.VariableSchema {
17-
schema := clusterv1.VariableSchema{
13+
return clusterv1.VariableSchema{
1814
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
1915
Description: "Docker cluster configuration",
2016
Type: "object",
21-
Properties: map[string]clusterv1.JSONSchemaProps{
22-
"customImage": OCIImage("").VariableSchema().OpenAPIV3Schema,
23-
},
17+
Properties: map[string]clusterv1.JSONSchemaProps{},
2418
},
2519
}
26-
27-
maps.Copy(
28-
schema.OpenAPIV3Schema.Properties,
29-
DockerWorkerSpecProperties,
30-
)
31-
32-
return schema
3320
}

api/v1alpha1/docker_workerconfig_types.go renamed to api/v1alpha1/docker_node_types.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,19 @@ import (
99
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/openapi/patterns"
1010
)
1111

12-
type DockerWorkerSpec struct {
12+
type DockerNodeSpec struct {
1313
//+optional
1414
CustomImage *OCIImage `json:"customImage,omitempty"`
1515
}
1616

17-
var DockerWorkerSpecProperties = map[string]clusterv1.JSONSchemaProps{
18-
"customImage": OCIImage("").VariableSchema().OpenAPIV3Schema,
19-
}
20-
21-
func (DockerWorkerSpec) VariableSchema() clusterv1.VariableSchema {
17+
func (DockerNodeSpec) VariableSchema() clusterv1.VariableSchema {
2218
return clusterv1.VariableSchema{
2319
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
24-
Description: "Docker worker configuration",
20+
Description: "Docker Node configuration",
2521
Type: "object",
26-
Properties: DockerWorkerSpecProperties,
22+
Properties: map[string]clusterv1.JSONSchemaProps{
23+
"customImage": OCIImage("").VariableSchema().OpenAPIV3Schema,
24+
},
2725
},
2826
}
2927
}
@@ -33,7 +31,7 @@ type OCIImage string
3331
func (OCIImage) VariableSchema() clusterv1.VariableSchema {
3432
return clusterv1.VariableSchema{
3533
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
36-
Description: "Custom OCI image for control plane and worker nodes.",
34+
Description: "Custom OCI image for control plane and worker Nodes.",
3735
Type: "string",
3836
Pattern: patterns.Anchored(patterns.ImageReference),
3937
},

api/v1alpha1/node_types.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2023 D2iQ, Inc. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package v1alpha1
5+
6+
import (
7+
"maps"
8+
9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
11+
)
12+
13+
//+kubebuilder:object:root=true
14+
15+
// NodeConfig is the Schema for the workerconfigs API.
16+
type NodeConfig struct {
17+
metav1.TypeMeta `json:",inline"`
18+
metav1.ObjectMeta `json:"metadata,omitempty"`
19+
20+
//+optional
21+
Spec NodeConfigSpec `json:"spec,omitempty"`
22+
}
23+
24+
// NodeConfigSpec defines the desired state of NodeConfig.
25+
// Place any configuration that can be applied to individual Nodes here.
26+
// Otherwise, it should go into the ClusterConfigSpec.
27+
type NodeConfigSpec struct {
28+
// +optional
29+
AWS *AWSNodeSpec `json:"aws,omitempty"`
30+
// +optional
31+
Docker *DockerNodeSpec `json:"docker,omitempty"`
32+
}
33+
34+
func (s NodeConfigSpec) VariableSchema() clusterv1.VariableSchema {
35+
nodeConfigProps := GenericNodeConfig{}.VariableSchema()
36+
37+
switch {
38+
case s.AWS != nil:
39+
maps.Copy(
40+
nodeConfigProps.OpenAPIV3Schema.Properties,
41+
map[string]clusterv1.JSONSchemaProps{
42+
"aws": AWSNodeSpec{}.VariableSchema().OpenAPIV3Schema,
43+
},
44+
)
45+
case s.Docker != nil:
46+
maps.Copy(
47+
nodeConfigProps.OpenAPIV3Schema.Properties,
48+
map[string]clusterv1.JSONSchemaProps{
49+
"docker": DockerNodeSpec{}.VariableSchema().OpenAPIV3Schema,
50+
},
51+
)
52+
}
53+
54+
return nodeConfigProps
55+
}
56+
57+
type GenericNodeConfig struct{}
58+
59+
func (GenericNodeConfig) VariableSchema() clusterv1.VariableSchema {
60+
return clusterv1.VariableSchema{
61+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
62+
Description: "Node configuration",
63+
Type: "object",
64+
Properties: map[string]clusterv1.JSONSchemaProps{},
65+
},
66+
}
67+
}
68+
69+
func init() {
70+
SchemeBuilder.Register(&NodeConfig{})
71+
}

api/v1alpha1/workerconfig_types.go

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)