containerized-data-importer/tests/tests_suite_test.go
Arnon Gilboa addf25b4f9
Support registry import using node docker cache (#1913)
* Support registry import using node docker cache

The new CRI (container runtime interface) importer pod is created with three containers and a shared emptyDir volume:
-Init container: copies static http server binary to empty dir
-Server container: container image container configured to run the http binary and serve up the image file in /data
-Client container: import.sh uses cdi-import to import from server container, and writes "done" file on emptydir
-Server container sees "done" file and exits

Thanks mhenriks for the PoC!

Done:
-added ImportMethod to DataVolumeSourceRegistry (DataVolume.Spec.Source.Registry, DataImportCron.Spec.Source.Registry).
Import method can be "skopeo" (default), or "cri" for container runtime interface based import
-added cdi-containerimage-server & import.sh to the cdi-importer container

ToDo:
-utests and func tests
-doc

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

* Add tests, fix CR comments

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

* CR fixes

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

* Use deployment docker prefix and tag in func tests

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

* Add OpenShift ImageStreams import support

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

* Add importer pod lookup annotation for image streams

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

* Add pullMethod and imageStream doc

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>
2021-09-20 22:05:36 +02:00

125 lines
5.3 KiB
Go

package tests_test
import (
"flag"
"fmt"
"testing"
"time"
"github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
"kubevirt.io/containerized-data-importer/tests"
"kubevirt.io/containerized-data-importer/tests/framework"
"kubevirt.io/containerized-data-importer/tests/reporters"
"kubevirt.io/containerized-data-importer/tests/utils"
)
const (
pollInterval = 2 * time.Second
nsDeletedTimeout = 270 * time.Second
)
var (
kubectlPath = flag.String("kubectl-path", "kubectl", "The path to the kubectl binary")
ocPath = flag.String("oc-path", "oc", "The path to the oc binary")
cdiInstallNs = flag.String("cdi-namespace", "cdi", "The namespace of the CDI controller")
kubeConfig = flag.String("kubeconfig", "/var/run/kubernetes/admin.kubeconfig", "The absolute path to the kubeconfig file")
master = flag.String("master", "", "master url:port")
goCLIPath = flag.String("gocli-path", "cli.sh", "The path to cli script")
snapshotSCName = flag.String("snapshot-sc", "", "The Storage Class supporting snapshots")
blockSCName = flag.String("block-sc", "", "The Storage Class supporting block mode volumes")
csiCloneSCName = flag.String("csiclone-sc", "", "The Storage Class supporting CSI Volume Cloning")
dockerPrefix = flag.String("docker-prefix", "", "The docker host:port")
dockerTag = flag.String("docker-tag", "", "The docker tag")
)
func TestTests(t *testing.T) {
defer GinkgoRecover()
RegisterFailHandler(tests.CDIFailHandler)
BuildTestSuite()
RunSpecsWithDefaultAndCustomReporters(t, "Tests Suite", reporters.NewReporters())
}
// To understand the order in which things are run, read http://onsi.github.io/ginkgo/#understanding-ginkgos-lifecycle
// flag parsing happens AFTER ginkgo has constructed the entire testing tree. So anything that uses information from flags
// cannot work when called during test tree construction.
func BuildTestSuite() {
BeforeSuite(func() {
fmt.Fprintf(ginkgo.GinkgoWriter, "Reading parameters\n")
// Read flags, and configure client instances
framework.ClientsInstance.KubectlPath = *kubectlPath
framework.ClientsInstance.OcPath = *ocPath
framework.ClientsInstance.CdiInstallNs = *cdiInstallNs
framework.ClientsInstance.KubeConfig = *kubeConfig
framework.ClientsInstance.Master = *master
framework.ClientsInstance.GoCLIPath = *goCLIPath
framework.ClientsInstance.SnapshotSCName = *snapshotSCName
framework.ClientsInstance.BlockSCName = *blockSCName
framework.ClientsInstance.CsiCloneSCName = *csiCloneSCName
framework.ClientsInstance.DockerPrefix = *dockerPrefix
framework.ClientsInstance.DockerTag = *dockerTag
fmt.Fprintf(ginkgo.GinkgoWriter, "Kubectl path: %s\n", framework.ClientsInstance.KubectlPath)
fmt.Fprintf(ginkgo.GinkgoWriter, "OC path: %s\n", framework.ClientsInstance.OcPath)
fmt.Fprintf(ginkgo.GinkgoWriter, "CDI install NS: %s\n", framework.ClientsInstance.CdiInstallNs)
fmt.Fprintf(ginkgo.GinkgoWriter, "Kubeconfig: %s\n", framework.ClientsInstance.KubeConfig)
fmt.Fprintf(ginkgo.GinkgoWriter, "Master: %s\n", framework.ClientsInstance.Master)
fmt.Fprintf(ginkgo.GinkgoWriter, "GO CLI path: %s\n", framework.ClientsInstance.GoCLIPath)
fmt.Fprintf(ginkgo.GinkgoWriter, "Snapshot SC: %s\n", framework.ClientsInstance.SnapshotSCName)
fmt.Fprintf(ginkgo.GinkgoWriter, "Block SC: %s\n", framework.ClientsInstance.BlockSCName)
fmt.Fprintf(ginkgo.GinkgoWriter, "CSI Volume Cloning SC: %s\n", framework.ClientsInstance.CsiCloneSCName)
fmt.Fprintf(ginkgo.GinkgoWriter, "DockerPrefix: %s\n", framework.ClientsInstance.DockerPrefix)
fmt.Fprintf(ginkgo.GinkgoWriter, "DockerTag: %s\n", framework.ClientsInstance.DockerTag)
restConfig, err := framework.ClientsInstance.LoadConfig()
if err != nil {
// Can't use Expect here due this being called outside of an It block, and Expect
// requires any calls to it to be inside an It block.
ginkgo.Fail("ERROR, unable to load RestConfig")
}
framework.ClientsInstance.RestConfig = restConfig
// clients
kcs, err := framework.ClientsInstance.GetKubeClient()
if err != nil {
ginkgo.Fail(fmt.Sprintf("ERROR, unable to create K8SClient: %v", err))
}
framework.ClientsInstance.K8sClient = kcs
cs, err := framework.ClientsInstance.GetCdiClient()
if err != nil {
ginkgo.Fail(fmt.Sprintf("ERROR, unable to create CdiClient: %v", err))
}
framework.ClientsInstance.CdiClient = cs
extcs, err := framework.ClientsInstance.GetExtClient()
if err != nil {
ginkgo.Fail(fmt.Sprintf("ERROR, unable to create CsiClient: %v", err))
}
framework.ClientsInstance.ExtClient = extcs
crClient, err := framework.ClientsInstance.GetCrClient()
if err != nil {
ginkgo.Fail(fmt.Sprintf("ERROR, unable to create CrClient: %v", err))
}
framework.ClientsInstance.CrClient = crClient
dyn, err := framework.ClientsInstance.GetDynamicClient()
if err != nil {
ginkgo.Fail(fmt.Sprintf("ERROR, unable to create DynamicClient: %v", err))
}
framework.ClientsInstance.DynamicClient = dyn
utils.CacheTestsData(framework.ClientsInstance.K8sClient, framework.ClientsInstance.CdiInstallNs)
})
AfterSuite(func() {
Eventually(func() []corev1.Namespace {
nsList, _ := utils.GetTestNamespaceList(framework.ClientsInstance.K8sClient, framework.NsPrefixLabel)
return nsList.Items
}, nsDeletedTimeout, pollInterval).Should(BeEmpty())
})
}