Skip to content

Commit

Permalink
Merge pull request #1245 from pivotal/fix-e2e
Browse files Browse the repository at this point in the history
Fix e2e
  • Loading branch information
chenbh authored Jul 7, 2023
2 parents b323164 + d05ed73 commit a3edeb3
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 6 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 6 additions & 4 deletions test/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand Down
8 changes: 7 additions & 1 deletion test/execute_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{}

Expand Down Expand Up @@ -638,7 +645,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)

Expand Down
59 changes: 59 additions & 0 deletions test/testhelpers.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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)
}
}

0 comments on commit a3edeb3

Please sign in to comment.