mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-10 18:06:55 +00:00
* add image verification * inline policy list Signed-off-by: Jim Bugwadia <jim@nirmata.com> * cosign version and dependencies updates Signed-off-by: Jim Bugwadia <jim@nirmata.com> * add registry initialization Signed-off-by: Jim Bugwadia <jim@nirmata.com> * add build tag to exclude k8schain for cloud providers Signed-off-by: Jim Bugwadia <jim@nirmata.com> * add build tag to exclude k8schain for cloud providers Signed-off-by: Jim Bugwadia <jim@nirmata.com> * generate deep copy and other fixtures Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix deep copy issues Signed-off-by: Jim Bugwadia <jim@nirmata.com> * mutate images to add digest Signed-off-by: Jim Bugwadia <jim@nirmata.com> * add certificates to Kyverno container for HTTPS lookups Signed-off-by: Jim Bugwadia <jim@nirmata.com> * align flag syntax Signed-off-by: Jim Bugwadia <jim@nirmata.com> * update docs Signed-off-by: Jim Bugwadia <jim@nirmata.com> * update dependencies Signed-off-by: Jim Bugwadia <jim@nirmata.com> * update dependencies Signed-off-by: Jim Bugwadia <jim@nirmata.com> * patch image with digest and fix checks Signed-off-by: Jim Bugwadia <jim@nirmata.com> * hardcode image for demos Signed-off-by: Jim Bugwadia <jim@nirmata.com> * add default registry (docker.io) before calling reference.Parse Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix definition Signed-off-by: Jim Bugwadia <jim@nirmata.com> * increase webhook timeout Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix args Signed-off-by: Jim Bugwadia <jim@nirmata.com> * run gofmt Signed-off-by: Jim Bugwadia <jim@nirmata.com> * rename for clarity Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix HasImageVerify check Signed-off-by: Jim Bugwadia <jim@nirmata.com> * align make test commands Signed-off-by: Jim Bugwadia <jim@nirmata.com> * align make test commands Signed-off-by: Jim Bugwadia <jim@nirmata.com> * align make test commands Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix linter error Signed-off-by: Jim Bugwadia <jim@nirmata.com> * format Signed-off-by: Jim Bugwadia <jim@nirmata.com> * handle API conflict and retry Signed-off-by: Jim Bugwadia <jim@nirmata.com> * format Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix reviewdog issues Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix make for unit tests Signed-off-by: Jim Bugwadia <jim@nirmata.com> * improve error message Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix durations Signed-off-by: Jim Bugwadia <jim@nirmata.com> * handle errors in tests Signed-off-by: Jim Bugwadia <jim@nirmata.com> * print policy name Signed-off-by: Jim Bugwadia <jim@nirmata.com> * update tests Signed-off-by: Jim Bugwadia <jim@nirmata.com> * add retries and duration to error log Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix time check in tests Signed-off-by: Jim Bugwadia <jim@nirmata.com> * round creation times in test Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix retry loop Signed-off-by: Jim Bugwadia <jim@nirmata.com> * remove timing check for policy creation Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix e2e error - policy not found Signed-off-by: Shuting Zhao <shutting06@gmail.com> * update string comparison method Signed-off-by: Shuting Zhao <shutting06@gmail.com> * fix test Generate_Namespace_Label_Actions Signed-off-by: Shuting Zhao <shutting06@gmail.com> * add debug info for e2e tests Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix error Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix generate bug Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix format Signed-off-by: Jim Bugwadia <jim@nirmata.com> * add check for update operations Signed-off-by: Jim Bugwadia <jim@nirmata.com> * increase time for deleteing a resource Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix check Signed-off-by: Jim Bugwadia <jim@nirmata.com> Co-authored-by: Shuting Zhao <shutting06@gmail.com>
117 lines
3.2 KiB
Go
117 lines
3.2 KiB
Go
package validate
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/kyverno/kyverno/test/e2e"
|
|
. "github.com/onsi/ginkgo"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var (
|
|
// Cluster Polict GVR
|
|
clPolGVR = e2e.GetGVR("kyverno.io", "v1", "clusterpolicies")
|
|
// Namespace GVR
|
|
nsGVR = e2e.GetGVR("", "v1", "namespaces")
|
|
// ConfigMap GVR
|
|
cmGVR = e2e.GetGVR("", "v1", "configmaps")
|
|
|
|
crdGVR = e2e.GetGVR("apiextensions.k8s.io", "v1", "customresourcedefinitions")
|
|
|
|
// ClusterPolicy Namespace
|
|
clPolNS = ""
|
|
// Namespace Name
|
|
// Hardcoded in YAML Definition
|
|
nspace = "test-validate"
|
|
|
|
crdName = "kustomizations.kustomize.toolkit.fluxcd.io"
|
|
)
|
|
|
|
func Test_Validate_Sets(t *testing.T) {
|
|
RegisterTestingT(t)
|
|
if os.Getenv("E2E") == "" {
|
|
t.Skip("Skipping E2E Test")
|
|
}
|
|
|
|
// Generate E2E Client
|
|
e2eClient, err := e2e.NewE2EClient()
|
|
Expect(err).To(BeNil())
|
|
|
|
for _, test := range ValidateTests {
|
|
By(fmt.Sprintf("Test to validate objects: \"%s\"", test.TestName))
|
|
|
|
// Clean up Resources
|
|
By(fmt.Sprintf("Cleaning Cluster Policies"))
|
|
e2eClient.CleanClusterPolicies(clPolGVR)
|
|
// Clear Namespace
|
|
By(fmt.Sprintf("Deleting Namespace: \"%s\"", nspace))
|
|
e2eClient.DeleteClusteredResource(nsGVR, nspace)
|
|
//CleanUp CRDs
|
|
e2eClient.DeleteClusteredResource(crdGVR, crdName)
|
|
|
|
// Wait Till Deletion of Namespace
|
|
e2e.GetWithRetry(time.Duration(1*time.Second), 15, func() error {
|
|
_, err := e2eClient.GetClusteredResource(nsGVR, nspace)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return errors.New("Deleting Namespace")
|
|
})
|
|
|
|
// Create Namespace
|
|
By(fmt.Sprintf("Creating namespace \"%s\"", nspace))
|
|
_, err = e2eClient.CreateClusteredResourceYaml(nsGVR, namespaceYaml)
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
// Create policy
|
|
By(fmt.Sprintf("Creating policy in \"%s\"", clPolNS))
|
|
_, err = e2eClient.CreateNamespacedResourceYaml(clPolGVR, clPolNS, test.Data)
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
// Create Flux CRD
|
|
By(fmt.Sprintf("Creating Flux CRD in \"%s\"", nspace))
|
|
_, err = e2eClient.CreateClusteredResourceYaml(crdGVR, kyverno_2043_FluxCRD)
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
// Wait till CRD is created
|
|
e2e.GetWithRetry(time.Duration(1*time.Second), 15, func() error {
|
|
_, err := e2eClient.GetClusteredResource(crdGVR, crdName)
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
return errors.New("Waiting for CRD to be created...")
|
|
})
|
|
|
|
// Created CRD is not a garantee that we already can create new resources
|
|
time.Sleep(3 * time.Second)
|
|
|
|
// Create Kustomize resource
|
|
kustomizeGVR := e2e.GetGVR("kustomize.toolkit.fluxcd.io", "v1beta1", "kustomizations")
|
|
By(fmt.Sprintf("Creating Kustomize resource in \"%s\"", nspace))
|
|
_, err = e2eClient.CreateNamespacedResourceYaml(kustomizeGVR, nspace, kyverno_2043_FluxKustomization)
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
//CleanUp Resources
|
|
e2eClient.CleanClusterPolicies(clPolGVR)
|
|
|
|
//CleanUp CRDs
|
|
e2eClient.DeleteClusteredResource(crdGVR, crdName)
|
|
|
|
// Clear Namespace
|
|
e2eClient.DeleteClusteredResource(nsGVR, nspace)
|
|
// Wait Till Deletion of Namespace
|
|
e2e.GetWithRetry(time.Duration(1*time.Second), 15, func() error {
|
|
_, err := e2eClient.GetClusteredResource(nsGVR, nspace)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return errors.New("Deleting Namespace")
|
|
})
|
|
|
|
By(fmt.Sprintf("Test %s Completed \n\n\n", test.TestName))
|
|
}
|
|
}
|