Skip to content

Commit 2abf01b

Browse files
dkoshkinjimmidyson
andauthored
fix: move provider fields under aws and docker (#204)
Co-authored-by: Jimmi Dyson <[email protected]>
1 parent 2660571 commit 2abf01b

File tree

17 files changed

+146
-116
lines changed

17 files changed

+146
-116
lines changed

api/v1alpha1/aws_clusterconfig_types.go

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,25 @@
44
package v1alpha1
55

66
import (
7-
"maps"
8-
9-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
107
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
118

129
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/variables"
1310
)
1411

15-
//+kubebuilder:object:root=true
16-
17-
// AWSClusterConfig is the Schema for the awsclusterconfigs API.
18-
type AWSClusterConfig struct {
19-
metav1.TypeMeta `json:",inline"`
20-
metav1.ObjectMeta `json:"metadata,omitempty"`
21-
22-
Spec AWSClusterConfigSpec `json:"spec,omitempty"`
23-
}
24-
25-
// AWSClusterConfigSpec defines the desired state of AWSClusterConfig.
26-
type AWSClusterConfigSpec struct {
12+
type AWSSpec struct {
2713
// +optional
2814
Region *Region `json:"region,omitempty"`
29-
30-
GenericClusterConfig `json:",inline"`
3115
}
3216

33-
func (AWSClusterConfigSpec) VariableSchema() clusterv1.VariableSchema {
34-
clusterConfigProps := GenericClusterConfig{}.VariableSchema().OpenAPIV3Schema.Properties
35-
36-
maps.Copy(
37-
clusterConfigProps,
38-
map[string]clusterv1.JSONSchemaProps{
39-
"region": Region("").VariableSchema().OpenAPIV3Schema,
40-
},
41-
)
42-
17+
func (AWSSpec) VariableSchema() clusterv1.VariableSchema {
4318
return clusterv1.VariableSchema{
4419
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
4520
Description: "AWS cluster configuration",
4621
Type: "object",
47-
Properties: clusterConfigProps,
48-
Required: []string{"region"},
22+
Properties: map[string]clusterv1.JSONSchemaProps{
23+
"region": Region("").VariableSchema().OpenAPIV3Schema,
24+
},
25+
Required: []string{"region"},
4926
},
5027
}
5128
}
@@ -61,7 +38,3 @@ func (Region) VariableSchema() clusterv1.VariableSchema {
6138
},
6239
}
6340
}
64-
65-
func init() {
66-
SchemeBuilder.Register(&AWSClusterConfig{})
67-
}

api/v1alpha1/clusterconfig_types.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
package v1alpha1
55

66
import (
7+
"maps"
8+
79
corev1 "k8s.io/api/core/v1"
10+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
811
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
912

1013
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/variables"
@@ -15,6 +18,60 @@ const (
1518
CNIProviderCalico = "calico"
1619
)
1720

21+
//+kubebuilder:object:root=true
22+
23+
// ClusterConfig is the Schema for the clusterconfigs API.
24+
type ClusterConfig struct {
25+
metav1.TypeMeta `json:",inline"`
26+
metav1.ObjectMeta `json:"metadata,omitempty"`
27+
28+
//+optional
29+
Spec ClusterConfigSpec `json:"spec,omitempty"`
30+
}
31+
32+
// ClusterConfigSpec defines the desired state of ClusterConfig.
33+
type ClusterConfigSpec struct {
34+
// +optional
35+
AWS *AWSSpec `json:"aws,omitempty"`
36+
// +optional
37+
Docker *DockerSpec `json:"docker,omitempty"`
38+
39+
GenericClusterConfig `json:",inline"`
40+
}
41+
42+
func (s ClusterConfigSpec) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect.
43+
clusterConfigProps := GenericClusterConfig{}.VariableSchema()
44+
45+
switch {
46+
case s.AWS != nil:
47+
maps.Copy(
48+
clusterConfigProps.OpenAPIV3Schema.Properties,
49+
map[string]clusterv1.JSONSchemaProps{
50+
"aws": AWSSpec{}.VariableSchema().OpenAPIV3Schema,
51+
},
52+
)
53+
54+
clusterConfigProps.OpenAPIV3Schema.Required = append(
55+
clusterConfigProps.OpenAPIV3Schema.Required,
56+
"aws",
57+
)
58+
case s.Docker != nil:
59+
maps.Copy(
60+
clusterConfigProps.OpenAPIV3Schema.Properties,
61+
map[string]clusterv1.JSONSchemaProps{
62+
"docker": DockerSpec{}.VariableSchema().OpenAPIV3Schema,
63+
},
64+
)
65+
66+
clusterConfigProps.OpenAPIV3Schema.Required = append(
67+
clusterConfigProps.OpenAPIV3Schema.Required,
68+
"docker",
69+
)
70+
}
71+
72+
return clusterConfigProps
73+
}
74+
1875
// GenericClusterConfig defines the generic cluster configdesired.
1976
type GenericClusterConfig struct {
2077
// +optional
@@ -312,3 +369,7 @@ func (NFD) VariableSchema() clusterv1.VariableSchema {
312369
},
313370
}
314371
}
372+
373+
func init() {
374+
SchemeBuilder.Register(&ClusterConfig{})
375+
}

api/v1alpha1/docker_clusterconfig_types.go

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,24 @@
44
package v1alpha1
55

66
import (
7-
"maps"
8-
9-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
107
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
118

129
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/openapi/patterns"
1310
)
1411

15-
//+kubebuilder:object:root=true
16-
17-
// DockerClusterConfig is the Schema for the dockerclusterconfigs API.
18-
type DockerClusterConfig struct {
19-
metav1.TypeMeta `json:",inline"`
20-
metav1.ObjectMeta `json:"metadata,omitempty"`
21-
22-
Spec DockerClusterConfigSpec `json:"spec,omitempty"`
23-
}
24-
25-
// DockerClusterConfigSpec defines the desired state of DockerClusterConfig.
26-
type DockerClusterConfigSpec struct {
27-
GenericClusterConfig `json:",inline"`
28-
12+
type DockerSpec struct {
2913
//+optional
3014
CustomImage *OCIImage `json:"customImage,omitempty"`
3115
}
3216

33-
func (DockerClusterConfigSpec) VariableSchema() clusterv1.VariableSchema {
34-
clusterConfigProps := GenericClusterConfig{}.VariableSchema().OpenAPIV3Schema.Properties
35-
36-
maps.Copy(
37-
clusterConfigProps,
38-
map[string]clusterv1.JSONSchemaProps{
39-
"customImage": OCIImage("").VariableSchema().OpenAPIV3Schema,
40-
},
41-
)
42-
17+
func (DockerSpec) VariableSchema() clusterv1.VariableSchema {
4318
return clusterv1.VariableSchema{
4419
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
4520
Description: "Docker cluster configuration",
4621
Type: "object",
47-
Properties: clusterConfigProps,
22+
Properties: map[string]clusterv1.JSONSchemaProps{
23+
"customImage": OCIImage("").VariableSchema().OpenAPIV3Schema,
24+
},
4825
},
4926
}
5027
}
@@ -60,7 +37,3 @@ func (OCIImage) VariableSchema() clusterv1.VariableSchema {
6037
},
6138
}
6239
}
63-
64-
func init() {
65-
SchemeBuilder.Register(&DockerClusterConfig{})
66-
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 38 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/customization/aws/region.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ spec:
2121
variables:
2222
- name: clusterConfig
2323
values:
24-
region: us-west-2
24+
aws:
25+
region: us-west-2
2526
```
2627
2728
Applying this configuration will result in the following value being set:

examples/capi-quick-start/aws-cluster.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ spec:
2424
cni:
2525
provider: calico
2626
nfd: {}
27+
aws: {}
2728
version: v1.27.5
2829
workers:
2930
machineDeployments:

examples/capi-quick-start/docker-cluster.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ spec:
2525
cni:
2626
provider: calico
2727
nfd: {}
28+
docker: {}
2829
version: v1.27.5
2930
workers:
3031
machineDeployments:

hack/examples/bases/aws/kustomization.yaml.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ patches:
3030
path: "/spec/topology/variables"
3131
value:
3232
- name: "clusterConfig"
33-
value: {}
33+
value:
34+
aws: {}
3435
- target:
3536
group: cluster.x-k8s.io
3637
kind: ClusterClass

hack/examples/bases/docker/kustomization.yaml.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ patches:
3030
path: "/spec/topology/variables"
3131
value:
3232
- name: "clusterConfig"
33-
value: {}
33+
value:
34+
docker: {}
3435
- target:
3536
group: cluster.x-k8s.io
3637
kind: ClusterClass

0 commit comments

Comments
 (0)