mirror of
https://github.com/kyverno/kyverno.git
synced 2025-04-08 10:04:25 +00:00
Enable verifyImages and CLI registry tests (#3684)
Signed-off-by: Sambhav Kothari <skothari44@bloomberg.net>
This commit is contained in:
parent
0ae671ca7a
commit
9d13e89697
3 changed files with 62 additions and 28 deletions
test/e2e/verifyimages
|
@ -31,7 +31,7 @@ var VerifyImagesTests = []struct {
|
|||
PolicyName: "tasks",
|
||||
PolicyRaw: kyvernoTaskPolicyWithSimpleExtractor,
|
||||
ResourceName: "example-task-name",
|
||||
ResourceNamespace: "test-validate",
|
||||
ResourceNamespace: "test-verify-images",
|
||||
ResourceGVR: taskGVR,
|
||||
ResourceRaw: tektonTask,
|
||||
MustSucceed: false,
|
||||
|
@ -42,7 +42,7 @@ var VerifyImagesTests = []struct {
|
|||
PolicyName: "tasks",
|
||||
PolicyRaw: kyvernoTaskPolicyWithComplexExtractor,
|
||||
ResourceName: "example-task-name",
|
||||
ResourceNamespace: "test-validate",
|
||||
ResourceNamespace: "test-verify-images",
|
||||
ResourceGVR: taskGVR,
|
||||
ResourceRaw: tektonTask,
|
||||
MustSucceed: false,
|
||||
|
@ -53,7 +53,7 @@ var VerifyImagesTests = []struct {
|
|||
PolicyName: "tasks",
|
||||
PolicyRaw: kyvernoTaskPolicyWithoutExtractor,
|
||||
ResourceName: "example-task-name",
|
||||
ResourceNamespace: "test-validate",
|
||||
ResourceNamespace: "test-verify-images",
|
||||
ResourceGVR: taskGVR,
|
||||
ResourceRaw: tektonTask,
|
||||
MustSucceed: true,
|
||||
|
@ -64,7 +64,7 @@ var VerifyImagesTests = []struct {
|
|||
PolicyName: "tasks",
|
||||
PolicyRaw: kyvernoTaskPolicyKeyless,
|
||||
ResourceName: "example-task-name",
|
||||
ResourceNamespace: "test-validate",
|
||||
ResourceNamespace: "test-verify-images",
|
||||
ResourceGVR: taskGVR,
|
||||
ResourceRaw: tektonTaskVerified,
|
||||
MustSucceed: true,
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
package verifyimages
|
||||
|
||||
// Namespace Description
|
||||
var namespaceYaml = []byte(`
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: test-verify-images
|
||||
`)
|
||||
import "fmt"
|
||||
|
||||
func newNamespaceYaml(name string) []byte {
|
||||
ns := fmt.Sprintf(`
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: %s
|
||||
`, name)
|
||||
return []byte(ns)
|
||||
}
|
||||
|
||||
var tektonTaskCRD = []byte(`
|
||||
apiVersion: apiextensions.k8s.io/v1
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/kyverno/kyverno/test/e2e"
|
||||
commonE2E "github.com/kyverno/kyverno/test/e2e/common"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
@ -38,33 +39,57 @@ func TestImageVerify(t *testing.T) {
|
|||
e2eClient, err := e2e.NewE2EClient()
|
||||
Expect(err).To(BeNil())
|
||||
for _, test := range VerifyImagesTests {
|
||||
By(fmt.Sprintf("Test to validate objects: \"%s\"", test.TestName))
|
||||
By("Deleting Cluster Policies...")
|
||||
_ = e2eClient.CleanClusterPolicies(policyGVR)
|
||||
|
||||
// Clean up Resources
|
||||
By(string("Cleaning Cluster Policies"))
|
||||
e2eClient.CleanClusterPolicies(policyGVR)
|
||||
// Clear Namespace
|
||||
By(fmt.Sprintf("Deleting Namespace: \"%s\"", nspace))
|
||||
e2eClient.DeleteClusteredResource(namespaceGVR, nspace)
|
||||
//CleanUp CRDs
|
||||
e2eClient.DeleteClusteredResource(crdGVR, crdName)
|
||||
By("Deleting Resource...")
|
||||
_ = e2eClient.DeleteNamespacedResource(test.ResourceGVR, test.ResourceNamespace, test.ResourceName)
|
||||
|
||||
// Wait Till Deletion of Namespace
|
||||
e2e.GetWithRetry(time.Duration(1*time.Second), 15, func() error {
|
||||
_, err := e2eClient.GetClusteredResource(namespaceGVR, nspace)
|
||||
By("Deleting Namespace...")
|
||||
By(fmt.Sprintf("Deleting Namespace: %s...", test.ResourceNamespace))
|
||||
_ = e2eClient.DeleteClusteredResource(namespaceGVR, test.ResourceNamespace)
|
||||
|
||||
By("Wait Till Deletion of Namespace...")
|
||||
err = e2e.GetWithRetry(1*time.Second, 15, func() error {
|
||||
_, err := e2eClient.GetClusteredResource(namespaceGVR, test.ResourceNamespace)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return errors.New("Deleting Namespace")
|
||||
return fmt.Errorf("failed to delete namespace: %v", err)
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// Create Namespace
|
||||
By(fmt.Sprintf("Creating namespace \"%s\"", nspace))
|
||||
_, err = e2eClient.CreateClusteredResourceYaml(namespaceGVR, namespaceYaml)
|
||||
By(fmt.Sprintf("Deleting CRD: %s...", policyNamespace))
|
||||
e2eClient.DeleteClusteredResource(crdGVR, crdName)
|
||||
|
||||
By("Wait Till Deletion of CRD...")
|
||||
err = e2e.GetWithRetry(1*time.Second, 15, func() error {
|
||||
_, err := e2eClient.GetClusteredResource(crdGVR, crdName)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("failed to crd: %v", err)
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By(fmt.Sprintf("Creating Namespace: %s...", test.ResourceNamespace))
|
||||
_, err = e2eClient.CreateClusteredResourceYaml(namespaceGVR, newNamespaceYaml(test.ResourceNamespace))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Wait Till Creation of Namespace...")
|
||||
err = e2e.GetWithRetry(1*time.Second, 15, func() error {
|
||||
_, err := e2eClient.GetClusteredResource(namespaceGVR, test.ResourceNamespace)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// Create Tekton CRD
|
||||
By(fmt.Sprintf("Creating Tekton CRD in \"%s\"", nspace))
|
||||
By("Creating Tekton CRD")
|
||||
_, err = e2eClient.CreateClusteredResourceYaml(crdGVR, tektonTaskCRD)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
|
@ -84,6 +109,11 @@ func TestImageVerify(t *testing.T) {
|
|||
By(fmt.Sprintf("Creating policy in \"%s\"", policyNamespace))
|
||||
_, err = e2eClient.CreateNamespacedResourceYaml(policyGVR, policyNamespace, test.PolicyName, test.PolicyRaw)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
err = commonE2E.PolicyCreated(test.PolicyName)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating Resource...")
|
||||
_, err = e2eClient.CreateNamespacedResourceYaml(test.ResourceGVR, test.ResourceNamespace, test.PolicyName, test.ResourceRaw)
|
||||
|
||||
if test.MustSucceed {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
|
Loading…
Add table
Reference in a new issue