Skip to content

Commit fc2ef20

Browse files
dkoshkinjimmidyson
andauthored
feat: Add worker configs var and handler (#208)
This adds code to set worker overrides to clusterConfig, here is an example of how to use it: ```yaml topology: class: docker-quick-start controlPlane: metadata: {} replicas: 1 variables: - name: clusterConfig value: addons: cni: provider: calico nfd: {} controlPlane: docker: customImage: ghcr.io/mesosphere/kind-node:v1.2.3-cp docker: {} - name: workerConfig value: docker: customImage: ghcr.io/mesosphere/kind-node:v1.2.3-worker version: v1.27.5 workers: machineDeployments: - class: default-worker metadata: {} name: md-0 replicas: 1 - class: default-worker metadata: {} name: md-1 replicas: 1 variables: overrides: - name: workerConfig value: docker: customImage: ghcr.io/mesosphere/kind-node:v1.2.3-custom ``` --------- Co-authored-by: Jimmi Dyson <[email protected]>
1 parent af46151 commit fc2ef20

File tree

34 files changed

+919
-153
lines changed

34 files changed

+919
-153
lines changed

api/v1alpha1/aws_node_types.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2023 D2iQ, Inc. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package v1alpha1
5+
6+
import clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
7+
8+
type AWSNodeSpec struct{}
9+
10+
func (AWSNodeSpec) VariableSchema() clusterv1.VariableSchema {
11+
return clusterv1.VariableSchema{
12+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
13+
Description: "AWS Node configuration",
14+
Type: "object",
15+
Properties: map[string]clusterv1.JSONSchemaProps{},
16+
},
17+
}
18+
}

api/v1alpha1/clusterconfig_types.go

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

3939
GenericClusterConfig `json:",inline"`
40+
41+
//+optional
42+
ControlPlane *NodeConfigSpec `json:"controlPlane,omitempty"`
4043
}
4144

4245
func (s ClusterConfigSpec) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect.
@@ -48,25 +51,21 @@ func (s ClusterConfigSpec) VariableSchema() clusterv1.VariableSchema { //nolint:
4851
clusterConfigProps.OpenAPIV3Schema.Properties,
4952
map[string]clusterv1.JSONSchemaProps{
5053
"aws": AWSSpec{}.VariableSchema().OpenAPIV3Schema,
54+
"controlPlane": NodeConfigSpec{
55+
AWS: &AWSNodeSpec{},
56+
}.VariableSchema().OpenAPIV3Schema,
5157
},
5258
)
53-
54-
clusterConfigProps.OpenAPIV3Schema.Required = append(
55-
clusterConfigProps.OpenAPIV3Schema.Required,
56-
"aws",
57-
)
5859
case s.Docker != nil:
5960
maps.Copy(
6061
clusterConfigProps.OpenAPIV3Schema.Properties,
6162
map[string]clusterv1.JSONSchemaProps{
6263
"docker": DockerSpec{}.VariableSchema().OpenAPIV3Schema,
64+
"controlPlane": NodeConfigSpec{
65+
Docker: &DockerNodeSpec{},
66+
}.VariableSchema().OpenAPIV3Schema,
6367
},
6468
)
65-
66-
clusterConfigProps.OpenAPIV3Schema.Required = append(
67-
clusterConfigProps.OpenAPIV3Schema.Required,
68-
"docker",
69-
)
7069
}
7170

7271
return clusterConfigProps
@@ -93,7 +92,7 @@ type GenericClusterConfig struct {
9392
Addons *Addons `json:"addons,omitempty"`
9493
}
9594

96-
func (GenericClusterConfig) VariableSchema() clusterv1.VariableSchema {
95+
func (s GenericClusterConfig) VariableSchema() clusterv1.VariableSchema {
9796
return clusterv1.VariableSchema{
9897
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
9998
Description: "Cluster configuration",

api/v1alpha1/docker_clusterconfig_types.go

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,16 @@ package v1alpha1
55

66
import (
77
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
8-
9-
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/openapi/patterns"
108
)
119

12-
type DockerSpec struct {
13-
//+optional
14-
CustomImage *OCIImage `json:"customImage,omitempty"`
15-
}
10+
type DockerSpec struct{}
1611

1712
func (DockerSpec) VariableSchema() clusterv1.VariableSchema {
1813
return clusterv1.VariableSchema{
1914
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
2015
Description: "Docker cluster configuration",
2116
Type: "object",
22-
Properties: map[string]clusterv1.JSONSchemaProps{
23-
"customImage": OCIImage("").VariableSchema().OpenAPIV3Schema,
24-
},
25-
},
26-
}
27-
}
28-
29-
type OCIImage string
30-
31-
func (OCIImage) VariableSchema() clusterv1.VariableSchema {
32-
return clusterv1.VariableSchema{
33-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
34-
Description: "Custom OCI image for control plane and worker nodes.",
35-
Type: "string",
36-
Pattern: patterns.Anchored(patterns.ImageReference),
17+
Properties: map[string]clusterv1.JSONSchemaProps{},
3718
},
3819
}
3920
}

api/v1alpha1/docker_node_types.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2023 D2iQ, Inc. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package v1alpha1
5+
6+
import (
7+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
8+
9+
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/openapi/patterns"
10+
)
11+
12+
type DockerNodeSpec struct {
13+
//+optional
14+
CustomImage *OCIImage `json:"customImage,omitempty"`
15+
}
16+
17+
func (DockerNodeSpec) VariableSchema() clusterv1.VariableSchema {
18+
return clusterv1.VariableSchema{
19+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
20+
Description: "Docker Node configuration",
21+
Type: "object",
22+
Properties: map[string]clusterv1.JSONSchemaProps{
23+
"customImage": OCIImage("").VariableSchema().OpenAPIV3Schema,
24+
},
25+
},
26+
}
27+
}
28+
29+
type OCIImage string
30+
31+
func (OCIImage) VariableSchema() clusterv1.VariableSchema {
32+
return clusterv1.VariableSchema{
33+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
34+
Description: "Custom OCI image for control plane and worker Nodes.",
35+
Type: "string",
36+
Pattern: patterns.Anchored(patterns.ImageReference),
37+
},
38+
}
39+
}

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/zz_generated.deepcopy.go

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

charts/capi-runtime-extensions/defaultclusterclasses/aws-cluster-class.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ spec:
2525
discoverVariablesExtension: awsclusterconfigvars.capi-runtime-extensions
2626
generateExtension: awsclusterconfigpatch.capi-runtime-extensions
2727
name: cluster-config
28+
- external:
29+
discoverVariablesExtension: awsworkerconfigvars.capi-runtime-extensions
30+
generateExtension: awsworkerconfigpatch.capi-runtime-extensions
31+
name: worker-config
2832
- definitions:
2933
- jsonPatches:
3034
- op: add

charts/capi-runtime-extensions/defaultclusterclasses/docker-cluster-class.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ spec:
2525
discoverVariablesExtension: dockerclusterconfigvars.capi-runtime-extensions
2626
generateExtension: dockerclusterconfigpatch.capi-runtime-extensions
2727
name: cluster-config
28+
- external:
29+
discoverVariablesExtension: dockerworkerconfigvars.capi-runtime-extensions
30+
generateExtension: dockerworkerconfigpatch.capi-runtime-extensions
31+
name: worker-config
2832
workers:
2933
machineDeployments:
3034
- class: default-worker

0 commit comments

Comments
 (0)