Skip to content

Commit 2c66a05

Browse files
jimmidysondkoshkin
andauthored
feat: Combine generic variables with provider specific variables (#173)
Co-authored-by: Dimitri Koshkin <[email protected]>
1 parent b597e01 commit 2c66a05

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+565
-434
lines changed

api/v1alpha1/aws_clusterconfig_types.go

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

66
import (
7+
"maps"
8+
79
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
810
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
911

@@ -24,17 +26,26 @@ type AWSClusterConfig struct {
2426
type AWSClusterConfigSpec struct {
2527
// +optional
2628
Region *Region `json:"region,omitempty"`
29+
30+
GenericClusterConfig `json:",inline"`
2731
}
2832

2933
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+
3043
return clusterv1.VariableSchema{
3144
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
32-
Description: "AWS Cluster configuration",
45+
Description: "AWS cluster configuration",
3346
Type: "object",
34-
Properties: map[string]clusterv1.JSONSchemaProps{
35-
"region": Region("").VariableSchema().OpenAPIV3Schema,
36-
},
37-
Required: []string{"region"},
47+
Properties: clusterConfigProps,
48+
Required: []string{"region"},
3849
},
3950
}
4051
}

api/v1alpha1/clusterconfig_types.go

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package v1alpha1
55

66
import (
7-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
87
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
98

109
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/variables"
@@ -15,18 +14,8 @@ const (
1514
CNIProviderCalico = "calico"
1615
)
1716

18-
//+kubebuilder:object:root=true
19-
20-
// ClusterConfig is the Schema for the clusterconfigs API.
21-
type ClusterConfig struct {
22-
metav1.TypeMeta `json:",inline"`
23-
metav1.ObjectMeta `json:"metadata,omitempty"`
24-
25-
Spec ClusterConfigSpec `json:"spec,omitempty"`
26-
}
27-
28-
// ClusterConfigSpec defines the desired state of ClusterConfig.
29-
type ClusterConfigSpec struct {
17+
// GenericClusterConfig defines the generic cluster configdesired.
18+
type GenericClusterConfig struct {
3019
// +optional
3120
KubernetesImageRepository *KubernetesImageRepository `json:"kubernetesImageRepository,omitempty"`
3221

@@ -43,7 +32,7 @@ type ClusterConfigSpec struct {
4332
Addons *Addons `json:"addons,omitempty"`
4433
}
4534

46-
func (ClusterConfigSpec) VariableSchema() clusterv1.VariableSchema {
35+
func (GenericClusterConfig) VariableSchema() clusterv1.VariableSchema {
4736
return clusterv1.VariableSchema{
4837
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
4938
Description: "Cluster configuration",
@@ -240,8 +229,3 @@ func (NFD) VariableSchema() clusterv1.VariableSchema {
240229
},
241230
}
242231
}
243-
244-
// +kubebuilder:object:root=true
245-
func init() {
246-
SchemeBuilder.Register(&ClusterConfig{})
247-
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2023 D2iQ, Inc. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package v1alpha1
5+
6+
import (
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
9+
)
10+
11+
//+kubebuilder:object:root=true
12+
13+
// DockerClusterConfig is the Schema for the dockerclusterconfigs API.
14+
type DockerClusterConfig struct {
15+
metav1.TypeMeta `json:",inline"`
16+
metav1.ObjectMeta `json:"metadata,omitempty"`
17+
18+
Spec AWSClusterConfigSpec `json:"spec,omitempty"`
19+
}
20+
21+
// DockerClusterConfigSpec defines the desired state of DockerClusterConfig.
22+
type DockerClusterConfigSpec struct {
23+
GenericClusterConfig `json:",inline"`
24+
}
25+
26+
func (DockerClusterConfigSpec) VariableSchema() clusterv1.VariableSchema {
27+
clusterConfigProps := GenericClusterConfig{}.VariableSchema().OpenAPIV3Schema.Properties
28+
29+
return clusterv1.VariableSchema{
30+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
31+
Description: "Docker cluster configuration",
32+
Type: "object",
33+
Properties: clusterConfigProps,
34+
},
35+
}
36+
}
37+
38+
func init() {
39+
SchemeBuilder.Register(&DockerClusterConfig{})
40+
}

api/v1alpha1/zz_generated.deepcopy.go

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

cmd/main.go

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/server"
3030
awsclusterconfig "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/aws/clusterconfig"
3131
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/aws/mutation/region"
32-
genericclusterconfig "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/clusterconfig"
32+
dockerclusterconfig "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/docker/clusterconfig"
3333
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/lifecycle/cni/calico"
3434
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/lifecycle/nfd"
3535
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/lifecycle/servicelbgc"
@@ -119,60 +119,49 @@ func main() {
119119
}
120120

121121
// Handlers for lifecycle hooks.
122-
genericLifeCycleHandlers := []handlers.Named{
122+
genericLifecycleHandlers := []handlers.Named{
123+
calico.New(mgr.GetClient(), calicoCNIConfig),
124+
nfd.New(mgr.GetClient(), nfdConfig),
123125
servicelbgc.New(mgr.GetClient()),
124126
}
125-
// Handlers that apply patches to the Cluster object and its objects.
126-
// Used by CAPI's GeneratePatches hook.
127-
genericPatchHandlers := []handlers.Named{
128-
httpproxy.NewPatch(mgr.GetClient()),
129-
extraapiservercertsans.NewPatch(),
130-
auditpolicy.NewPatch(),
131-
kubernetesimagerepository.NewPatch(),
132-
etcd.NewPatch(),
133-
}
134-
// Handlers used by CAPI's DiscoverVariables hook.
135-
// It's ok that this does not match patchHandlers.
136-
// Some of those handlers may always get applied and not have a corresponding variable.
137-
genericVariableHandlers := []handlers.Named{
138-
httpproxy.NewVariable(),
139-
extraapiservercertsans.NewVariable(),
140-
kubernetesimagerepository.NewVariable(),
141-
}
127+
142128
// This genericMetaPatchHandlers combines all other patch and variable handlers under a single handler.
143129
// It allows to specify configuration under a single variable.
144130
genericMetaPatchHandlers := []mutation.MetaMutater{
145-
httpproxy.NewMetaPatch(mgr.GetClient()),
146-
extraapiservercertsans.NewMetaPatch(),
147131
auditpolicy.NewPatch(),
148-
kubernetesimagerepository.NewMetaPatch(),
149132
etcd.NewMetaPatch(),
150-
}
151-
genericMetaHandlers := []handlers.Named{
152-
// This Calico handler relies on a variable but does not generate a patch.
153-
// Instead it creates other resources in the API.
154-
calico.NewMetaHandler(mgr.GetClient(), calicoCNIConfig),
155-
nfd.NewMetaHandler(mgr.GetClient(), nfdConfig),
156-
genericclusterconfig.NewVariable(),
157-
mutation.NewMetaGeneratePatchesHandler("clusterConfigPatch", genericMetaPatchHandlers...),
133+
extraapiservercertsans.NewMetaPatch(),
134+
httpproxy.NewMetaPatch(mgr.GetClient()),
135+
kubernetesimagerepository.NewMetaPatch(),
158136
}
159137

160-
// This awsMetaPatchHandlers combines all AWS patch and variable handlers under a single handler.
138+
// awsMetaPatchHandlers combines all AWS patch and variable handlers under a single handler.
161139
// It allows to specify configuration under a single variable.
162-
awsMetaPatchHandlers := []mutation.MetaMutater{
163-
region.NewMetaPatch(),
164-
}
140+
awsMetaPatchHandlers := append(
141+
[]mutation.MetaMutater{
142+
region.NewMetaPatch(),
143+
},
144+
genericMetaPatchHandlers...,
145+
)
165146
awsMetaHandlers := []handlers.Named{
166147
awsclusterconfig.NewVariable(),
167148
mutation.NewMetaGeneratePatchesHandler("awsClusterConfigPatch", awsMetaPatchHandlers...),
168149
}
169150

151+
// dockerMetaPatchHandlers combines all Docker patch and variable handlers under a single handler.
152+
// It allows to specify configuration under a single variable.
153+
dockerMetaPatchHandlers := []mutation.MetaMutater{}
154+
dockerMetaHandlers := []handlers.Named{
155+
dockerclusterconfig.NewVariable(),
156+
mutation.NewMetaGeneratePatchesHandler(
157+
"dockerClusterConfigPatch",
158+
dockerMetaPatchHandlers...),
159+
}
160+
170161
var allHandlers []handlers.Named
171-
allHandlers = append(allHandlers, genericLifeCycleHandlers...)
172-
allHandlers = append(allHandlers, genericPatchHandlers...)
173-
allHandlers = append(allHandlers, genericVariableHandlers...)
174-
allHandlers = append(allHandlers, genericMetaHandlers...)
162+
allHandlers = append(allHandlers, genericLifecycleHandlers...)
175163
allHandlers = append(allHandlers, awsMetaHandlers...)
164+
allHandlers = append(allHandlers, dockerMetaHandlers...)
176165

177166
runtimeWebhookServer := server.NewServer(runtimeWebhookServerOpts, allHandlers...)
178167

devbox.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,12 @@
3535
"yamale@latest",
3636
"yamllint@latest",
3737
"kind@latest"
38-
]
38+
],
39+
"shell": {
40+
"scripts": {
41+
"preview-docs": [
42+
"cd docs && hugo serve -F -D"
43+
]
44+
}
45+
}
3946
}

docs/archetypes/default.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
---
2-
title: "{{ replace .Name "-" " " | title }}"
3-
date: {{ .Date }}
4-
---
1+
+++
2+
title = "{{ replace .Name "-" " " | title }}"
3+
+++

docs/content/_index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
+++
22
title = "CAPI Runtime Extensions"
33

4-
[[cascade]]
5-
type = "blog"
6-
toc_root = true
4+
# [[cascade]]
5+
# type = "blog"
6+
# toc_root = true
77

8-
[cascade._target]
9-
path = "/news/**"
8+
# [cascade._target]
9+
# path = "/blog/**"
1010

1111
[[cascade]]
1212
type = "docs"

0 commit comments

Comments
 (0)