Skip to content

Commit eb8da02

Browse files
committed
feat: publish first working version
This PR will be the first working version of our control plane provider. Signed-off-by: Spencer Smith <[email protected]>
1 parent b50cd88 commit eb8da02

Some content is hidden

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

48 files changed

+2614
-10
lines changed

Dockerfile

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ 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].5
8+
RUN go get sigs.k8s.io/controller-tools/cmd/[email protected].8
99
WORKDIR /src
1010
COPY ./go.mod ./
1111
COPY ./go.sum ./
@@ -17,7 +17,8 @@ RUN ! go mod tidy -v 2>&1 | grep .
1717

1818
FROM build AS manifests-build
1919
ARG NAME
20-
RUN controller-gen rbac:roleName=${NAME}-role crd paths="./..." output:rbac:artifacts:config=config/rbac output:crd:artifacts:config=config/crd/bases
20+
RUN controller-gen crd:crdVersions=v1 paths="./api/..." output:crd:dir=config/crd/bases output:webhook:dir=config/webhook webhook
21+
RUN controller-gen rbac:roleName=manager-role paths="./controllers/..." output:rbac:dir=config/rbac
2122
FROM scratch AS manifests
2223
COPY --from=manifests-build /src/config/crd /config/crd
2324
COPY --from=manifests-build /src/config/rbac /config/rbac
@@ -30,19 +31,22 @@ COPY --from=generate-build /src/api /api
3031
FROM k8s.gcr.io/hyperkube:v1.17.0 AS release-build
3132
RUN apt update -y \
3233
&& apt install -y curl \
33-
&& curl -LO https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv3.4.0/kustomize_v3.4.0_linux_amd64.tar.gz \
34-
&& tar -xf kustomize_v3.4.0_linux_amd64.tar.gz -C /usr/local/bin \
35-
&& rm kustomize_v3.4.0_linux_amd64.tar.gz
34+
&& curl -LO https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv3.5.4/kustomize_v3.5.4_linux_amd64.tar.gz \
35+
&& tar -xf kustomize_v3.5.4_linux_amd64.tar.gz -C /usr/local/bin \
36+
&& rm kustomize_v3.5.4_linux_amd64.tar.gz
3637
COPY ./config ./config
3738
ARG REGISTRY_AND_USERNAME
3839
ARG NAME
3940
ARG TAG
4041
RUN cd config/manager \
4142
&& kustomize edit set image controller=${REGISTRY_AND_USERNAME}/${NAME}:${TAG} \
4243
&& cd - \
43-
&& kubectl kustomize config >/release.yaml
44+
&& kustomize config >/control-plane-components.yaml \
45+
&& cp config/metadata/metadata.yaml /metadata.yaml
46+
4447
FROM scratch AS release
45-
COPY --from=release-build /release.yaml /release.yaml
48+
COPY --from=release-build /control-plane-components.yaml /control-plane-components.yaml
49+
COPY --from=release-build /metadata.yaml /metadata.yaml
4650

4751
FROM build AS binary
4852
RUN --mount=type=cache,target=/root/.cache/go-build GOOS=linux go build -ldflags "-s -w" -o /manager

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ SHA ?= $(shell git describe --match=none --always --abbrev=8 --dirty)
44
TAG ?= $(shell git describe --tag --always --dirty)
55
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
66
REGISTRY_AND_USERNAME := $(REGISTRY)/$(USERNAME)
7-
NAME := template-controller-manager
7+
NAME := cluster-api-control-plane-talos-controller
88

99
ARTIFACTS := _out
1010

@@ -42,7 +42,7 @@ apiVersion: kustomize.config.k8s.io/v1beta1
4242
kind: Kustomization
4343
namespace: $(NAMESPACE)
4444
commonLabels:
45-
app: template-controller-manager
45+
app: cluster-api-control-plane-provider-talos
4646
bases:
4747
- crd
4848
- rbac

PROJECT

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
domain: controlplane.cluster.x-k8s.io
2+
repo: github.com/talos-systems/cluster-api-control-plane-provider-talos
3+
resources:
4+
- group: controlplane
5+
kind: TalosControlPlane
6+
version: v1alpha3
7+
version: "2"

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
Initializing a new project.
44

55
```bash
6-
make init DOMAIN=domain.tld NAMESPACE=template
6+
controlplane.cluster.x-k8s.io
7+
make init DOMAIN=controlplane.cluster.x-k8s.io NAMESPACE=template
78
```
89

910
Rename the controller.

api/v1alpha3/groupversion_info.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
// Package v1alpha3 contains API Schema definitions for the controlplane v1alpha3 API group
6+
// +kubebuilder:object:generate=true
7+
// +groupName=controlplane.cluster.x-k8s.io
8+
package v1alpha3
9+
10+
import (
11+
"k8s.io/apimachinery/pkg/runtime/schema"
12+
"sigs.k8s.io/controller-runtime/pkg/scheme"
13+
)
14+
15+
var (
16+
// GroupVersion is group version used to register these objects
17+
GroupVersion = schema.GroupVersion{Group: "controlplane.cluster.x-k8s.io", Version: "v1alpha3"}
18+
19+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
20+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
21+
22+
// AddToScheme adds the types in this group-version to the given scheme.
23+
AddToScheme = SchemeBuilder.AddToScheme
24+
)
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
package v1alpha3
6+
7+
import (
8+
cabptv1 "github.com/talos-systems/cluster-api-bootstrap-provider-talos/api/v1alpha3"
9+
corev1 "k8s.io/api/core/v1"
10+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
)
12+
13+
const (
14+
TalosControlPlaneFinalizer = "talos.controlplane.cluster.x-k8s.io"
15+
)
16+
17+
type ControlPlaneConfig struct {
18+
InitConfig cabptv1.TalosConfigSpec `json:"init"`
19+
ControlPlaneConfig cabptv1.TalosConfigSpec `json:"controlplane"`
20+
}
21+
22+
// TalosControlPlaneSpec defines the desired state of TalosControlPlane
23+
type TalosControlPlaneSpec struct {
24+
// Number of desired machines. Defaults to 1. When stacked etcd is used only
25+
// odd numbers are permitted, as per [etcd best practice](https://etcd.io/docs/v3.3.12/faq/#why-an-odd-number-of-cluster-members).
26+
// This is a pointer to distinguish between explicit zero and not specified.
27+
// +optional
28+
Replicas *int32 `json:"replicas,omitempty"`
29+
30+
// Version defines the desired Kubernetes version.
31+
// +kubebuilder:validation:MinLength:=2
32+
// +kubebuilder:validation:Pattern:=^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)([-0-9a-zA-Z_\.+]*)?$
33+
Version string `json:"version"`
34+
35+
// InfrastructureTemplate is a required reference to a custom resource
36+
// offered by an infrastructure provider.
37+
InfrastructureTemplate corev1.ObjectReference `json:"infrastructureTemplate"`
38+
39+
// ControlPlaneConfig is a two TalosConfigSpecs
40+
// to use for initializing and joining machines to the control plane.
41+
ControlPlaneConfig ControlPlaneConfig `json:"controlPlaneConfig"`
42+
}
43+
44+
// TalosControlPlaneStatus defines the observed state of TalosControlPlane
45+
type TalosControlPlaneStatus struct {
46+
// Selector is the label selector in string format to avoid introspection
47+
// by clients, and is used to provide the CRD-based integration for the
48+
// scale subresource and additional integrations for things like kubectl
49+
// describe.. The string will be in the same format as the query-param syntax.
50+
// More info about label selectors: http://kubernetes.io/docs/user-guide/labels#label-selectors
51+
// +optional
52+
Selector string `json:"selector,omitempty"`
53+
54+
// Total number of non-terminated machines targeted by this control plane
55+
// (their labels match the selector).
56+
// +optional
57+
Replicas int32 `json:"replicas,omitempty"`
58+
59+
// Total number of fully running and ready control plane machines.
60+
// +optional
61+
ReadyReplicas int32 `json:"readyReplicas,omitempty"`
62+
63+
// Total number of unavailable machines targeted by this control plane.
64+
// This is the total number of machines that are still required for
65+
// the deployment to have 100% available capacity. They may either
66+
// be machines that are running but not yet ready or machines
67+
// that still have not been created.
68+
// +optional
69+
UnavailableReplicas int32 `json:"unavailableReplicas,omitempty"`
70+
71+
// Initialized denotes whether or not the control plane has the
72+
// uploaded talos-config configmap.
73+
// +optional
74+
Initialized bool `json:"initialized"`
75+
76+
// Ready denotes that the TalosControlPlane API Server is ready to
77+
// receive requests.
78+
// +optional
79+
Ready bool `json:"ready"`
80+
81+
// FailureReason indicates that there is a terminal problem reconciling the
82+
// state, and will be set to a token value suitable for
83+
// programmatic interpretation.
84+
// +optional
85+
FailureReason *string `json:"failureReason,omitempty"`
86+
87+
// ErrorMessage indicates that there is a terminal problem reconciling the
88+
// state, and will be set to a descriptive error message.
89+
// +optional
90+
FailureMessage *string `json:"failureMessage,omitempty"`
91+
}
92+
93+
// +kubebuilder:object:root=true
94+
// +kubebuilder:resource:path=taloscontrolplanes,shortName=tcp,scope=Namespaced,categories=cluster-api
95+
// +kubebuilder:storageversion
96+
// +kubebuilder:subresource:status
97+
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector
98+
// +kubebuilder:printcolumn:name="Ready",type=boolean,JSONPath=".status.ready",description="TalosControlPlane API Server is ready to receive requests"
99+
// +kubebuilder:printcolumn:name="Initialized",type=boolean,JSONPath=".status.initialized",description="This denotes whether or not the control plane has the uploaded talos-config configmap"
100+
// +kubebuilder:printcolumn:name="Replicas",type=integer,JSONPath=".status.replicas",description="Total number of non-terminated machines targeted by this control plane"
101+
// +kubebuilder:printcolumn:name="Ready Replicas",type=integer,JSONPath=".status.readyReplicas",description="Total number of fully running and ready control plane machines"
102+
// +kubebuilder:printcolumn:name="Unavailable Replicas",type=integer,JSONPath=".status.unavailableReplicas",description="Total number of unavailable machines targeted by this control plane"
103+
104+
// TalosControlPlane is the Schema for the taloscontrolplanes API
105+
type TalosControlPlane struct {
106+
metav1.TypeMeta `json:",inline"`
107+
metav1.ObjectMeta `json:"metadata,omitempty"`
108+
109+
Spec TalosControlPlaneSpec `json:"spec,omitempty"`
110+
Status TalosControlPlaneStatus `json:"status,omitempty"`
111+
}
112+
113+
// +kubebuilder:object:root=true
114+
115+
// TalosControlPlaneList contains a list of TalosControlPlane
116+
type TalosControlPlaneList struct {
117+
metav1.TypeMeta `json:",inline"`
118+
metav1.ListMeta `json:"metadata,omitempty"`
119+
Items []TalosControlPlane `json:"items"`
120+
}
121+
122+
func init() {
123+
SchemeBuilder.Register(&TalosControlPlane{}, &TalosControlPlaneList{})
124+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package v1alpha3
2+
3+
import (
4+
ctrl "sigs.k8s.io/controller-runtime"
5+
)
6+
7+
func (r *TalosControlPlane) SetupWebhookWithManager(mgr ctrl.Manager) error {
8+
return ctrl.NewWebhookManagedBy(mgr).
9+
For(r).
10+
Complete()
11+
}

api/v1alpha3/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)