Skip to content

Commit fbe998f

Browse files
committed
fixup! refactor: Add more kubebuilder annotations
1 parent 98b10c5 commit fbe998f

33 files changed

+495
-269
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ issues:
9999
- source: "flags.Parse|response.WriteError"
100100
linters:
101101
- errcheck
102-
- source: "^// \\+kubebuilder:"
102+
- source: "// \\+kubebuilder:"
103103
linters:
104104
- lll
105105
# Idiomatic to use init functions to register APIs with scheme

api/v1alpha1/addon_types.go

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,34 @@ type AddonStrategy string
4040

4141
// CNI required for providing CNI configuration.
4242
type CNI struct {
43-
// +optional
44-
Provider string `json:"provider,omitempty"`
45-
// +optional
46-
Strategy AddonStrategy `json:"strategy,omitempty"`
43+
// CNI provider to deploy.
44+
// +kubebuilder:validation:Enum=Calico;Cilium
45+
Provider string `json:"provider"`
46+
// Addon strategy used to deploy the CNI provider to the workload cluster.
47+
// +kubebuilder:validation:Enum=ClusterResourceSet;HelmAddon
48+
Strategy AddonStrategy `json:"strategy"`
4749
}
4850

4951
// NFD tells us to enable or disable the node feature discovery addon.
5052
type NFD struct {
51-
// +optional
52-
Strategy AddonStrategy `json:"strategy,omitempty"`
53+
// Addon strategy used to deploy Node Feature Discovery (NFD) to the workload cluster.
54+
// +kubebuilder:validation:Enum=ClusterResourceSet;HelmAddon
55+
Strategy AddonStrategy `json:"strategy"`
5356
}
5457

5558
// ClusterAutoscaler tells us to enable or disable the cluster-autoscaler addon.
5659
type ClusterAutoscaler struct {
57-
// +optional
58-
Strategy AddonStrategy `json:"strategy,omitempty"`
60+
// Addon strategy used to deploy cluster-autoscaler to the management cluster
61+
// targeting the workload cluster.
62+
// +kubebuilder:validation:Enum=ClusterResourceSet;HelmAddon
63+
Strategy AddonStrategy `json:"strategy"`
5964
}
6065

6166
type DefaultStorage struct {
62-
ProviderName string `json:"providerName"`
67+
// Name of the CSI Provider for the default storage class.
68+
// +kubebuilder:validation:Enum=aws-ebs;nutanix
69+
ProviderName string `json:"providerName"`
70+
// Name of storage class config in any of the provider objects.
6371
StorageClassConfigName string `json:"storageClassConfigName"`
6472
}
6573

@@ -71,29 +79,42 @@ type CSI struct {
7179
}
7280

7381
type CSIProvider struct {
82+
// Name of the CSI Provider.
83+
// +kubebuilder:validation:Enum=aws-ebs;nutanix
7484
Name string `json:"name"`
7585

7686
// +optional
7787
StorageClassConfig []StorageClassConfig `json:"storageClassConfig,omitempty"`
7888

89+
// Addon strategy used to deploy the CSI provider to the workload cluster.
90+
// +kubebuilder:validation:Enum=ClusterResourceSet;HelmAddon
7991
Strategy AddonStrategy `json:"strategy"`
8092

93+
// The reference to any secret used by the CSI Provider.
8194
// +optional
8295
Credentials *corev1.LocalObjectReference `json:"credentials,omitempty"`
8396
}
8497

8598
type StorageClassConfig struct {
99+
// Name of storage class config.
86100
Name string `json:"name"`
87101

102+
// Parameters passed into the storage class object.
88103
// +optional
89104
Parameters map[string]string `json:"parameters,omitempty"`
90105

106+
// +kubebuilder:validation:Enum=Delete;Retain;Recycle
107+
// +kubebuilder:default=Delete
91108
// +optional
92109
ReclaimPolicy corev1.PersistentVolumeReclaimPolicy `json:"reclaimPolicy,omitempty"`
93110

111+
// +kubebuilder:validation:Enum=Immediate;WaitForFirstConsumer
112+
// +kubebuilder:default=WaitForFirstConsumer
94113
// +optional
95114
VolumeBindingMode storagev1.VolumeBindingMode `json:"volumeBindingMode,omitempty"`
96115

116+
// If the storage class should allow volume expanding
117+
// +kubebuilder:default=false
97118
// +optional
98119
AllowExpansion bool `json:"allowExpansion,omitempty"`
99120
}

api/v1alpha1/aws_clusterconfig_types.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type AWSSpec struct {
1111
// AWS region to create cluster in.
1212
// +optional
1313
Region *Region `json:"region,omitempty"`
14+
// AWS network configuration.
1415
// +optional
1516
Network *AWSNetwork `json:"network,omitempty"`
1617
// +optional
@@ -23,26 +24,27 @@ type AWSNetwork struct {
2324
// +optional
2425
VPC *VPC `json:"vpc,omitempty"`
2526

27+
// AWS Subnet configuration.
2628
// +optional
2729
Subnets Subnets `json:"subnets,omitempty"`
2830
}
2931

3032
type VPC struct {
31-
// ID is the vpc-id of the VPC this provider should use to create resources.
32-
ID string `json:"id,omitempty"`
33+
// Existing VPC ID to use for the cluster.
34+
ID string `json:"id"`
3335
}
3436

3537
type Subnets []SubnetSpec
3638

3739
// SubnetSpec configures an AWS Subnet.
3840
type SubnetSpec struct {
39-
// ID defines a unique identifier to reference this resource.
41+
// Existing Subnet ID to use for the cluster.
4042
ID string `json:"id"`
4143
}
4244

4345
// AWSLoadBalancerSpec configures an AWS control-plane LoadBalancer.
4446
type AWSLoadBalancerSpec struct {
45-
// Scheme sets the scheme of the load balancer (defaults to internet-facing)
47+
// Scheme sets the scheme of the load balancer.
4648
// +kubebuilder:default=internet-facing
4749
// +kubebuilder:validation:Enum=internet-facing;internal
4850
// +optional

api/v1alpha1/clusterconfig_types.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func (s AWSClusterConfig) VariableSchema() clusterv1.VariableSchema { //nolint:g
8282

8383
// AWSClusterConfigSpec defines the desired state of ClusterConfig.
8484
type AWSClusterConfigSpec struct {
85+
// AWS cluster configuration.
8586
// +optional
8687
AWS *AWSSpec `json:"aws,omitempty"`
8788

@@ -160,20 +161,27 @@ func (s GenericClusterConfig) VariableSchema() clusterv1.VariableSchema { //noli
160161

161162
// GenericClusterConfigSpec defines the desired state of GenericClusterConfig.
162163
type GenericClusterConfigSpec struct {
164+
// Sets the Kubernetes image repository used for the KubeadmControlPlane.
165+
// +kubebuilder:validation:Pattern=`^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*$`
163166
// +optional
164-
KubernetesImageRepository *KubernetesImageRepository `json:"kubernetesImageRepository,omitempty"`
167+
KubernetesImageRepository *string `json:"kubernetesImageRepository,omitempty"`
165168

166169
// +optional
167170
Etcd *Etcd `json:"etcd,omitempty"`
168171

169172
// +optional
170173
Proxy *HTTPProxy `json:"proxy,omitempty"`
171174

175+
// Subject Alternative Names for the API Server signing cert.
176+
// For Docker are injected automatically.
177+
// For Nutanix are injected automatically.
178+
// +kubebuilder:validation:UniqueItems=true
179+
// +kubebuilder:validation:items:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`
172180
// +optional
173-
ExtraAPIServerCertSANs ExtraAPIServerCertSANs `json:"extraAPIServerCertSANs,omitempty"`
181+
ExtraAPIServerCertSANs []string `json:"extraAPIServerCertSANs,omitempty"`
174182

175183
// +optional
176-
ImageRegistries ImageRegistries `json:"imageRegistries,omitempty"`
184+
ImageRegistries []ImageRegistry `json:"imageRegistries,omitempty"`
177185

178186
// +optional
179187
GlobalImageRegistryMirror *GlobalImageRegistryMirror `json:"globalImageRegistryMirror,omitempty"`
@@ -182,22 +190,17 @@ type GenericClusterConfigSpec struct {
182190
Addons *Addons `json:"addons,omitempty"`
183191

184192
// +optional
185-
Users Users `json:"users,omitempty"`
186-
}
187-
188-
// KubernetesImageRepository required for overriding Kubernetes image repository.
189-
type KubernetesImageRepository string
190-
191-
func (v KubernetesImageRepository) String() string {
192-
return string(v)
193+
Users []User `json:"users,omitempty"`
193194
}
194195

195196
type Image struct {
196197
// Repository is used to override the image repository to pull from.
198+
// +kubebuilder:validation:Pattern=`^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*$`
197199
// +optional
198200
Repository string `json:"repository,omitempty"`
199201

200202
// Tag is used to override the default image tag.
203+
// +kubebuilder:validation:Pattern=`^[\w][\w.-]{0,127}$`
201204
// +optional
202205
Tag string `json:"tag,omitempty"`
203206
}
@@ -210,10 +213,10 @@ type Etcd struct {
210213

211214
// HTTPProxy required for providing proxy configuration.
212215
type HTTPProxy struct {
213-
// HTTP proxy.
216+
// HTTP proxy value.
214217
HTTP string `json:"http,omitempty"`
215218

216-
// HTTPS proxy.
219+
// HTTPS proxy value.
217220
HTTPS string `json:"https,omitempty"`
218221

219222
// AdditionalNo Proxy list that will be added to the automatically calculated
@@ -223,9 +226,6 @@ type HTTPProxy struct {
223226
AdditionalNo []string `json:"additionalNo"`
224227
}
225228

226-
// ExtraAPIServerCertSANs required for providing API server cert SANs.
227-
type ExtraAPIServerCertSANs []string
228-
229229
type RegistryCredentials struct {
230230
// A reference to the Secret containing the registry credentials and optional CA certificate
231231
// using the keys `username`, `password` and `ca.crt`.
@@ -236,7 +236,9 @@ type RegistryCredentials struct {
236236

237237
// GlobalImageRegistryMirror sets default mirror configuration for all the image registries.
238238
type GlobalImageRegistryMirror struct {
239-
// Registry URL.
239+
// Registry mirror URL.
240+
// +kubebuilder:validation:Format=`uri`
241+
// +kubebuilder:validation:Pattern=`^https?://`
240242
URL string `json:"url"`
241243

242244
// Credentials and CA certificate for the image registry mirror
@@ -246,17 +248,15 @@ type GlobalImageRegistryMirror struct {
246248

247249
type ImageRegistry struct {
248250
// Registry URL.
251+
// +kubebuilder:validation:Format=`uri`
252+
// +kubebuilder:validation:Pattern=`^https?://`
249253
URL string `json:"url"`
250254

251255
// Credentials and CA certificate for the image registry
252256
// +optional
253257
Credentials *RegistryCredentials `json:"credentials,omitempty"`
254258
}
255259

256-
type ImageRegistries []ImageRegistry
257-
258-
type Users []User
259-
260260
// User defines the input for a generated user in cloud-init.
261261
type User struct {
262262
// Name specifies the user name.

api/v1alpha1/common_types.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33

44
package v1alpha1
55

6-
import (
7-
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
8-
)
9-
106
const (
117
APIServerPort = 6443
128
)
@@ -32,4 +28,13 @@ type ObjectMeta struct {
3228
Annotations map[string]string `json:"annotations,omitempty"`
3329
}
3430

35-
type ControlPlaneEndpointSpec clusterv1.APIEndpoint
31+
type ControlPlaneEndpointSpec struct {
32+
// The hostname on which the API server is serving.
33+
// +kubebuilder:validation:MinLength=1
34+
Host string `json:"host"`
35+
36+
// The port on which the API server is serving.
37+
// +kubebuilder:validation:Minimum=1
38+
// +kubebuilder:validation:Maximum=65535
39+
Port int32 `json:"port"`
40+
}

0 commit comments

Comments
 (0)