Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 405e2e9

Browse files
committedJan 11, 2021
fix: load required docker images for kind cluster in ci e2e test
1 parent e3313a0 commit 405e2e9

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
 

‎test/e2e/bundle_image_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ import (
1515
batchv1 "k8s.io/api/batch/v1"
1616
corev1 "k8s.io/api/core/v1"
1717
rbacv1 "k8s.io/api/rbac/v1"
18+
"k8s.io/apimachinery/pkg/api/errors"
1819
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1920
"k8s.io/apimachinery/pkg/watch"
21+
"k8s.io/client-go/kubernetes"
2022

2123
"github.com/operator-framework/operator-registry/pkg/client"
2224
"github.com/operator-framework/operator-registry/pkg/configmap"
@@ -754,6 +756,9 @@ var _ = Describe("Launch bundle", func() {
754756
buildContainer(initImage, imageDirectory+"serve.Dockerfile", "../../bin", GinkgoWriter)
755757
buildContainer(bundleImage, imageDirectory+"bundle.Dockerfile", imageDirectory, GinkgoWriter)
756758

759+
err = maybeLoadKind(kubeclient, GinkgoWriter, initImage, bundleImage)
760+
Expect(err).ToNot(HaveOccurred(), "error loading required images into cluster")
761+
757762
By("creating a batch job")
758763
bundleDataConfigMap, job, err := configmap.LaunchBundleImage(kubeclient, bundleImage, initImage, namespace)
759764
Expect(err).NotTo(HaveOccurred())
@@ -816,3 +821,44 @@ var _ = Describe("Launch bundle", func() {
816821
})
817822
})
818823
})
824+
825+
const kindControlPlaneNodeName = "kind-control-plane"
826+
827+
func isKindCluster(client *kubernetes.Clientset) (bool, error) {
828+
kindNode, err := client.CoreV1().Nodes().Get(context.TODO(), kindControlPlaneNodeName, metav1.GetOptions{})
829+
if err != nil {
830+
if errors.IsNotFound(err) {
831+
// not a kind cluster
832+
return false, nil
833+
}
834+
// transient error accessing nodes in cluster
835+
// return an error, failing the test
836+
return false, fmt.Errorf("accessing nodes in cluster")
837+
}
838+
if kindNode == nil {
839+
return true, fmt.Errorf("finding kind node %s in cluster", kindControlPlaneNodeName)
840+
}
841+
return true, nil
842+
}
843+
844+
// maybeLoadKind loads the built images via kind load docker-image if the test is running in a kind cluster
845+
func maybeLoadKind(client *kubernetes.Clientset, w io.Writer, images ...string) error {
846+
kind, err := isKindCluster(client)
847+
if err != nil {
848+
return err
849+
}
850+
if !kind {
851+
return nil
852+
}
853+
854+
for _, image := range images {
855+
cmd := exec.Command("kind", "load", "docker-image", image)
856+
cmd.Stderr = w
857+
cmd.Stdout = w
858+
err := cmd.Run()
859+
if err != nil {
860+
return err
861+
}
862+
}
863+
return nil
864+
}

0 commit comments

Comments
 (0)
Please sign in to comment.