Skip to content

Commit bbd1f33

Browse files
committed
Enable optionalorrequired linter
1 parent 04a4f62 commit bbd1f33

File tree

149 files changed

+1748
-437
lines changed

Some content is hidden

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

149 files changed

+1748
-437
lines changed

.golangci-kal.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ linters:
2424
#- "maxlength" # Ensure all strings and arrays have maximum lengths/maximum items.
2525
#- "nobools" # Bools do not evolve over time, should use enums instead.
2626
#- "nofloats" # Ensure floats are not used.
27-
#- "optionalorrequired" # Every field should be marked as `+optional` or `+required`.
27+
- "optionalorrequired" # Every field should be marked as `+optional` or `+required`.
2828
# - "requiredfields" # Required fields should not be pointers, and should not have `omitempty`.
2929
- "statussubresource" # All root objects that have a `status` field should have a status subresource.
3030

api/v1beta1/awscluster_types.go

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121

2222
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
23+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2324
)
2425

2526
const (
@@ -34,9 +35,11 @@ const (
3435
// AWSClusterSpec defines the desired state of an EC2-based Kubernetes cluster.
3536
type AWSClusterSpec struct {
3637
// NetworkSpec encapsulates all things related to AWS network.
38+
// +optional
3739
NetworkSpec NetworkSpec `json:"network,omitempty"`
3840

3941
// The AWS Region the cluster lives in.
42+
// +optional
4043
Region string `json:"region,omitempty"`
4144

4245
// SSHKeyName is the name of the ssh key to attach to the bastion host. Valid values are empty string (do not use SSH keys), a valid SSH key name, or omitted (use the default SSH key name)
@@ -45,7 +48,7 @@ type AWSClusterSpec struct {
4548

4649
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
4750
// +optional
48-
ControlPlaneEndpoint clusterv1beta1.APIEndpoint `json:"controlPlaneEndpoint"`
51+
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
4952

5053
// AdditionalTags is an optional set of tags to add to AWS resources managed by the AWS provider, in addition to the
5154
// ones added by default.
@@ -81,6 +84,7 @@ type AWSClusterSpec struct {
8184
// up machine images when a machine does not specify an AMI. When set, this
8285
// will be used for all cluster machines unless a machine specifies a
8386
// different ImageLookupBaseOS.
87+
// +optional
8488
ImageLookupBaseOS string `json:"imageLookupBaseOS,omitempty"`
8589

8690
// Bastion contains options to configure the bastion host.
@@ -91,6 +95,7 @@ type AWSClusterSpec struct {
9195

9296
// IdentityRef is a reference to an identity to be used when reconciling the managed control plane.
9397
// If no identity is specified, the default identity for this controller will be used.
98+
// +optional
9499
IdentityRef *AWSIdentityReference `json:"identityRef,omitempty"`
95100

96101
// S3Bucket contains options to configure a supporting S3 bucket for this
@@ -119,10 +124,12 @@ var (
119124
type AWSIdentityReference struct {
120125
// Name of the identity.
121126
// +kubebuilder:validation:MinLength=1
127+
// +required
122128
Name string `json:"name"`
123129

124130
// Kind of the identity.
125131
// +kubebuilder:validation:Enum=AWSClusterControllerIdentity;AWSClusterRoleIdentity;AWSClusterStaticIdentity
132+
// +required
126133
Kind AWSIdentityKind `json:"kind"`
127134
}
128135

@@ -146,6 +153,7 @@ type Bastion struct {
146153
// InstanceType will use the specified instance type for the bastion. If not specified,
147154
// Cluster API Provider AWS will use t3.micro for all regions except us-east-1, where t2.micro
148155
// will be the default.
156+
// +optional
149157
InstanceType string `json:"instanceType,omitempty"`
150158

151159
// AMI will use the specified AMI to boot the bastion. If not specified,
@@ -200,27 +208,35 @@ type AWSLoadBalancerSpec struct {
200208
// AWSClusterStatus defines the observed state of AWSCluster.
201209
type AWSClusterStatus struct {
202210
// +kubebuilder:default=false
203-
Ready bool `json:"ready"`
204-
Network NetworkStatus `json:"networkStatus,omitempty"`
211+
// +required
212+
Ready bool `json:"ready"`
213+
// +optional
214+
Network NetworkStatus `json:"networkStatus,omitempty"`
215+
// +optional
205216
FailureDomains clusterv1beta1.FailureDomains `json:"failureDomains,omitempty"`
206-
Bastion *Instance `json:"bastion,omitempty"`
207-
Conditions clusterv1beta1.Conditions `json:"conditions,omitempty"`
217+
// +optional
218+
Bastion *Instance `json:"bastion,omitempty"`
219+
// +optional
220+
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
208221
}
209222

210223
// S3Bucket defines a supporting S3 bucket for the cluster, currently can be optionally used for Ignition.
211224
type S3Bucket struct {
212225
// ControlPlaneIAMInstanceProfile is a name of the IAMInstanceProfile, which will be allowed
213226
// to read control-plane node bootstrap data from S3 Bucket.
227+
// +required
214228
ControlPlaneIAMInstanceProfile string `json:"controlPlaneIAMInstanceProfile"`
215229

216230
// NodesIAMInstanceProfiles is a list of IAM instance profiles, which will be allowed to read
217231
// worker nodes bootstrap data from S3 Bucket.
232+
// +required
218233
NodesIAMInstanceProfiles []string `json:"nodesIAMInstanceProfiles"`
219234

220235
// Name defines name of S3 Bucket to be created.
221236
// +kubebuilder:validation:MinLength:=3
222237
// +kubebuilder:validation:MaxLength:=63
223238
// +kubebuilder:validation:Pattern=`^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$`
239+
// +required
224240
Name string `json:"name"`
225241
}
226242

@@ -236,10 +252,13 @@ type S3Bucket struct {
236252

237253
// AWSCluster is the schema for Amazon EC2 based Kubernetes Cluster API.
238254
type AWSCluster struct {
239-
metav1.TypeMeta `json:",inline"`
255+
metav1.TypeMeta `json:",inline"`
256+
// +optional
240257
metav1.ObjectMeta `json:"metadata,omitempty"`
241258

242-
Spec AWSClusterSpec `json:"spec,omitempty"`
259+
// +optional
260+
Spec AWSClusterSpec `json:"spec,omitempty"`
261+
// +optional
243262
Status AWSClusterStatus `json:"status,omitempty"`
244263
}
245264

@@ -249,8 +268,10 @@ type AWSCluster struct {
249268
// AWSClusterList contains a list of AWSCluster.
250269
type AWSClusterList struct {
251270
metav1.TypeMeta `json:",inline"`
271+
// +optional
252272
metav1.ListMeta `json:"metadata,omitempty"`
253-
Items []AWSCluster `json:"items"`
273+
// +required
274+
Items []AWSCluster `json:"items"`
254275
}
255276

256277
// GetConditions returns the observations of the operational state of the AWSCluster resource.

api/v1beta1/awsclustertemplate_types.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ package v1beta1
1919
import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121

22-
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
22+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
2323
)
2424

2525
// AWSClusterTemplateSpec defines the desired state of AWSClusterTemplate.
2626
type AWSClusterTemplateSpec struct {
27+
// +required
2728
Template AWSClusterTemplateResource `json:"template"`
2829
}
2930

@@ -34,9 +35,11 @@ type AWSClusterTemplateSpec struct {
3435

3536
// AWSClusterTemplate is the schema for Amazon EC2 based Kubernetes Cluster Templates.
3637
type AWSClusterTemplate struct {
37-
metav1.TypeMeta `json:",inline"`
38+
metav1.TypeMeta `json:",inline"`
39+
// +optional
3840
metav1.ObjectMeta `json:"metadata,omitempty"`
3941

42+
// +optional
4043
Spec AWSClusterTemplateSpec `json:"spec,omitempty"`
4144
}
4245

@@ -45,8 +48,10 @@ type AWSClusterTemplate struct {
4548
// AWSClusterTemplateList contains a list of AWSClusterTemplate.
4649
type AWSClusterTemplateList struct {
4750
metav1.TypeMeta `json:",inline"`
51+
// +optional
4852
metav1.ListMeta `json:"metadata,omitempty"`
49-
Items []AWSClusterTemplate `json:"items"`
53+
// +required
54+
Items []AWSClusterTemplate `json:"items"`
5055
}
5156

5257
func init() {
@@ -58,6 +63,7 @@ type AWSClusterTemplateResource struct {
5863
// Standard object's metadata.
5964
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
6065
// +optional
61-
ObjectMeta clusterv1beta1.ObjectMeta `json:"metadata,omitempty"`
62-
Spec AWSClusterSpec `json:"spec"`
66+
ObjectMeta clusterv1.ObjectMeta `json:"metadata,omitempty"`
67+
// +required
68+
Spec AWSClusterSpec `json:"spec"`
6369
}

api/v1beta1/awsidentity_types.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,24 @@ type AllowedNamespaces struct {
5353
// AWSRoleSpec defines the specifications for all identities based around AWS roles.
5454
type AWSRoleSpec struct {
5555
// The Amazon Resource Name (ARN) of the role to assume.
56+
// +required
5657
RoleArn string `json:"roleARN"`
5758
// An identifier for the assumed role session
59+
// +optional
5860
SessionName string `json:"sessionName,omitempty"`
5961
// The duration, in seconds, of the role session before it is renewed.
6062
// +kubebuilder:validation:Minimum:=900
6163
// +kubebuilder:validation:Maximum:=43200
64+
// +optional
6265
DurationSeconds int32 `json:"durationSeconds,omitempty"`
6366
// An IAM policy as a JSON-encoded string that you want to use as an inline session policy.
67+
// +optional
6468
InlinePolicy string `json:"inlinePolicy,omitempty"`
6569

6670
// The Amazon Resource Names (ARNs) of the IAM managed policies that you want
6771
// to use as managed session policies.
6872
// The policies must exist in the same account as the role.
73+
// +optional
6974
PolicyARNs []string `json:"policyARNs,omitempty"`
7075
}
7176

@@ -77,9 +82,11 @@ type AWSRoleSpec struct {
7782
// It represents a reference to an AWS access key ID and secret access key, stored in a secret.
7883
type AWSClusterStaticIdentity struct {
7984
metav1.TypeMeta `json:",inline"`
85+
// +optional
8086
metav1.ObjectMeta `json:"metadata,omitempty"`
8187

8288
// Spec for this AWSClusterStaticIdentity
89+
// +optional
8390
Spec AWSClusterStaticIdentitySpec `json:"spec,omitempty"`
8491
}
8592

@@ -89,7 +96,9 @@ type AWSClusterStaticIdentity struct {
8996
// AWSClusterStaticIdentityList contains a list of AWSClusterStaticIdentity.
9097
type AWSClusterStaticIdentityList struct {
9198
metav1.TypeMeta `json:",inline"`
99+
// +optional
92100
metav1.ListMeta `json:"metadata,omitempty"`
101+
// +required
93102
Items []AWSClusterStaticIdentity `json:"items"`
94103
}
95104

@@ -101,6 +110,7 @@ type AWSClusterStaticIdentitySpec struct {
101110
// AccessKeyID: AKIAIOSFODNN7EXAMPLE
102111
// SecretAccessKey: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
103112
// SessionToken: Optional
113+
// +required
104114
SecretRef string `json:"secretRef"`
105115
}
106116

@@ -112,9 +122,11 @@ type AWSClusterStaticIdentitySpec struct {
112122
// It is used to assume a role using the provided sourceRef.
113123
type AWSClusterRoleIdentity struct {
114124
metav1.TypeMeta `json:",inline"`
125+
// +optional
115126
metav1.ObjectMeta `json:"metadata,omitempty"`
116127

117128
// Spec for this AWSClusterRoleIdentity.
129+
// +optional
118130
Spec AWSClusterRoleIdentitySpec `json:"spec,omitempty"`
119131
}
120132

@@ -124,7 +136,9 @@ type AWSClusterRoleIdentity struct {
124136
// AWSClusterRoleIdentityList contains a list of AWSClusterRoleIdentity.
125137
type AWSClusterRoleIdentityList struct {
126138
metav1.TypeMeta `json:",inline"`
139+
// +optional
127140
metav1.ListMeta `json:"metadata,omitempty"`
141+
// +required
128142
Items []AWSClusterRoleIdentity `json:"items"`
129143
}
130144

@@ -146,6 +160,7 @@ type AWSClusterRoleIdentitySpec struct {
146160

147161
// SourceIdentityRef is a reference to another identity which will be chained to do
148162
// role assumption. All identity types are accepted.
163+
// +optional
149164
SourceIdentityRef *AWSIdentityReference `json:"sourceIdentityRef,omitempty"`
150165
}
151166

@@ -157,9 +172,11 @@ type AWSClusterRoleIdentitySpec struct {
157172
// It is used to grant access to use Cluster API Provider AWS Controller credentials.
158173
type AWSClusterControllerIdentity struct {
159174
metav1.TypeMeta `json:",inline"`
175+
// +optional
160176
metav1.ObjectMeta `json:"metadata,omitempty"`
161177

162178
// Spec for this AWSClusterControllerIdentity.
179+
// +optional
163180
Spec AWSClusterControllerIdentitySpec `json:"spec,omitempty"`
164181
}
165182

@@ -169,7 +186,9 @@ type AWSClusterControllerIdentity struct {
169186
// AWSClusterControllerIdentityList contains a list of AWSClusterControllerIdentity.
170187
type AWSClusterControllerIdentityList struct {
171188
metav1.TypeMeta `json:",inline"`
189+
// +optional
172190
metav1.ListMeta `json:"metadata,omitempty"`
191+
// +required
173192
Items []AWSClusterControllerIdentity `json:"items"`
174193
}
175194

0 commit comments

Comments
 (0)