Skip to content

Commit 21c7313

Browse files
authored
Merge pull request #12565 from sbueringer/pr-fix-token
⚠️ Change BootstrapToken.Token from *BootstrapTokenString to BootstrapTokenString
2 parents 37e5033 + 8346633 commit 21c7313

File tree

16 files changed

+95
-22
lines changed

16 files changed

+95
-22
lines changed

.golangci-kal.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,6 @@ linters:
142142
text: "nomaps: FeatureGates should not use a map type, use a list type with a unique name/identifier instead"
143143
linters:
144144
- kubeapilinter
145-
# Note: Maybe this has to stay a pointer for marshalling reasons.
146-
# TODO: we should eventually remove the pointer: https://github.com/kubernetes-sigs/cluster-api/issues/10852
147-
- path: "api/bootstrap/kubeadm/v1beta2/kubeadm_types.go"
148-
text: "field Token is marked as required, should not be a pointer"
149-
linters:
150-
- kubeapilinter
151145

152146
## Excludes for optionalfields
153147
# Empty Bootstrap object is blocked via validating webhooks. This cannot be detected by KAL (same if we move the validation to CEL).

api/bootstrap/kubeadm/v1beta1/conversion.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,12 @@ func Convert_v1beta2_BootstrapToken_To_v1beta1_BootstrapToken(in *bootstrapv1.Bo
435435
if !reflect.DeepEqual(in.Expires, metav1.Time{}) {
436436
out.Expires = ptr.To(in.Expires)
437437
}
438+
if !reflect.DeepEqual(in.Token, bootstrapv1.BootstrapTokenString{}) {
439+
out.Token = &BootstrapTokenString{}
440+
if err := autoConvert_v1beta2_BootstrapTokenString_To_v1beta1_BootstrapTokenString(&in.Token, out.Token, s); err != nil {
441+
return err
442+
}
443+
}
438444
return nil
439445
}
440446

@@ -569,6 +575,11 @@ func Convert_v1beta1_BootstrapToken_To_v1beta2_BootstrapToken(in *BootstrapToken
569575
if in.Expires != nil && !reflect.DeepEqual(in.Expires, &metav1.Time{}) {
570576
out.Expires = *in.Expires
571577
}
578+
if in.Token != nil {
579+
if err := autoConvert_v1beta1_BootstrapTokenString_To_v1beta2_BootstrapTokenString(in.Token, &out.Token, s); err != nil {
580+
return err
581+
}
582+
}
572583
return nil
573584
}
574585

api/bootstrap/kubeadm/v1beta1/zz_generated.conversion.go

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

api/bootstrap/kubeadm/v1beta2/kubeadm_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ type BootstrapToken struct {
424424
// token is used for establishing bidirectional trust between nodes and control-planes.
425425
// Used for joining nodes in the cluster.
426426
// +required
427-
Token *BootstrapTokenString `json:"token"`
427+
Token BootstrapTokenString `json:"token,omitempty,omitzero"`
428428

429429
// description sets a human-friendly message why this token exists and what it's used
430430
// for, so other administrators can know its purpose.

api/bootstrap/kubeadm/v1beta2/zz_generated.deepcopy.go

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bootstrap/kubeadm/types/upstreamv1beta3/conversion.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ func Convert_upstreamv1beta3_BootstrapToken_To_v1beta2_BootstrapToken(in *Bootst
213213
if in.Expires != nil && !reflect.DeepEqual(in.Expires, &metav1.Time{}) {
214214
out.Expires = *in.Expires
215215
}
216+
if in.Token != nil {
217+
if err := autoConvert_upstreamv1beta3_BootstrapTokenString_To_v1beta2_BootstrapTokenString(in.Token, &out.Token, s); err != nil {
218+
return err
219+
}
220+
}
216221
return nil
217222
}
218223

@@ -306,6 +311,12 @@ func Convert_v1beta2_BootstrapToken_To_upstreamv1beta3_BootstrapToken(in *bootst
306311
if !reflect.DeepEqual(in.Expires, metav1.Time{}) {
307312
out.Expires = ptr.To(in.Expires)
308313
}
314+
if !reflect.DeepEqual(in.Token, bootstrapv1.BootstrapTokenString{}) {
315+
out.Token = &BootstrapTokenString{}
316+
if err := autoConvert_v1beta2_BootstrapTokenString_To_upstreamv1beta3_BootstrapTokenString(&in.Token, out.Token, s); err != nil {
317+
return err
318+
}
319+
}
309320
return nil
310321
}
311322

bootstrap/kubeadm/types/upstreamv1beta3/conversion_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ import (
3636
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
3737
)
3838

39+
const (
40+
fakeID = "abcdef"
41+
fakeSecret = "abcdef0123456789"
42+
)
43+
3944
// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out.
4045

4146
func TestFuzzyConversion(t *testing.T) {
@@ -99,6 +104,7 @@ func clusterConfigurationFuzzFuncs(_ runtimeserializer.CodecFactory) []interface
99104
func initConfigurationFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
100105
return []interface{}{
101106
spokeBootstrapToken,
107+
spokeBootstrapTokenString,
102108
}
103109
}
104110

@@ -190,6 +196,11 @@ func spokeBootstrapToken(in *BootstrapToken, c randfill.Continue) {
190196
}
191197
}
192198

199+
func spokeBootstrapTokenString(in *BootstrapTokenString, _ randfill.Continue) {
200+
in.ID = fakeID
201+
in.Secret = fakeSecret
202+
}
203+
193204
func hubAPIServerFuzzer(obj *bootstrapv1.APIServer, c randfill.Continue) {
194205
c.FillNoCustom(obj)
195206

bootstrap/kubeadm/types/upstreamv1beta3/zz_generated.conversion.go

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

bootstrap/kubeadm/types/upstreamv1beta4/conversion.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ func Convert_upstreamv1beta4_BootstrapToken_To_v1beta2_BootstrapToken(in *Bootst
172172
if in.Expires != nil && !reflect.DeepEqual(in.Expires, &metav1.Time{}) {
173173
out.Expires = *in.Expires
174174
}
175+
if in.Token != nil {
176+
if err := autoConvert_upstreamv1beta4_BootstrapTokenString_To_v1beta2_BootstrapTokenString(in.Token, &out.Token, s); err != nil {
177+
return err
178+
}
179+
}
175180
return nil
176181
}
177182

@@ -423,6 +428,12 @@ func Convert_v1beta2_BootstrapToken_To_upstreamv1beta4_BootstrapToken(in *bootst
423428
if !reflect.DeepEqual(in.Expires, metav1.Time{}) {
424429
out.Expires = ptr.To(in.Expires)
425430
}
431+
if !reflect.DeepEqual(in.Token, bootstrapv1.BootstrapTokenString{}) {
432+
out.Token = &BootstrapTokenString{}
433+
if err := autoConvert_v1beta2_BootstrapTokenString_To_upstreamv1beta4_BootstrapTokenString(&in.Token, out.Token, s); err != nil {
434+
return err
435+
}
436+
}
426437
return nil
427438
}
428439

bootstrap/kubeadm/types/upstreamv1beta4/conversion_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ import (
3636
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
3737
)
3838

39+
const (
40+
fakeID = "abcdef"
41+
fakeSecret = "abcdef0123456789"
42+
)
43+
3944
// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out.
4045

4146
func TestFuzzyConversion(t *testing.T) {
@@ -90,6 +95,7 @@ func fuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
9095
func initConfigurationFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
9196
return []interface{}{
9297
spokeBootstrapToken,
98+
spokeBootstrapTokenString,
9399
}
94100
}
95101

@@ -203,6 +209,11 @@ func spokeBootstrapToken(in *BootstrapToken, c randfill.Continue) {
203209
}
204210
}
205211

212+
func spokeBootstrapTokenString(in *BootstrapTokenString, _ randfill.Continue) {
213+
in.ID = fakeID
214+
in.Secret = fakeSecret
215+
}
216+
206217
func hubClusterConfigurationFuzzer(in *bootstrapv1.ClusterConfiguration, c randfill.Continue) {
207218
c.FillNoCustom(in)
208219

0 commit comments

Comments
 (0)