Skip to content

Commit d2d6802

Browse files
committed
Fix golint issues in test/e2e/lifecycle/
1 parent cf16e49 commit d2d6802

File tree

5 files changed

+39
-27
lines changed

5 files changed

+39
-27
lines changed

hack/.golint_failures

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,6 @@ staging/src/k8s.io/sample-apiserver/pkg/apis/wardle/v1alpha1
532532
staging/src/k8s.io/sample-apiserver/pkg/registry/wardle/fischer
533533
staging/src/k8s.io/sample-apiserver/pkg/registry/wardle/flunder
534534
test/e2e/common
535-
test/e2e/lifecycle/bootstrap
536535
test/e2e/storage/vsphere
537536
test/e2e_node/remote
538537
test/e2e_node/runner/remote

test/e2e/lifecycle/bootstrap/bootstrap_signer.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ import (
2727
)
2828

2929
const (
30-
TokenIDBytes = 3
30+
// TokenIDBytes is the length of the byte array to generate tokenID.
31+
TokenIDBytes = 3
32+
33+
// TokenSecretBytes is the length of the byte array to generate tokenSecret.
3134
TokenSecretBytes = 8
3235
)
3336

@@ -50,34 +53,34 @@ var _ = lifecycle.SIGDescribe("[Feature:BootstrapTokens]", func() {
5053

5154
ginkgo.It("should sign the new added bootstrap tokens", func() {
5255
ginkgo.By("create a new bootstrap token secret")
53-
tokenId, err := GenerateTokenId()
56+
tokenID, err := GenerateTokenID()
5457
framework.ExpectNoError(err)
55-
secret := newTokenSecret(tokenId, "tokenSecret")
58+
secret := newTokenSecret(tokenID, "tokenSecret")
5659
_, err = c.CoreV1().Secrets(metav1.NamespaceSystem).Create(secret)
57-
secretNeedClean = bootstrapapi.BootstrapTokenSecretPrefix + tokenId
60+
secretNeedClean = bootstrapapi.BootstrapTokenSecretPrefix + tokenID
5861

5962
framework.ExpectNoError(err)
6063

6164
ginkgo.By("wait for the bootstrap token secret be signed")
62-
err = WaitforSignedClusterInfoByBootStrapToken(c, tokenId)
65+
err = WaitforSignedClusterInfoByBootStrapToken(c, tokenID)
6366
framework.ExpectNoError(err)
6467
})
6568

6669
ginkgo.It("should resign the bootstrap tokens when the clusterInfo ConfigMap updated [Serial][Disruptive]", func() {
6770
ginkgo.By("create a new bootstrap token secret")
68-
tokenId, err := GenerateTokenId()
71+
tokenID, err := GenerateTokenID()
6972
framework.ExpectNoError(err)
70-
secret := newTokenSecret(tokenId, "tokenSecret")
73+
secret := newTokenSecret(tokenID, "tokenSecret")
7174
_, err = c.CoreV1().Secrets(metav1.NamespaceSystem).Create(secret)
7275
framework.ExpectNoError(err)
73-
secretNeedClean = bootstrapapi.BootstrapTokenSecretPrefix + tokenId
76+
secretNeedClean = bootstrapapi.BootstrapTokenSecretPrefix + tokenID
7477

7578
ginkgo.By("wait for the bootstrap token secret be signed")
76-
err = WaitforSignedClusterInfoByBootStrapToken(c, tokenId)
79+
err = WaitforSignedClusterInfoByBootStrapToken(c, tokenID)
7780

7881
cfgMap, err := f.ClientSet.CoreV1().ConfigMaps(metav1.NamespacePublic).Get(bootstrapapi.ConfigMapClusterInfo, metav1.GetOptions{})
7982
framework.ExpectNoError(err)
80-
signedToken, ok := cfgMap.Data[bootstrapapi.JWSSignatureKeyPrefix+tokenId]
83+
signedToken, ok := cfgMap.Data[bootstrapapi.JWSSignatureKeyPrefix+tokenID]
8184
framework.ExpectEqual(ok, true)
8285

8386
ginkgo.By("update the cluster-info ConfigMap")
@@ -97,28 +100,28 @@ var _ = lifecycle.SIGDescribe("[Feature:BootstrapTokens]", func() {
97100
}()
98101

99102
ginkgo.By("wait for signed bootstrap token updated")
100-
err = WaitForSignedClusterInfoGetUpdatedByBootstrapToken(c, tokenId, signedToken)
103+
err = WaitForSignedClusterInfoGetUpdatedByBootstrapToken(c, tokenID, signedToken)
101104
framework.ExpectNoError(err)
102105
})
103106

104107
ginkgo.It("should delete the signed bootstrap tokens from clusterInfo ConfigMap when bootstrap token is deleted", func() {
105108
ginkgo.By("create a new bootstrap token secret")
106-
tokenId, err := GenerateTokenId()
109+
tokenID, err := GenerateTokenID()
107110
framework.ExpectNoError(err)
108-
secret := newTokenSecret(tokenId, "tokenSecret")
111+
secret := newTokenSecret(tokenID, "tokenSecret")
109112
_, err = c.CoreV1().Secrets(metav1.NamespaceSystem).Create(secret)
110113
framework.ExpectNoError(err)
111114

112115
ginkgo.By("wait for the bootstrap secret be signed")
113-
err = WaitforSignedClusterInfoByBootStrapToken(c, tokenId)
116+
err = WaitforSignedClusterInfoByBootStrapToken(c, tokenID)
114117
framework.ExpectNoError(err)
115118

116119
ginkgo.By("delete the bootstrap token secret")
117-
err = c.CoreV1().Secrets(metav1.NamespaceSystem).Delete(bootstrapapi.BootstrapTokenSecretPrefix+tokenId, &metav1.DeleteOptions{})
120+
err = c.CoreV1().Secrets(metav1.NamespaceSystem).Delete(bootstrapapi.BootstrapTokenSecretPrefix+tokenID, &metav1.DeleteOptions{})
118121
framework.ExpectNoError(err)
119122

120123
ginkgo.By("wait for the bootstrap token removed from cluster-info ConfigMap")
121-
err = WaitForSignedClusterInfoByBootstrapTokenToDisappear(c, tokenId)
124+
err = WaitForSignedClusterInfoByBootstrapTokenToDisappear(c, tokenID)
122125
framework.ExpectNoError(err)
123126
})
124127
})

test/e2e/lifecycle/bootstrap/bootstrap_token_cleaner.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,36 +49,36 @@ var _ = lifecycle.SIGDescribe("[Feature:BootstrapTokens]", func() {
4949
})
5050
ginkgo.It("should delete the token secret when the secret expired", func() {
5151
ginkgo.By("create a new expired bootstrap token secret")
52-
tokenId, err := GenerateTokenId()
52+
tokenID, err := GenerateTokenID()
5353
framework.ExpectNoError(err)
5454
tokenSecret, err := GenerateTokenSecret()
5555
framework.ExpectNoError(err)
5656

57-
secret := newTokenSecret(tokenId, tokenSecret)
57+
secret := newTokenSecret(tokenID, tokenSecret)
5858
addSecretExpiration(secret, TimeStringFromNow(-time.Hour))
5959
_, err = c.CoreV1().Secrets(metav1.NamespaceSystem).Create(secret)
6060

6161
framework.ExpectNoError(err)
6262

6363
ginkgo.By("wait for the bootstrap token secret be deleted")
64-
err = WaitForBootstrapTokenSecretToDisappear(c, tokenId)
64+
err = WaitForBootstrapTokenSecretToDisappear(c, tokenID)
6565
framework.ExpectNoError(err)
6666
})
6767

6868
ginkgo.It("should not delete the token secret when the secret is not expired", func() {
6969
ginkgo.By("create a new expired bootstrap token secret")
70-
tokenId, err := GenerateTokenId()
70+
tokenID, err := GenerateTokenID()
7171
framework.ExpectNoError(err)
7272
tokenSecret, err := GenerateTokenSecret()
7373
framework.ExpectNoError(err)
74-
secret := newTokenSecret(tokenId, tokenSecret)
74+
secret := newTokenSecret(tokenID, tokenSecret)
7575
addSecretExpiration(secret, TimeStringFromNow(time.Hour))
7676
_, err = c.CoreV1().Secrets(metav1.NamespaceSystem).Create(secret)
77-
secretNeedClean = bootstrapapi.BootstrapTokenSecretPrefix + tokenId
77+
secretNeedClean = bootstrapapi.BootstrapTokenSecretPrefix + tokenID
7878
framework.ExpectNoError(err)
7979

8080
ginkgo.By("wait for the bootstrap token secret not be deleted")
81-
err = WaitForBootstrapTokenSecretNotDisappear(c, tokenId, 20*time.Second)
81+
err = WaitForBootstrapTokenSecretNotDisappear(c, tokenID, 20*time.Second)
8282
framework.ExpectNoError(err)
8383
})
8484
})

test/e2e/lifecycle/bootstrap/util.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"errors"
2323
"time"
2424

25-
"k8s.io/api/core/v1"
25+
v1 "k8s.io/api/core/v1"
2626
apierrs "k8s.io/apimachinery/pkg/api/errors"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
"k8s.io/apimachinery/pkg/util/wait"
@@ -46,13 +46,16 @@ func newTokenSecret(tokenID, tokenSecret string) *v1.Secret {
4646
}
4747
}
4848

49-
func GenerateTokenId() (string, error) {
49+
// GenerateTokenID generates tokenID.
50+
func GenerateTokenID() (string, error) {
5051
tokenID, err := randBytes(TokenIDBytes)
5152
if err != nil {
5253
return "", err
5354
}
5455
return tokenID, nil
5556
}
57+
58+
// GenerateTokenSecret generates tokenSecret.
5659
func GenerateTokenSecret() (string, error) {
5760
tokenSecret, err := randBytes(TokenSecretBytes)
5861
if err != nil {
@@ -74,10 +77,13 @@ func addSecretExpiration(s *v1.Secret, expiration string) {
7477
s.Data[bootstrapapi.BootstrapTokenExpirationKey] = []byte(expiration)
7578
}
7679

80+
// TimeStringFromNow returns the time as a string from now.
81+
// e.g: 2019-12-03T14:30:40+08:00.
7782
func TimeStringFromNow(delta time.Duration) string {
7883
return time.Now().Add(delta).Format(time.RFC3339)
7984
}
8085

86+
// WaitforSignedClusterInfoByBootStrapToken waits for signed cluster info by bootstrap token.
8187
func WaitforSignedClusterInfoByBootStrapToken(c clientset.Interface, tokenID string) error {
8288

8389
return wait.Poll(framework.Poll, 2*time.Minute, func() (bool, error) {
@@ -94,6 +100,7 @@ func WaitforSignedClusterInfoByBootStrapToken(c clientset.Interface, tokenID str
94100
})
95101
}
96102

103+
// WaitForSignedClusterInfoGetUpdatedByBootstrapToken waits for signed cluster info to be updated by bootstrap token.
97104
func WaitForSignedClusterInfoGetUpdatedByBootstrapToken(c clientset.Interface, tokenID string, signedToken string) error {
98105

99106
return wait.Poll(framework.Poll, 2*time.Minute, func() (bool, error) {
@@ -110,6 +117,7 @@ func WaitForSignedClusterInfoGetUpdatedByBootstrapToken(c clientset.Interface, t
110117
})
111118
}
112119

120+
// WaitForSignedClusterInfoByBootstrapTokenToDisappear waits for signed cluster info to be disappeared by bootstrap token.
113121
func WaitForSignedClusterInfoByBootstrapTokenToDisappear(c clientset.Interface, tokenID string) error {
114122

115123
return wait.Poll(framework.Poll, 2*time.Minute, func() (bool, error) {
@@ -126,6 +134,7 @@ func WaitForSignedClusterInfoByBootstrapTokenToDisappear(c clientset.Interface,
126134
})
127135
}
128136

137+
// WaitForBootstrapTokenSecretToDisappear waits for bootstrap token secret to be disappeared.
129138
func WaitForBootstrapTokenSecretToDisappear(c clientset.Interface, tokenID string) error {
130139

131140
return wait.Poll(framework.Poll, 1*time.Minute, func() (bool, error) {
@@ -137,6 +146,7 @@ func WaitForBootstrapTokenSecretToDisappear(c clientset.Interface, tokenID strin
137146
})
138147
}
139148

149+
// WaitForBootstrapTokenSecretNotDisappear waits for bootstrap token secret not to be disappeared and takes time for the specified timeout as success path.
140150
func WaitForBootstrapTokenSecretNotDisappear(c clientset.Interface, tokenID string, t time.Duration) error {
141151
err := wait.Poll(framework.Poll, t, func() (bool, error) {
142152
secret, err := c.CoreV1().Secrets(metav1.NamespaceSystem).Get(bootstrapapi.BootstrapTokenSecretPrefix+tokenID, metav1.GetOptions{})

test/integration/auth/bootstraptoken_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (b bootstrapSecrets) Get(name string) (*corev1.Secret, error) {
4747

4848
// TestBootstrapTokenAuth tests the bootstrap token auth provider
4949
func TestBootstrapTokenAuth(t *testing.T) {
50-
tokenID, err := bootstraputil.GenerateTokenId()
50+
tokenID, err := bootstraputil.GenerateTokenID()
5151
if err != nil {
5252
t.Fatalf("unexpected error: %v", err)
5353
}

0 commit comments

Comments
 (0)