Skip to content

Commit b07e2c7

Browse files
committed
feat: introduce v1alpha3 support
This PR will allow our bootstrap provider to support the v1alpha3 cluster api. It is also backwards compatible with v1alpha2. Signed-off-by: Spencer Smith <[email protected]>
1 parent f6d6df8 commit b07e2c7

Some content is hidden

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

50 files changed

+1478
-400
lines changed

Dockerfile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ ENV GO111MODULE on
55
ENV GOPROXY https://proxy.golang.org
66
ENV CGO_ENABLED 0
77
WORKDIR /tmp
8-
RUN go get sigs.k8s.io/controller-tools/cmd/[email protected]
8+
RUN go get sigs.k8s.io/controller-tools/cmd/[email protected]
9+
RUN go get k8s.io/code-generator/cmd/[email protected]
910
WORKDIR /src
1011
COPY ./go.mod ./
1112
COPY ./go.sum ./
@@ -17,13 +18,14 @@ RUN ! go mod tidy -v 2>&1 | grep .
1718

1819
FROM build AS manifests-build
1920
ARG NAME
20-
RUN controller-gen rbac:roleName=manager-role crd paths="./..." output:rbac:artifacts:config=config/rbac output:crd:artifacts:config=config/crd/bases
21+
RUN controller-gen crd:crdVersions=v1 paths="./api/..." output:crd:dir=config/crd/bases output:webhook:dir=config/webhook webhook
22+
RUN controller-gen rbac:roleName=manager-role paths="./controllers/..." output:rbac:dir=config/rbac
2123
FROM scratch AS manifests
22-
COPY --from=manifests-build /src/config/crd /config/crd
23-
COPY --from=manifests-build /src/config/rbac /config/rbac
24+
COPY --from=manifests-build /src/config /config
2425

2526
FROM build AS generate-build
2627
RUN controller-gen object:headerFile=./hack/boilerplate.go.txt paths="./..."
28+
RUN conversion-gen --input-dirs=./api/v1alpha2 --output-base ./ --output-file-base=zz_generated.conversion --go-header-file=./hack/boilerplate.go.txt
2729
FROM scratch AS generate
2830
COPY --from=generate-build /src/api /api
2931

@@ -40,7 +42,7 @@ ARG TAG
4042
RUN cd config/manager \
4143
&& kustomize edit set image controller=${REGISTRY_AND_USERNAME}/${NAME}:${TAG} \
4244
&& cd - \
43-
&& kubectl kustomize config/default >/bootstrap-components.yaml \
45+
&& kustomize build config > /bootstrap-components.yaml \
4446
&& cp config/metadata/metadata.yaml /metadata.yaml
4547
FROM scratch AS release
4648
COPY --from=release-build /bootstrap-components.yaml /bootstrap-components.yaml

PROJECT

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@ resources:
77
- group: bootstrap
88
kind: TalosConfigTemplate
99
version: v1alpha2
10+
- group: bootstrap
11+
kind: TalosConfig
12+
version: v1alpha3
13+
- group: bootstrap
14+
kind: TalosConfigTemplate
15+
version: v1alpha3
1016
version: "2"

api/v1alpha2/doc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package v1alpha2
2+
3+
// +k8s:conversion-gen=github.com/talos-systems/cluster-api-bootstrap-provider-talos/api/v1alpha3

api/v1alpha2/groupversion_info.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ var (
3232

3333
// AddToScheme adds the types in this group-version to the given scheme.
3434
AddToScheme = SchemeBuilder.AddToScheme
35+
36+
// localSchemeBuilder is used for type conversions.
37+
localSchemeBuilder = SchemeBuilder.SchemeBuilder
3538
)
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package v1alpha2
2+
3+
import (
4+
bootstrapv1alpha3 "github.com/talos-systems/cluster-api-bootstrap-provider-talos/api/v1alpha3"
5+
apiconversion "k8s.io/apimachinery/pkg/conversion"
6+
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
7+
"sigs.k8s.io/controller-runtime/pkg/conversion"
8+
)
9+
10+
// ConvertTo converts this TalosConfig to the Hub version (v1alpha3).
11+
func (src *TalosConfig) ConvertTo(dstRaw conversion.Hub) error {
12+
dst := dstRaw.(*bootstrapv1alpha3.TalosConfig)
13+
if err := Convert_v1alpha2_TalosConfig_To_v1alpha3_TalosConfig(src, dst, nil); err != nil {
14+
return err
15+
}
16+
17+
// Manually restore data.
18+
restored := &bootstrapv1alpha3.TalosConfig{}
19+
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
20+
return err
21+
}
22+
23+
dst.Status.DataSecretName = restored.Status.DataSecretName
24+
25+
return nil
26+
}
27+
28+
// ConvertFrom converts from the TalosConfig Hub version (v1alpha3) to this version.
29+
func (dst *TalosConfig) ConvertFrom(srcRaw conversion.Hub) error {
30+
src := srcRaw.(*bootstrapv1alpha3.TalosConfig)
31+
if err := Convert_v1alpha3_TalosConfig_To_v1alpha2_TalosConfig(src, dst, nil); err != nil {
32+
return nil
33+
}
34+
35+
// Preserve Hub data on down-conversion.
36+
if err := utilconversion.MarshalData(src, dst); err != nil {
37+
return err
38+
}
39+
40+
return nil
41+
}
42+
43+
// ConvertTo converts this TalosConfigList to the Hub version (v1alpha3).
44+
func (src *TalosConfigList) ConvertTo(dstRaw conversion.Hub) error {
45+
dst := dstRaw.(*bootstrapv1alpha3.TalosConfigList)
46+
return Convert_v1alpha2_TalosConfigList_To_v1alpha3_TalosConfigList(src, dst, nil)
47+
}
48+
49+
// ConvertFrom converts from the TalosConfigList Hub version (v1alpha3) to this version.
50+
func (dst *TalosConfigList) ConvertFrom(srcRaw conversion.Hub) error {
51+
src := srcRaw.(*bootstrapv1alpha3.TalosConfigList)
52+
return Convert_v1alpha3_TalosConfigList_To_v1alpha2_TalosConfigList(src, dst, nil)
53+
}
54+
55+
// ConvertTo converts this TalosConfigTemplate to the Hub version (v1alpha3).
56+
func (src *TalosConfigTemplate) ConvertTo(dstRaw conversion.Hub) error {
57+
dst := dstRaw.(*bootstrapv1alpha3.TalosConfigTemplate)
58+
return Convert_v1alpha2_TalosConfigTemplate_To_v1alpha3_TalosConfigTemplate(src, dst, nil)
59+
}
60+
61+
// ConvertFrom converts from the TalosConfigTemplate Hub version (v1alpha3) to this version.
62+
func (dst *TalosConfigTemplate) ConvertFrom(srcRaw conversion.Hub) error {
63+
src := srcRaw.(*bootstrapv1alpha3.TalosConfigTemplate)
64+
return Convert_v1alpha3_TalosConfigTemplate_To_v1alpha2_TalosConfigTemplate(src, dst, nil)
65+
}
66+
67+
// ConvertTo converts this TalosConfigTemplateList to the Hub version (v1alpha3).
68+
func (src *TalosConfigTemplateList) ConvertTo(dstRaw conversion.Hub) error {
69+
dst := dstRaw.(*bootstrapv1alpha3.TalosConfigTemplateList)
70+
return Convert_v1alpha2_TalosConfigTemplateList_To_v1alpha3_TalosConfigTemplateList(src, dst, nil)
71+
}
72+
73+
// ConvertFrom converts from the TalosConfigTemplateList Hub version (v1alpha3) to this version.
74+
func (dst *TalosConfigTemplateList) ConvertFrom(srcRaw conversion.Hub) error {
75+
src := srcRaw.(*bootstrapv1alpha3.TalosConfigTemplateList)
76+
return Convert_v1alpha3_TalosConfigTemplateList_To_v1alpha2_TalosConfigTemplateList(src, dst, nil)
77+
}
78+
79+
// Convert_v1alpha2_TalosConfigStatus_To_v1alpha3_TalosConfigStatus converts this TalosConfigStatus to the Hub version (v1alpha3).
80+
func Convert_v1alpha2_TalosConfigStatus_To_v1alpha3_TalosConfigStatus(in *TalosConfigStatus, out *bootstrapv1alpha3.TalosConfigStatus, s apiconversion.Scope) error {
81+
if err := autoConvert_v1alpha2_TalosConfigStatus_To_v1alpha3_TalosConfigStatus(in, out, s); err != nil {
82+
return err
83+
}
84+
85+
// Manually convert the Error fields to the Failure fields
86+
out.FailureMessage = in.ErrorMessage
87+
out.FailureReason = in.ErrorReason
88+
89+
return nil
90+
}
91+
92+
// Convert_v1alpha3_TalosConfigStatus_To_v1alpha2_TalosConfigStatus converts from the Hub version (v1alpha3) of the TalosConfigStatus to this version.
93+
func Convert_v1alpha3_TalosConfigStatus_To_v1alpha2_TalosConfigStatus(in *bootstrapv1alpha3.TalosConfigStatus, out *TalosConfigStatus, s apiconversion.Scope) error {
94+
if err := autoConvert_v1alpha3_TalosConfigStatus_To_v1alpha2_TalosConfigStatus(in, out, s); err != nil {
95+
return err
96+
}
97+
98+
// Manually convert the Failure fields to the Error fields
99+
out.ErrorMessage = in.FailureMessage
100+
out.ErrorReason = in.FailureReason
101+
102+
return nil
103+
}
104+
105+
// Convert_v1alpha2_TalosConfigSpec_To_v1alpha3_TalosConfigSpec converts this TalosConfigSpec to the Hub version (v1alpha3).
106+
func Convert_v1alpha2_TalosConfigSpec_To_v1alpha3_TalosConfigSpec(in *TalosConfigSpec, out *bootstrapv1alpha3.TalosConfigSpec, s apiconversion.Scope) error {
107+
return autoConvert_v1alpha2_TalosConfigSpec_To_v1alpha3_TalosConfigSpec(in, out, s)
108+
}
109+
110+
// Convert_v1alpha3_TalosConfigSpec_To_v1alpha2_TalosConfigSpec converts from the Hub version (v1alpha3) of the TalosConfigSpec to this version.
111+
func Convert_v1alpha3_TalosConfigSpec_To_v1alpha2_TalosConfigSpec(in *bootstrapv1alpha3.TalosConfigSpec, out *TalosConfigSpec, s apiconversion.Scope) error {
112+
return autoConvert_v1alpha3_TalosConfigSpec_To_v1alpha2_TalosConfigSpec(in, out, s)
113+
}

api/v1alpha2/talosconfig_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ type TalosConfigStatus struct {
5757
}
5858

5959
// +kubebuilder:object:root=true
60-
// +kubebuilder:storageversion
6160
// +kubebuilder:resource:path=talosconfigs,scope=Namespaced,categories=cluster-api
6261
// +kubebuilder:subresource:status
6362

api/v1alpha2/talosconfigtemplate_types.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,13 @@ import (
1919
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2020
)
2121

22-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
23-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
24-
2522
// TalosConfigTemplateSpec defines the desired state of TalosConfigTemplate
2623
type TalosConfigTemplateSpec struct {
2724
Template TalosConfigTemplateResource `json:"template"`
2825
}
2926

3027
// +kubebuilder:object:root=true
3128
// +kubebuilder:resource:path=talosconfigtemplates,scope=Namespaced,categories=cluster-api
32-
// +kubebuilder:storageversion
3329

3430
// TalosConfigTemplate is the Schema for the talosconfigtemplates API
3531
type TalosConfigTemplate struct {

0 commit comments

Comments
 (0)