From 1b57e903e99984c925632698e6ae5617071644bd Mon Sep 17 00:00:00 2001 From: Bohan Chen Date: Fri, 7 Jul 2023 10:22:31 -0400 Subject: [PATCH 1/2] parse annotation prefix from repo source in case we ever test with non-github repos Signed-off-by: Bohan Chen --- .github/workflows/ci.yaml | 7 ++++++- test/config.go | 10 ++++++---- test/execute_build_test.go | 1 - 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3f1c6442d..41fb691b3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -366,7 +366,7 @@ jobs: export IMAGE_REGISTRY_USERNAME=${{ env.REGISTRY_USER }} export IMAGE_REGISTRY_PASSWORD=${{ env.REGISTRY_PASS }} - export GIT_PRIVATE_REPO=${{ env.E2E_PRIVATE_REPO }} + export GIT_PRIVATE_REPO=${{ vars.E2E_PRIVATE_REPO }} export GIT_BASIC_USERNAME="${{ secrets.E2E_PRIVATE_REPO_USERNAME }}" export GIT_BASIC_PASSWORD="${{ secrets.E2E_PRIVATE_REPO_PASSWORD }}" export GIT_SSH_PRIVATE_KEY="${{ secrets.E2E_PRIVATE_REPO_PRIVATE_KEY }}" @@ -407,6 +407,11 @@ jobs: export IMAGE_REGISTRY_PASSWORD=${{ env.REGISTRY_PASS }} export KPACK_TEST_NAMESPACE_LABELS="istio-injection=enabled" + export GIT_PRIVATE_REPO=${{ vars.E2E_PRIVATE_REPO }} + export GIT_BASIC_USERNAME="${{ secrets.E2E_PRIVATE_REPO_USERNAME }}" + export GIT_BASIC_PASSWORD="${{ secrets.E2E_PRIVATE_REPO_PASSWORD }}" + export GIT_SSH_PRIVATE_KEY="${{ secrets.E2E_PRIVATE_REPO_PRIVATE_KEY }}" + make e2e release: diff --git a/test/config.go b/test/config.go index 2d0b376ef..bb81eb8ba 100644 --- a/test/config.go +++ b/test/config.go @@ -114,14 +114,15 @@ func (c *config) makeGitBasicAuthSecret(secretName, namespace string) (*corev1.S } // convert `github.com/org/repo` -> `https://github.com/org/repo.git` - repo := fmt.Sprintf("https://%v.git", c.gitSourcePrivateRepo) + repo := fmt.Sprintf("https://%v", c.gitSourcePrivateRepo) + host := strings.Split(c.gitSourcePrivateRepo, "/")[0] return &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: secretName, Namespace: namespace, Annotations: map[string]string{ - v1alpha2.GITSecretAnnotationPrefix: "https://github.com", + v1alpha2.GITSecretAnnotationPrefix: fmt.Sprintf("https://%v", host), }, }, Data: map[string][]byte{ @@ -138,15 +139,16 @@ func (c *config) makeGitSSHAuthSecret(secretName, namespace string) (*corev1.Sec } // convert `github.com/org/repo` -> `git@github.com:org/repo.git` - repo := fmt.Sprintf("git@%v.git", c.gitSourcePrivateRepo) + repo := fmt.Sprintf("git@%v", c.gitSourcePrivateRepo) repo = strings.Replace(repo, "/", ":", 1) + host := strings.Split(c.gitSourcePrivateRepo, "/")[0] return &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: secretName, Namespace: namespace, Annotations: map[string]string{ - v1alpha2.GITSecretAnnotationPrefix: "git@github.com", + v1alpha2.GITSecretAnnotationPrefix: fmt.Sprintf("git@%v", host), }, }, Data: map[string][]byte{ diff --git a/test/execute_build_test.go b/test/execute_build_test.go index 377dbfabf..985e608b5 100644 --- a/test/execute_build_test.go +++ b/test/execute_build_test.go @@ -638,7 +638,6 @@ func waitUntilReady(t *testing.T, ctx context.Context, clients *clients, objects gvr, _ := meta.UnsafeGuessKindToResource(ob.GetGroupVersionKind()) eventually(t, func() bool { - unstructured, err := clients.dynamicClient.Resource(gvr).Namespace(namespace).Get(ctx, name, metav1.GetOptions{}) require.NoError(t, err) From d05ed73110e112a34d4efae2ed946d64a039b415 Mon Sep 17 00:00:00 2001 From: Bohan Chen Date: Fri, 7 Jul 2023 10:23:23 -0400 Subject: [PATCH 2/2] dump crds on failed test it.After doesn't run if t.Fatal/t.FailNow is called, so we have to rely on t.Cleanup to register a cleanup function Signed-off-by: Bohan Chen --- test/execute_build_test.go | 7 +++++ test/testhelpers.go | 59 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/test/execute_build_test.go b/test/execute_build_test.go index 985e608b5..6be2d8452 100644 --- a/test/execute_build_test.go +++ b/test/execute_build_test.go @@ -123,6 +123,13 @@ func testCreateImage(t *testing.T, when spec.G, it spec.S) { } it.Before(func() { + // register a cleanup function that dumps crds only if the test fails + t.Cleanup(func() { + if t.Failed() { + dumpK8s(t, ctx, clients, testNamespace) + } + }) + cfg = loadConfig(t) builtImages = map[string]struct{}{} diff --git a/test/testhelpers.go b/test/testhelpers.go index 656ee51e4..d23187623 100644 --- a/test/testhelpers.go +++ b/test/testhelpers.go @@ -1,8 +1,15 @@ package test import ( + "context" + "os" "testing" "time" + + "github.com/ghodss/yaml" + "github.com/pivotal/kpack/pkg/logs" + "github.com/stretchr/testify/require" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func eventually(t *testing.T, fun func() bool, interval time.Duration, duration time.Duration) { @@ -19,3 +26,55 @@ func eventually(t *testing.T, fun func() bool, interval time.Duration, duration } } } + +func printObject(t *testing.T, obj interface{}) { + data, err := yaml.Marshal(obj) + require.NoError(t, err) + + t.Log(string(data)) +} + +func dumpK8s(t *testing.T, ctx context.Context, clients *clients, namespace string) { + const header = "=================%v=================\n" + + t.Logf(header, "ClusterBuilders") + clusterBuilders, err := clients.client.KpackV1alpha2().ClusterBuilders().List(ctx, metav1.ListOptions{}) + require.NoError(t, err) + for _, cb := range clusterBuilders.Items { + printObject(t, cb) + } + + t.Logf(header, "Builders") + builders, err := clients.client.KpackV1alpha2().Builders(namespace).List(ctx, metav1.ListOptions{}) + require.NoError(t, err) + for _, b := range builders.Items { + printObject(t, b) + } + + t.Logf(header, "Images") + images, err := clients.client.KpackV1alpha2().Images(namespace).List(ctx, metav1.ListOptions{}) + require.NoError(t, err) + for _, i := range images.Items { + printObject(t, i) + } + + t.Logf(header, "SourceResolvers") + sourceResolvers, err := clients.client.KpackV1alpha2().SourceResolvers(namespace).List(ctx, metav1.ListOptions{}) + require.NoError(t, err) + for _, sr := range sourceResolvers.Items { + printObject(t, sr) + } + + t.Logf(header, "Pods") + pods, err := clients.k8sClient.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{}) + require.NoError(t, err) + for _, p := range pods.Items { + printObject(t, p) + } + + t.Logf(header, "Image logs") + for _, i := range images.Items { + err = logs.NewBuildLogsClient(clients.k8sClient).GetImageLogs(ctx, os.Stdout, i.Name, i.Namespace) + require.NoError(t, err) + } +}