mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 09:52:49 +00:00
Fix golint issues in test/e2e/lifecycle/
This commit is contained in:
parent
cf16e4988f
commit
d2d68026fc
@ -532,7 +532,6 @@ staging/src/k8s.io/sample-apiserver/pkg/apis/wardle/v1alpha1
|
||||
staging/src/k8s.io/sample-apiserver/pkg/registry/wardle/fischer
|
||||
staging/src/k8s.io/sample-apiserver/pkg/registry/wardle/flunder
|
||||
test/e2e/common
|
||||
test/e2e/lifecycle/bootstrap
|
||||
test/e2e/storage/vsphere
|
||||
test/e2e_node/remote
|
||||
test/e2e_node/runner/remote
|
||||
|
@ -27,7 +27,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
TokenIDBytes = 3
|
||||
// TokenIDBytes is the length of the byte array to generate tokenID.
|
||||
TokenIDBytes = 3
|
||||
|
||||
// TokenSecretBytes is the length of the byte array to generate tokenSecret.
|
||||
TokenSecretBytes = 8
|
||||
)
|
||||
|
||||
@ -50,34 +53,34 @@ var _ = lifecycle.SIGDescribe("[Feature:BootstrapTokens]", func() {
|
||||
|
||||
ginkgo.It("should sign the new added bootstrap tokens", func() {
|
||||
ginkgo.By("create a new bootstrap token secret")
|
||||
tokenId, err := GenerateTokenId()
|
||||
tokenID, err := GenerateTokenID()
|
||||
framework.ExpectNoError(err)
|
||||
secret := newTokenSecret(tokenId, "tokenSecret")
|
||||
secret := newTokenSecret(tokenID, "tokenSecret")
|
||||
_, err = c.CoreV1().Secrets(metav1.NamespaceSystem).Create(secret)
|
||||
secretNeedClean = bootstrapapi.BootstrapTokenSecretPrefix + tokenId
|
||||
secretNeedClean = bootstrapapi.BootstrapTokenSecretPrefix + tokenID
|
||||
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
ginkgo.By("wait for the bootstrap token secret be signed")
|
||||
err = WaitforSignedClusterInfoByBootStrapToken(c, tokenId)
|
||||
err = WaitforSignedClusterInfoByBootStrapToken(c, tokenID)
|
||||
framework.ExpectNoError(err)
|
||||
})
|
||||
|
||||
ginkgo.It("should resign the bootstrap tokens when the clusterInfo ConfigMap updated [Serial][Disruptive]", func() {
|
||||
ginkgo.By("create a new bootstrap token secret")
|
||||
tokenId, err := GenerateTokenId()
|
||||
tokenID, err := GenerateTokenID()
|
||||
framework.ExpectNoError(err)
|
||||
secret := newTokenSecret(tokenId, "tokenSecret")
|
||||
secret := newTokenSecret(tokenID, "tokenSecret")
|
||||
_, err = c.CoreV1().Secrets(metav1.NamespaceSystem).Create(secret)
|
||||
framework.ExpectNoError(err)
|
||||
secretNeedClean = bootstrapapi.BootstrapTokenSecretPrefix + tokenId
|
||||
secretNeedClean = bootstrapapi.BootstrapTokenSecretPrefix + tokenID
|
||||
|
||||
ginkgo.By("wait for the bootstrap token secret be signed")
|
||||
err = WaitforSignedClusterInfoByBootStrapToken(c, tokenId)
|
||||
err = WaitforSignedClusterInfoByBootStrapToken(c, tokenID)
|
||||
|
||||
cfgMap, err := f.ClientSet.CoreV1().ConfigMaps(metav1.NamespacePublic).Get(bootstrapapi.ConfigMapClusterInfo, metav1.GetOptions{})
|
||||
framework.ExpectNoError(err)
|
||||
signedToken, ok := cfgMap.Data[bootstrapapi.JWSSignatureKeyPrefix+tokenId]
|
||||
signedToken, ok := cfgMap.Data[bootstrapapi.JWSSignatureKeyPrefix+tokenID]
|
||||
framework.ExpectEqual(ok, true)
|
||||
|
||||
ginkgo.By("update the cluster-info ConfigMap")
|
||||
@ -97,28 +100,28 @@ var _ = lifecycle.SIGDescribe("[Feature:BootstrapTokens]", func() {
|
||||
}()
|
||||
|
||||
ginkgo.By("wait for signed bootstrap token updated")
|
||||
err = WaitForSignedClusterInfoGetUpdatedByBootstrapToken(c, tokenId, signedToken)
|
||||
err = WaitForSignedClusterInfoGetUpdatedByBootstrapToken(c, tokenID, signedToken)
|
||||
framework.ExpectNoError(err)
|
||||
})
|
||||
|
||||
ginkgo.It("should delete the signed bootstrap tokens from clusterInfo ConfigMap when bootstrap token is deleted", func() {
|
||||
ginkgo.By("create a new bootstrap token secret")
|
||||
tokenId, err := GenerateTokenId()
|
||||
tokenID, err := GenerateTokenID()
|
||||
framework.ExpectNoError(err)
|
||||
secret := newTokenSecret(tokenId, "tokenSecret")
|
||||
secret := newTokenSecret(tokenID, "tokenSecret")
|
||||
_, err = c.CoreV1().Secrets(metav1.NamespaceSystem).Create(secret)
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
ginkgo.By("wait for the bootstrap secret be signed")
|
||||
err = WaitforSignedClusterInfoByBootStrapToken(c, tokenId)
|
||||
err = WaitforSignedClusterInfoByBootStrapToken(c, tokenID)
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
ginkgo.By("delete the bootstrap token secret")
|
||||
err = c.CoreV1().Secrets(metav1.NamespaceSystem).Delete(bootstrapapi.BootstrapTokenSecretPrefix+tokenId, &metav1.DeleteOptions{})
|
||||
err = c.CoreV1().Secrets(metav1.NamespaceSystem).Delete(bootstrapapi.BootstrapTokenSecretPrefix+tokenID, &metav1.DeleteOptions{})
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
ginkgo.By("wait for the bootstrap token removed from cluster-info ConfigMap")
|
||||
err = WaitForSignedClusterInfoByBootstrapTokenToDisappear(c, tokenId)
|
||||
err = WaitForSignedClusterInfoByBootstrapTokenToDisappear(c, tokenID)
|
||||
framework.ExpectNoError(err)
|
||||
})
|
||||
})
|
||||
|
@ -49,36 +49,36 @@ var _ = lifecycle.SIGDescribe("[Feature:BootstrapTokens]", func() {
|
||||
})
|
||||
ginkgo.It("should delete the token secret when the secret expired", func() {
|
||||
ginkgo.By("create a new expired bootstrap token secret")
|
||||
tokenId, err := GenerateTokenId()
|
||||
tokenID, err := GenerateTokenID()
|
||||
framework.ExpectNoError(err)
|
||||
tokenSecret, err := GenerateTokenSecret()
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
secret := newTokenSecret(tokenId, tokenSecret)
|
||||
secret := newTokenSecret(tokenID, tokenSecret)
|
||||
addSecretExpiration(secret, TimeStringFromNow(-time.Hour))
|
||||
_, err = c.CoreV1().Secrets(metav1.NamespaceSystem).Create(secret)
|
||||
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
ginkgo.By("wait for the bootstrap token secret be deleted")
|
||||
err = WaitForBootstrapTokenSecretToDisappear(c, tokenId)
|
||||
err = WaitForBootstrapTokenSecretToDisappear(c, tokenID)
|
||||
framework.ExpectNoError(err)
|
||||
})
|
||||
|
||||
ginkgo.It("should not delete the token secret when the secret is not expired", func() {
|
||||
ginkgo.By("create a new expired bootstrap token secret")
|
||||
tokenId, err := GenerateTokenId()
|
||||
tokenID, err := GenerateTokenID()
|
||||
framework.ExpectNoError(err)
|
||||
tokenSecret, err := GenerateTokenSecret()
|
||||
framework.ExpectNoError(err)
|
||||
secret := newTokenSecret(tokenId, tokenSecret)
|
||||
secret := newTokenSecret(tokenID, tokenSecret)
|
||||
addSecretExpiration(secret, TimeStringFromNow(time.Hour))
|
||||
_, err = c.CoreV1().Secrets(metav1.NamespaceSystem).Create(secret)
|
||||
secretNeedClean = bootstrapapi.BootstrapTokenSecretPrefix + tokenId
|
||||
secretNeedClean = bootstrapapi.BootstrapTokenSecretPrefix + tokenID
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
ginkgo.By("wait for the bootstrap token secret not be deleted")
|
||||
err = WaitForBootstrapTokenSecretNotDisappear(c, tokenId, 20*time.Second)
|
||||
err = WaitForBootstrapTokenSecretNotDisappear(c, tokenID, 20*time.Second)
|
||||
framework.ExpectNoError(err)
|
||||
})
|
||||
})
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
apierrs "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
@ -46,13 +46,16 @@ func newTokenSecret(tokenID, tokenSecret string) *v1.Secret {
|
||||
}
|
||||
}
|
||||
|
||||
func GenerateTokenId() (string, error) {
|
||||
// GenerateTokenID generates tokenID.
|
||||
func GenerateTokenID() (string, error) {
|
||||
tokenID, err := randBytes(TokenIDBytes)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return tokenID, nil
|
||||
}
|
||||
|
||||
// GenerateTokenSecret generates tokenSecret.
|
||||
func GenerateTokenSecret() (string, error) {
|
||||
tokenSecret, err := randBytes(TokenSecretBytes)
|
||||
if err != nil {
|
||||
@ -74,10 +77,13 @@ func addSecretExpiration(s *v1.Secret, expiration string) {
|
||||
s.Data[bootstrapapi.BootstrapTokenExpirationKey] = []byte(expiration)
|
||||
}
|
||||
|
||||
// TimeStringFromNow returns the time as a string from now.
|
||||
// e.g: 2019-12-03T14:30:40+08:00.
|
||||
func TimeStringFromNow(delta time.Duration) string {
|
||||
return time.Now().Add(delta).Format(time.RFC3339)
|
||||
}
|
||||
|
||||
// WaitforSignedClusterInfoByBootStrapToken waits for signed cluster info by bootstrap token.
|
||||
func WaitforSignedClusterInfoByBootStrapToken(c clientset.Interface, tokenID string) error {
|
||||
|
||||
return wait.Poll(framework.Poll, 2*time.Minute, func() (bool, error) {
|
||||
@ -94,6 +100,7 @@ func WaitforSignedClusterInfoByBootStrapToken(c clientset.Interface, tokenID str
|
||||
})
|
||||
}
|
||||
|
||||
// WaitForSignedClusterInfoGetUpdatedByBootstrapToken waits for signed cluster info to be updated by bootstrap token.
|
||||
func WaitForSignedClusterInfoGetUpdatedByBootstrapToken(c clientset.Interface, tokenID string, signedToken string) error {
|
||||
|
||||
return wait.Poll(framework.Poll, 2*time.Minute, func() (bool, error) {
|
||||
@ -110,6 +117,7 @@ func WaitForSignedClusterInfoGetUpdatedByBootstrapToken(c clientset.Interface, t
|
||||
})
|
||||
}
|
||||
|
||||
// WaitForSignedClusterInfoByBootstrapTokenToDisappear waits for signed cluster info to be disappeared by bootstrap token.
|
||||
func WaitForSignedClusterInfoByBootstrapTokenToDisappear(c clientset.Interface, tokenID string) error {
|
||||
|
||||
return wait.Poll(framework.Poll, 2*time.Minute, func() (bool, error) {
|
||||
@ -126,6 +134,7 @@ func WaitForSignedClusterInfoByBootstrapTokenToDisappear(c clientset.Interface,
|
||||
})
|
||||
}
|
||||
|
||||
// WaitForBootstrapTokenSecretToDisappear waits for bootstrap token secret to be disappeared.
|
||||
func WaitForBootstrapTokenSecretToDisappear(c clientset.Interface, tokenID string) error {
|
||||
|
||||
return wait.Poll(framework.Poll, 1*time.Minute, func() (bool, error) {
|
||||
@ -137,6 +146,7 @@ func WaitForBootstrapTokenSecretToDisappear(c clientset.Interface, tokenID strin
|
||||
})
|
||||
}
|
||||
|
||||
// WaitForBootstrapTokenSecretNotDisappear waits for bootstrap token secret not to be disappeared and takes time for the specified timeout as success path.
|
||||
func WaitForBootstrapTokenSecretNotDisappear(c clientset.Interface, tokenID string, t time.Duration) error {
|
||||
err := wait.Poll(framework.Poll, t, func() (bool, error) {
|
||||
secret, err := c.CoreV1().Secrets(metav1.NamespaceSystem).Get(bootstrapapi.BootstrapTokenSecretPrefix+tokenID, metav1.GetOptions{})
|
||||
|
@ -47,7 +47,7 @@ func (b bootstrapSecrets) Get(name string) (*corev1.Secret, error) {
|
||||
|
||||
// TestBootstrapTokenAuth tests the bootstrap token auth provider
|
||||
func TestBootstrapTokenAuth(t *testing.T) {
|
||||
tokenID, err := bootstraputil.GenerateTokenId()
|
||||
tokenID, err := bootstraputil.GenerateTokenID()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user