mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
e2e_auth: stop using deprecated framework.ExpectEqual
This commit is contained in:
parent
fa88c0b779
commit
36d3672249
@ -22,10 +22,10 @@ import (
|
||||
"crypto/x509/pkix"
|
||||
"encoding/json"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
"github.com/onsi/gomega"
|
||||
|
||||
certificatesv1 "k8s.io/api/certificates/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
@ -166,7 +166,7 @@ var _ = SIGDescribe("Certificates API [Privileged:ClusterAdmin]", func() {
|
||||
|
||||
certs, err := cert.ParseCertsPEM(csr.Status.Certificate)
|
||||
framework.ExpectNoError(err)
|
||||
framework.ExpectEqual(len(certs), 1, "expected a single cert, got %#v", certs)
|
||||
gomega.Expect(certs).To(gomega.HaveLen(1), "expected a single cert, got %#v", certs)
|
||||
cert := certs[0]
|
||||
// make sure the cert is not valid for longer than our requested time (plus allowance for backdating)
|
||||
if e, a := time.Hour+5*time.Minute, cert.NotAfter.Sub(cert.NotBefore); a > e {
|
||||
@ -182,7 +182,7 @@ var _ = SIGDescribe("Certificates API [Privileged:ClusterAdmin]", func() {
|
||||
defer func() {
|
||||
framework.ExpectNoError(csrClient.Delete(ctx, newCSR.Name, metav1.DeleteOptions{}))
|
||||
}()
|
||||
framework.ExpectEqual(newCSR.Spec.Username, commonName)
|
||||
gomega.Expect(newCSR.Spec.Username).To(gomega.Equal(commonName))
|
||||
})
|
||||
|
||||
/*
|
||||
@ -304,13 +304,13 @@ var _ = SIGDescribe("Certificates API [Privileged:ClusterAdmin]", func() {
|
||||
ginkgo.By("getting")
|
||||
gottenCSR, err := csrClient.Get(ctx, createdCSR.Name, metav1.GetOptions{})
|
||||
framework.ExpectNoError(err)
|
||||
framework.ExpectEqual(gottenCSR.UID, createdCSR.UID)
|
||||
framework.ExpectEqual(gottenCSR.Spec.ExpirationSeconds, csr.DurationToExpirationSeconds(time.Hour))
|
||||
gomega.Expect(gottenCSR.UID).To(gomega.Equal(createdCSR.UID))
|
||||
gomega.Expect(gottenCSR.Spec.ExpirationSeconds).To(gomega.Equal(csr.DurationToExpirationSeconds(time.Hour)))
|
||||
|
||||
ginkgo.By("listing")
|
||||
csrs, err := csrClient.List(ctx, metav1.ListOptions{FieldSelector: "spec.signerName=" + signerName})
|
||||
framework.ExpectNoError(err)
|
||||
framework.ExpectEqual(len(csrs.Items), 3, "filtered list should have 3 items")
|
||||
gomega.Expect(csrs.Items).To(gomega.HaveLen(3), "filtered list should have 3 items")
|
||||
|
||||
ginkgo.By("watching")
|
||||
framework.Logf("starting watch")
|
||||
@ -320,14 +320,14 @@ var _ = SIGDescribe("Certificates API [Privileged:ClusterAdmin]", func() {
|
||||
ginkgo.By("patching")
|
||||
patchedCSR, err := csrClient.Patch(ctx, createdCSR.Name, types.MergePatchType, []byte(`{"metadata":{"annotations":{"patched":"true"}}}`), metav1.PatchOptions{})
|
||||
framework.ExpectNoError(err)
|
||||
framework.ExpectEqual(patchedCSR.Annotations["patched"], "true", "patched object should have the applied annotation")
|
||||
gomega.Expect(patchedCSR.Annotations).To(gomega.HaveKeyWithValue("patched", "true"), "patched object should have the applied annotation")
|
||||
|
||||
ginkgo.By("updating")
|
||||
csrToUpdate := patchedCSR.DeepCopy()
|
||||
csrToUpdate.Annotations["updated"] = "true"
|
||||
updatedCSR, err := csrClient.Update(ctx, csrToUpdate, metav1.UpdateOptions{})
|
||||
framework.ExpectNoError(err)
|
||||
framework.ExpectEqual(updatedCSR.Annotations["updated"], "true", "updated object should have the applied annotation")
|
||||
gomega.Expect(updatedCSR.Annotations).To(gomega.HaveKeyWithValue("updated", "true"), "updated object should have the applied annotation")
|
||||
|
||||
framework.Logf("waiting for watch events with expected annotations")
|
||||
for sawAnnotations := false; !sawAnnotations; {
|
||||
@ -336,7 +336,7 @@ var _ = SIGDescribe("Certificates API [Privileged:ClusterAdmin]", func() {
|
||||
if !ok {
|
||||
framework.Fail("watch channel should not close")
|
||||
}
|
||||
framework.ExpectEqual(evt.Type, watch.Modified)
|
||||
gomega.Expect(evt.Type).To(gomega.Equal(watch.Modified))
|
||||
watchedCSR, isCSR := evt.Object.(*certificatesv1.CertificateSigningRequest)
|
||||
if !isCSR {
|
||||
framework.Failf("expected CSR, got %T", evt.Object)
|
||||
@ -358,17 +358,17 @@ var _ = SIGDescribe("Certificates API [Privileged:ClusterAdmin]", func() {
|
||||
ginkgo.By("getting /approval")
|
||||
gottenApproval, err := f.DynamicClient.Resource(csrResource).Get(ctx, createdCSR.Name, metav1.GetOptions{}, "approval")
|
||||
framework.ExpectNoError(err)
|
||||
framework.ExpectEqual(gottenApproval.GetObjectKind().GroupVersionKind(), certificatesv1.SchemeGroupVersion.WithKind("CertificateSigningRequest"))
|
||||
framework.ExpectEqual(gottenApproval.GetUID(), createdCSR.UID)
|
||||
gomega.Expect(gottenApproval.GetObjectKind().GroupVersionKind()).To(gomega.Equal(certificatesv1.SchemeGroupVersion.WithKind("CertificateSigningRequest")))
|
||||
gomega.Expect(gottenApproval.GetUID()).To(gomega.Equal(createdCSR.UID))
|
||||
|
||||
ginkgo.By("patching /approval")
|
||||
patchedApproval, err := csrClient.Patch(ctx, createdCSR.Name, types.MergePatchType,
|
||||
[]byte(`{"metadata":{"annotations":{"patchedapproval":"true"}},"status":{"conditions":[{"type":"ApprovalPatch","status":"True","reason":"e2e"}]}}`),
|
||||
metav1.PatchOptions{}, "approval")
|
||||
framework.ExpectNoError(err)
|
||||
framework.ExpectEqual(len(patchedApproval.Status.Conditions), 1, fmt.Sprintf("patched object should have the applied condition, got %#v", patchedApproval.Status.Conditions))
|
||||
framework.ExpectEqual(string(patchedApproval.Status.Conditions[0].Type), "ApprovalPatch", fmt.Sprintf("patched object should have the applied condition, got %#v", patchedApproval.Status.Conditions))
|
||||
framework.ExpectEqual(patchedApproval.Annotations["patchedapproval"], "true", "patched object should have the applied annotation")
|
||||
gomega.Expect(patchedApproval.Status.Conditions).To(gomega.HaveLen(1), "patched object should have the applied condition")
|
||||
gomega.Expect(string(patchedApproval.Status.Conditions[0].Type)).To(gomega.Equal("ApprovalPatch"), "patched object should have the applied condition, got %#v", patchedApproval.Status.Conditions)
|
||||
gomega.Expect(patchedApproval.Annotations).To(gomega.HaveKeyWithValue("patchedapproval", "true"), "patched object should have the applied annotation")
|
||||
|
||||
ginkgo.By("updating /approval")
|
||||
approvalToUpdate := patchedApproval.DeepCopy()
|
||||
@ -380,24 +380,24 @@ var _ = SIGDescribe("Certificates API [Privileged:ClusterAdmin]", func() {
|
||||
})
|
||||
updatedApproval, err := csrClient.UpdateApproval(ctx, approvalToUpdate.Name, approvalToUpdate, metav1.UpdateOptions{})
|
||||
framework.ExpectNoError(err)
|
||||
framework.ExpectEqual(len(updatedApproval.Status.Conditions), 2, fmt.Sprintf("updated object should have the applied condition, got %#v", updatedApproval.Status.Conditions))
|
||||
framework.ExpectEqual(updatedApproval.Status.Conditions[1].Type, certificatesv1.CertificateApproved, fmt.Sprintf("updated object should have the approved condition, got %#v", updatedApproval.Status.Conditions))
|
||||
gomega.Expect(updatedApproval.Status.Conditions).To(gomega.HaveLen(2), "updated object should have the applied condition, got %#v", updatedApproval.Status.Conditions)
|
||||
gomega.Expect(updatedApproval.Status.Conditions[1].Type).To(gomega.Equal(certificatesv1.CertificateApproved), "updated object should have the approved condition, got %#v", updatedApproval.Status.Conditions)
|
||||
|
||||
// /status subresource operations
|
||||
|
||||
ginkgo.By("getting /status")
|
||||
gottenStatus, err := f.DynamicClient.Resource(csrResource).Get(ctx, createdCSR.Name, metav1.GetOptions{}, "status")
|
||||
framework.ExpectNoError(err)
|
||||
framework.ExpectEqual(gottenStatus.GetObjectKind().GroupVersionKind(), certificatesv1.SchemeGroupVersion.WithKind("CertificateSigningRequest"))
|
||||
framework.ExpectEqual(gottenStatus.GetUID(), createdCSR.UID)
|
||||
gomega.Expect(gottenStatus.GetObjectKind().GroupVersionKind()).To(gomega.Equal(certificatesv1.SchemeGroupVersion.WithKind("CertificateSigningRequest")))
|
||||
gomega.Expect(gottenStatus.GetUID()).To(gomega.Equal(createdCSR.UID))
|
||||
|
||||
ginkgo.By("patching /status")
|
||||
patchedStatus, err := csrClient.Patch(ctx, createdCSR.Name, types.MergePatchType,
|
||||
[]byte(`{"metadata":{"annotations":{"patchedstatus":"true"}},"status":{"certificate":`+string(certificateDataJSON)+`}}`),
|
||||
metav1.PatchOptions{}, "status")
|
||||
framework.ExpectNoError(err)
|
||||
framework.ExpectEqual(patchedStatus.Status.Certificate, certificateData, "patched object should have the applied certificate")
|
||||
framework.ExpectEqual(patchedStatus.Annotations["patchedstatus"], "true", "patched object should have the applied annotation")
|
||||
gomega.Expect(patchedStatus.Status.Certificate).To(gomega.Equal(certificateData), "patched object should have the applied certificate")
|
||||
gomega.Expect(patchedStatus.Annotations).To(gomega.HaveKeyWithValue("patchedstatus", "true"), "patched object should have the applied annotation")
|
||||
|
||||
ginkgo.By("updating /status")
|
||||
statusToUpdate := patchedStatus.DeepCopy()
|
||||
@ -409,8 +409,8 @@ var _ = SIGDescribe("Certificates API [Privileged:ClusterAdmin]", func() {
|
||||
})
|
||||
updatedStatus, err := csrClient.UpdateStatus(ctx, statusToUpdate, metav1.UpdateOptions{})
|
||||
framework.ExpectNoError(err)
|
||||
framework.ExpectEqual(len(updatedStatus.Status.Conditions), len(statusToUpdate.Status.Conditions), fmt.Sprintf("updated object should have the applied condition, got %#v", updatedStatus.Status.Conditions))
|
||||
framework.ExpectEqual(string(updatedStatus.Status.Conditions[len(updatedStatus.Status.Conditions)-1].Type), "StatusUpdate", fmt.Sprintf("updated object should have the approved condition, got %#v", updatedStatus.Status.Conditions))
|
||||
gomega.Expect(updatedStatus.Status.Conditions).To(gomega.HaveLen(len(statusToUpdate.Status.Conditions)), "updated object should have the applied condition, got %#v", updatedStatus.Status.Conditions)
|
||||
gomega.Expect(string(updatedStatus.Status.Conditions[len(updatedStatus.Status.Conditions)-1].Type)).To(gomega.Equal("StatusUpdate"), "updated object should have the approved condition, got %#v", updatedStatus.Status.Conditions)
|
||||
|
||||
// main resource delete operations
|
||||
|
||||
@ -423,13 +423,13 @@ var _ = SIGDescribe("Certificates API [Privileged:ClusterAdmin]", func() {
|
||||
}
|
||||
csrs, err = csrClient.List(ctx, metav1.ListOptions{FieldSelector: "spec.signerName=" + signerName})
|
||||
framework.ExpectNoError(err)
|
||||
framework.ExpectEqual(len(csrs.Items), 2, "filtered list should have 2 items")
|
||||
gomega.Expect(csrs.Items).To(gomega.HaveLen(2), "filtered list should have 2 items")
|
||||
|
||||
ginkgo.By("deleting a collection")
|
||||
err = csrClient.DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{FieldSelector: "spec.signerName=" + signerName})
|
||||
framework.ExpectNoError(err)
|
||||
csrs, err = csrClient.List(ctx, metav1.ListOptions{FieldSelector: "spec.signerName=" + signerName})
|
||||
framework.ExpectNoError(err)
|
||||
framework.ExpectEqual(len(csrs.Items), 0, "filtered list should have 0 items")
|
||||
gomega.Expect(csrs.Items).To(gomega.BeEmpty(), "filtered list should have 0 items")
|
||||
})
|
||||
})
|
||||
|
@ -48,6 +48,7 @@ import (
|
||||
utilptr "k8s.io/utils/pointer"
|
||||
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
"github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
const rootCAConfigMapName = "kube-root-ca.crt"
|
||||
@ -110,8 +111,8 @@ var _ = SIGDescribe("ServiceAccounts", func() {
|
||||
rootCA, err := f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Get(ctx, rootCAConfigMapName, metav1.GetOptions{})
|
||||
framework.ExpectNoError(err)
|
||||
framework.Logf("Got root ca configmap in namespace %q", f.Namespace.Name)
|
||||
framework.ExpectEqual(mountedCA, rootCA.Data["ca.crt"])
|
||||
framework.ExpectEqual(mountedNamespace, f.Namespace.Name)
|
||||
gomega.Expect(mountedCA).To(gomega.Equal(rootCA.Data["ca.crt"]))
|
||||
gomega.Expect(mountedNamespace).To(gomega.Equal(f.Namespace.Name))
|
||||
// Token should be a valid credential that identifies the pod's service account
|
||||
tokenReview := &authenticationv1.TokenReview{Spec: authenticationv1.TokenReviewSpec{Token: mountedToken}}
|
||||
tokenReview, err = f.ClientSet.AuthenticationV1().TokenReviews().Create(ctx, tokenReview, metav1.CreateOptions{})
|
||||
@ -119,8 +120,8 @@ var _ = SIGDescribe("ServiceAccounts", func() {
|
||||
if !tokenReview.Status.Authenticated {
|
||||
framework.Fail("tokenReview is not authenticated")
|
||||
}
|
||||
framework.ExpectEqual(tokenReview.Status.Error, "")
|
||||
framework.ExpectEqual(tokenReview.Status.User.Username, "system:serviceaccount:"+f.Namespace.Name+":"+sa.Name)
|
||||
gomega.Expect(tokenReview.Status.Error).To(gomega.BeEmpty())
|
||||
gomega.Expect(tokenReview.Status.User.Username).To(gomega.Equal("system:serviceaccount:" + f.Namespace.Name + ":" + sa.Name))
|
||||
groups := sets.NewString(tokenReview.Status.User.Groups...)
|
||||
if !groups.Has("system:authenticated") {
|
||||
framework.Failf("expected system:authenticated group, had %v", groups.List())
|
||||
@ -662,7 +663,7 @@ var _ = SIGDescribe("ServiceAccounts", func() {
|
||||
|
||||
getServiceAccount, err := f.ClientSet.CoreV1().ServiceAccounts(testNamespaceName).Get(ctx, testServiceAccountName, metav1.GetOptions{})
|
||||
framework.ExpectNoError(err, "failed to fetch the created ServiceAccount")
|
||||
framework.ExpectEqual(createdServiceAccount.UID, getServiceAccount.UID)
|
||||
gomega.Expect(createdServiceAccount.UID).To(gomega.Equal(getServiceAccount.UID))
|
||||
|
||||
ginkgo.By("watching for the ServiceAccount to be added")
|
||||
resourceWatchTimeoutSeconds := int64(180)
|
||||
@ -819,7 +820,7 @@ var _ = SIGDescribe("ServiceAccounts", func() {
|
||||
ginkgo.By(fmt.Sprintf("Creating ServiceAccount %q ", saName))
|
||||
createdServiceAccount, err := saClient.Create(ctx, initialServiceAccount, metav1.CreateOptions{})
|
||||
framework.ExpectNoError(err)
|
||||
framework.ExpectEqual(createdServiceAccount.AutomountServiceAccountToken, utilptr.Bool(false), "Failed to set AutomountServiceAccountToken")
|
||||
gomega.Expect(createdServiceAccount.AutomountServiceAccountToken).To(gomega.Equal(utilptr.Bool(false)), "Failed to set AutomountServiceAccountToken")
|
||||
framework.Logf("AutomountServiceAccountToken: %v", *createdServiceAccount.AutomountServiceAccountToken)
|
||||
|
||||
ginkgo.By(fmt.Sprintf("Updating ServiceAccount %q ", saName))
|
||||
@ -833,7 +834,7 @@ var _ = SIGDescribe("ServiceAccounts", func() {
|
||||
return err
|
||||
})
|
||||
framework.ExpectNoError(err, "Failed to update ServiceAccount")
|
||||
framework.ExpectEqual(updatedServiceAccount.AutomountServiceAccountToken, utilptr.Bool(true), "Failed to set AutomountServiceAccountToken")
|
||||
gomega.Expect(updatedServiceAccount.AutomountServiceAccountToken).To(gomega.Equal(utilptr.Bool(true)), "Failed to set AutomountServiceAccountToken")
|
||||
framework.Logf("AutomountServiceAccountToken: %v", *updatedServiceAccount.AutomountServiceAccountToken)
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user