|
| 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 | +} |
0 commit comments