From 895e69c72894db84ecacf7dfb345078e74ba01ca Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Fri, 24 May 2024 13:18:51 +0200 Subject: [PATCH 01/23] Make e2e tests work with local porch-server, but everything else in kind --- test/e2e/cli/cluster.go | 10 +-- test/e2e/e2e_test.go | 8 ++- test/e2e/e2e_test_utils.go | 4 +- test/e2e/suite.go | 121 +++++++++++++++++++------------------ 4 files changed, 76 insertions(+), 67 deletions(-) diff --git a/test/e2e/cli/cluster.go b/test/e2e/cli/cluster.go index 560fba78..bcbcb584 100644 --- a/test/e2e/cli/cluster.go +++ b/test/e2e/cli/cluster.go @@ -27,7 +27,7 @@ const ( ) func GetGitServerImageName(t *testing.T) string { - cmd := exec.Command("kubectl", "get", "pods", "--selector=app=porch-server", "--namespace=porch-system", + cmd := exec.Command("kubectl", "get", "pods", "--selector=app=function-runner", "--namespace=porch-system", "--output=jsonpath={.items[*].spec.containers[*].image}") var stderr bytes.Buffer @@ -204,10 +204,10 @@ func RemovePackagerevFinalizers(t *testing.T, namespace string) { } func realySplit(s, sep string) []string { - if len(s) == 0 { - return []string{} - } - return strings.Split(s, sep) + if len(s) == 0 { + return []string{} + } + return strings.Split(s, sep) } func RegisterRepository(t *testing.T, repoURL, namespace, name string) { diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 2e25cbbc..3e00a978 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -23,7 +23,7 @@ import ( "strings" "testing" "time" - + "github.com/google/go-cmp/cmp" porchapi "github.com/nephio-project/porch/api/porch/v1alpha1" configapi "github.com/nephio-project/porch/api/porchconfig/v1alpha1" @@ -1018,15 +1018,18 @@ func (t *PorchSuite) TestDeleteFinal(ctx context.Context) { t.mustExist(ctx, client.ObjectKey{Namespace: t.namespace, Name: created.Name}, &pkg) // Propose the package revision to be finalized + t.Log("Proposing package") pkg.Spec.Lifecycle = porchapi.PackageRevisionLifecycleProposed t.UpdateF(ctx, &pkg) + t.Log("Approving package") pkg.Spec.Lifecycle = porchapi.PackageRevisionLifecyclePublished t.UpdateApprovalF(ctx, &pkg, metav1.UpdateOptions{}) t.mustExist(ctx, client.ObjectKey{Namespace: t.namespace, Name: created.Name}, &pkg) // Try to delete the package. This should fail because it hasn't been proposed for deletion. + t.Log("Trying to delete package (should fail)") t.DeleteL(ctx, &porchapi.PackageRevision{ ObjectMeta: metav1.ObjectMeta{ Namespace: t.namespace, @@ -1036,9 +1039,11 @@ func (t *PorchSuite) TestDeleteFinal(ctx context.Context) { t.mustExist(ctx, client.ObjectKey{Namespace: t.namespace, Name: created.Name}, &pkg) // Propose deletion and then delete the package + t.Log("Proposing deletion of package") pkg.Spec.Lifecycle = porchapi.PackageRevisionLifecycleDeletionProposed t.UpdateApprovalF(ctx, &pkg, metav1.UpdateOptions{}) + t.Log("Deleting package") t.DeleteE(ctx, &porchapi.PackageRevision{ ObjectMeta: metav1.ObjectMeta{ Namespace: t.namespace, @@ -2380,4 +2385,3 @@ func (t *PorchSuite) TestPackageRevisionFinalizers(ctx context.Context) { Namespace: pr.Namespace, }, 10*time.Second) } - diff --git a/test/e2e/e2e_test_utils.go b/test/e2e/e2e_test_utils.go index 1786b2e4..d86a4187 100644 --- a/test/e2e/e2e_test_utils.go +++ b/test/e2e/e2e_test_utils.go @@ -17,8 +17,9 @@ package e2e import ( "context" "fmt" - "time" "strings" + "time" + "github.com/google/go-cmp/cmp" porchapi "github.com/nephio-project/porch/api/porch/v1alpha1" configapi "github.com/nephio-project/porch/api/porchconfig/v1alpha1" @@ -188,6 +189,7 @@ func (t *TestSuite) createPackageDraftF(ctx context.Context, repository, name, w } func (t *TestSuite) mustExist(ctx context.Context, key client.ObjectKey, obj client.Object) { + t.Logf("Checking existence of %q...", key) t.GetF(ctx, key, obj) if got, want := obj.GetName(), key.Name; got != want { t.Errorf("%T.Name: got %q, want %q", obj, got, want) diff --git a/test/e2e/suite.go b/test/e2e/suite.go index 68bac169..cf6aaf7b 100644 --- a/test/e2e/suite.go +++ b/test/e2e/suite.go @@ -44,7 +44,6 @@ import ( coreapi "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" @@ -167,32 +166,26 @@ func (t *TestSuite) IsUsingDevPorch() bool { Name: porch.Spec.Service.Name, }, &service) - return service.Spec.Type == coreapi.ServiceTypeExternalName && service.Spec.ExternalName == "host.docker.internal" + return len(service.Spec.Selector) == 0 } func (t *TestSuite) CreateGitRepo() GitConfig { - if t.IsUsingDevPorch() { - // Create Git server on the local machine. - t.Logf("using dev porch; creating local git server") - return createLocalGitServer(t.T) - } else { - // Deploy Git server via k8s client. - t.Logf("not using dev porch; creating git server in cluster") - return t.createInClusterGitServer(context.TODO()) - } + // Deploy Git server via k8s client. + t.Logf("creating git server in cluster") + return t.createInClusterGitServer(context.TODO(), t.IsUsingDevPorch()) } type ErrorHandler func(format string, args ...interface{}) func (t *TestSuite) get(ctx context.Context, key client.ObjectKey, obj client.Object, eh ErrorHandler) { if err := t.client.Get(ctx, key, obj); err != nil { - eh("failed to get resource %s %s/%s: %v", obj.GetObjectKind().GroupVersionKind(), key.Name, key.Namespace, err) + eh("failed to get resource %T %s: %v", obj, key, err) } } func (c *TestSuite) list(ctx context.Context, list client.ObjectList, opts []client.ListOption, eh ErrorHandler) { if err := c.client.List(ctx, list, opts...); err != nil { - eh("failed to list resources %s %+v: %v", list.GetObjectKind().GroupVersionKind(), list, err) + eh("failed to list resources %T %+v: %v", list, list, err) } } @@ -251,6 +244,7 @@ func (t *TestSuite) patch(ctx context.Context, obj client.Object, patch client.P } func (t *TestSuite) updateApproval(ctx context.Context, obj *porchapi.PackageRevision, opts metav1.UpdateOptions, eh ErrorHandler) *porchapi.PackageRevision { + t.Logf("updating approval of %v", DebugFormat(obj)) if res, err := t.clientset.PorchV1alpha1().PackageRevisions(obj.Namespace).UpdateApproval(ctx, obj.Name, obj, opts); err != nil { eh("failed to update approval of %s/%s: %v", obj.Namespace, obj.Name, err) return nil @@ -439,25 +433,30 @@ func createInitialCommit(t *testing.T, repo *gogit.Repository) { } } -func (t *TestSuite) createInClusterGitServer(ctx context.Context) GitConfig { +func (t *TestSuite) createInClusterGitServer(ctx context.Context, exposeByLoadBalancer bool) GitConfig { // Determine git-server image name. Use the same container registry and tag as the Porch server, // replacing base image name with `git-server`. TODO: Make configurable? var porch appsv1.Deployment t.GetF(ctx, client.ObjectKey{ Namespace: "porch-system", - Name: "porch-server", + Name: "function-runner", }, &porch) gitImage := porchtest.InferGitServerImage(porch.Spec.Template.Spec.Containers[0].Image) + var deploymentKey = client.ObjectKey{ + Namespace: t.namespace, + Name: "git-server", + } var replicas int32 = 1 - var selector = strings.ReplaceAll(t.Name(), "/", "_") - + var selector = map[string]string{ + "git-server": strings.ReplaceAll(t.Name(), "/", "_"), + } t.CreateF(ctx, &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ - Name: "git-server", - Namespace: t.namespace, + Name: deploymentKey.Name, + Namespace: deploymentKey.Namespace, Annotations: map[string]string{ "kpt.dev/porch-test": t.Name(), }, @@ -465,15 +464,11 @@ func (t *TestSuite) createInClusterGitServer(ctx context.Context) GitConfig { Spec: appsv1.DeploymentSpec{ Replicas: &replicas, Selector: &metav1.LabelSelector{ - MatchLabels: map[string]string{ - "git-server": selector, - }, + MatchLabels: selector, }, Template: coreapi.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ - Labels: map[string]string{ - "git-server": selector, - }, + Labels: selector, }, Spec: coreapi.PodSpec{ Containers: []coreapi.Container{ @@ -498,23 +493,24 @@ func (t *TestSuite) createInClusterGitServer(ctx context.Context) GitConfig { t.Cleanup(func() { t.DeleteE(ctx, &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ - Name: "git-server", - Namespace: t.namespace, + Name: deploymentKey.Name, + Namespace: deploymentKey.Namespace, }, }) }) t.Cleanup(func() { - t.DumpLogsForDeployment(ctx, types.NamespacedName{ - Name: "git-server", - Namespace: t.namespace, - }) + t.DumpLogsForDeployment(ctx, deploymentKey) }) - t.CreateF(ctx, &coreapi.Service{ + serviceKey := client.ObjectKey{ + Namespace: t.namespace, + Name: "git-server-service", + } + service := coreapi.Service{ ObjectMeta: metav1.ObjectMeta{ - Name: "git-server-service", - Namespace: t.namespace, + Name: serviceKey.Name, + Namespace: serviceKey.Namespace, Annotations: map[string]string{ "kpt.dev/porch-test": t.Name(), }, @@ -530,17 +526,19 @@ func (t *TestSuite) createInClusterGitServer(ctx context.Context) GitConfig { }, }, }, - Selector: map[string]string{ - "git-server": selector, - }, + Selector: selector, }, - }) + } + if exposeByLoadBalancer { + service.Spec.Type = coreapi.ServiceTypeLoadBalancer + } + t.CreateF(ctx, &service) t.Cleanup(func() { t.DeleteE(ctx, &coreapi.Service{ ObjectMeta: metav1.ObjectMeta{ - Name: "git-server-service", - Namespace: t.namespace, + Name: serviceKey.Name, + Namespace: serviceKey.Namespace, }, }) }) @@ -554,10 +552,7 @@ func (t *TestSuite) createInClusterGitServer(ctx context.Context) GitConfig { time.Sleep(5 * time.Second) var deployment appsv1.Deployment - t.GetF(ctx, client.ObjectKey{ - Namespace: t.namespace, - Name: "git-server", - }, &deployment) + t.GetF(ctx, deploymentKey, &deployment) ready := true if ready && deployment.Generation != deployment.Status.ObservedGeneration { @@ -600,31 +595,39 @@ func (t *TestSuite) createInClusterGitServer(ctx context.Context) GitConfig { t.Logf("Waiting for git-server-service to be ready ...") - // Check the Endpoint resource for readiness + // Check the Endpoint and Service resources for readiness + gitUrl := fmt.Sprintf("http://%s.%s.svc.cluster.local:8080", serviceKey.Name, serviceKey.Namespace) giveUp = time.Now().Add(time.Minute) - for { time.Sleep(5 * time.Second) + if time.Now().After(giveUp) { + t.Fatalf("git-server-service not ready on time") + return GitConfig{} + } var endpoint coreapi.Endpoints - err := t.client.Get(ctx, client.ObjectKey{ - Namespace: t.namespace, - Name: "git-server-service", - }, &endpoint) - - if err == nil && endpointIsReady(&endpoint) { - t.Logf("git-server-service is ready") - break + err := t.client.Get(ctx, serviceKey, &endpoint) + if err != nil || !endpointIsReady(&endpoint) { + t.Logf("waiting for Endpoint to be ready: %+v", endpoint) + continue } - - if time.Now().After(giveUp) { - t.Fatalf("git-server-service not ready on time: %s", &endpoint) - return GitConfig{} + if exposeByLoadBalancer { + var svc coreapi.Service + t.client.Get(ctx, serviceKey, &svc) + if len(svc.Status.LoadBalancer.Ingress) == 0 { + t.Logf("waiting for LoadBalancer to be assigned: %+v", svc) + continue + } + t.Logf("LoadBalancer IP was assigned to git-server-service: %s", svc.Status.LoadBalancer.Ingress[0].IP) + gitUrl = fmt.Sprintf("http://%s:8080", svc.Status.LoadBalancer.Ingress[0].IP) } + + t.Log("git-server-service is ready") + break } return GitConfig{ - Repo: fmt.Sprintf("http://git-server-service.%s.svc.cluster.local:8080", t.namespace), + Repo: gitUrl, Branch: "main", Directory: "/", } From 4ebe67588756a2415db0b7aefbbb89c579824e50 Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Sat, 25 May 2024 11:20:21 +0200 Subject: [PATCH 02/23] Various improvements to end-to-end testing capabilities - start with clean etcd for local tests - make some problematic test cases more verbose (and faster) - handle the new testing scenario, when everything is running in-cluster, but the porch-server (that is running locally) --- .vscode/launch.json | 31 +++++++++------ Makefile | 1 + deployments/local/porch-api-endpoints.yaml | 3 +- scripts/clean-kind-only-e2e-test.sh | 32 +++++++++++++++ test/e2e/e2e_test.go | 46 +++++++++++++--------- test/e2e/suite.go | 19 ++++++--- 6 files changed, 93 insertions(+), 39 deletions(-) create mode 100755 scripts/clean-kind-only-e2e-test.sh diff --git a/.vscode/launch.json b/.vscode/launch.json index 3ba8ce3f..d84da3c8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,17 +4,6 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ - { - "name": "Launch test function", - "type": "go", - "request": "launch", - "mode": "test", - "program": "${workspaceFolder}/apiserver/pkg/e2e", - "args": [ - "-test.run", - "TestE2E/PorchSuite/TestCloneIntoDeploymentRepository" - ] - }, { "name": "Launch Server", "type": "go", @@ -28,9 +17,27 @@ "--kubeconfig=${env:KUBECONFIG}", "--cache-directory=${workspaceFolder}/.cache", "--function-runner=172.18.255.201:9445", - "--repo-sync-frequency=60s" + "--repo-sync-frequency=60s", + // "--cert-dir=${workspaceFolder}/.build/pki/empty1", ], "cwd": "${workspaceFolder}", + "env": { + "CERT_STORAGE_DIR": "${workspaceFolder}/.build/pki/empty2", + "CERT_NAMESPACE": "porch-system" + } + }, + { + "name": "Launch test function", + "type": "go", + "request": "launch", + "mode": "test", + "program": "${workspaceFolder}/test/e2e", + "args": [ + "-test.v", + "-test.run", + "TestE2E/PorchSuite/TestDeleteFinal" + ], + "env": { "E2E": "1"} }, { "name": "Launch Func Client", diff --git a/Makefile b/Makefile index 7d7711ca..db538960 100644 --- a/Makefile +++ b/Makefile @@ -104,6 +104,7 @@ stop: .PHONY: start-etcd start-etcd: docker buildx build -t etcd --output=type=docker -f ./build/Dockerfile.etcd ./build + rm -rf $(BUILDDIR)/data/etcd || true mkdir -p $(BUILDDIR)/data/etcd docker stop etcd || true docker rm etcd || true diff --git a/deployments/local/porch-api-endpoints.yaml b/deployments/local/porch-api-endpoints.yaml index 98abbde6..e6723091 100644 --- a/deployments/local/porch-api-endpoints.yaml +++ b/deployments/local/porch-api-endpoints.yaml @@ -9,8 +9,7 @@ subsets: - addresses: - ip: 172.17.0.1 ports: - - appProtocol: https - name: api + - name: api port: 4443 protocol: TCP - name: webhooks diff --git a/scripts/clean-kind-only-e2e-test.sh b/scripts/clean-kind-only-e2e-test.sh new file mode 100755 index 00000000..681c777c --- /dev/null +++ b/scripts/clean-kind-only-e2e-test.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# Copyright 2022 The kpt and Nephio Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Stricter error handling +set -e # Exit on error +set -u # Must predefine variables +set -o pipefail # Check errors in piped commands + +PORCH_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" + +cd $PORCH_DIR + +kind delete cluster --name dev || true +kind create cluster --name dev +make run-in-kind-kpt IMAGE_TAG='test' KIND_CONTEXT_NAME='dev' KUBECONFIG=$KUBECONFIG +kubectl rollout status deployment porch-controllers --namespace porch-system +kubectl rollout status deployment porch-server --namespace porch-system +kubectl rollout status deployment function-runner --namespace porch-system +sleep 2 +E2E=1 go test -v ./test/e2e diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 3e00a978..2eb8e485 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -1198,7 +1198,7 @@ func (t *PorchSuite) TestDeleteFromMain(ctx context.Context) { // Register the repository t.registerMainGitRepositoryF(ctx, repository) - // Create the first draft package + t.Logf("Create and approve package: %s", packageNameFirst) createdFirst := t.createPackageDraftF(ctx, repository, packageNameFirst, workspace) // Check the package exists @@ -1214,7 +1214,7 @@ func (t *PorchSuite) TestDeleteFromMain(ctx context.Context) { t.mustExist(ctx, client.ObjectKey{Namespace: t.namespace, Name: createdFirst.Name}, &pkgFirst) - // Create the second draft package + t.Logf("Create and approve package: %s", packageNameSecond) createdSecond := t.createPackageDraftF(ctx, repository, packageNameSecond, workspace) // Check the package exists @@ -1230,31 +1230,38 @@ func (t *PorchSuite) TestDeleteFromMain(ctx context.Context) { t.mustExist(ctx, client.ObjectKey{Namespace: t.namespace, Name: createdSecond.Name}, &pkgSecond) - // We need to wait for the sync for the "main" revisions to get created - time.Sleep(75 * time.Second) - - var list porchapi.PackageRevisionList - t.ListE(ctx, &list, client.InNamespace(t.namespace)) - + t.Log("Wait for the 'main' revisions to get created") var firstPkgRevFromMain porchapi.PackageRevision var secondPkgRevFromMain porchapi.PackageRevision - - for _, pkgrev := range list.Items { - if pkgrev.Spec.PackageName == packageNameFirst && pkgrev.Spec.Revision == "main" { - firstPkgRevFromMain = pkgrev + var list porchapi.PackageRevisionList + finalDeadline := time.Now().Add(5 * time.Minute) + for firstPkgRevFromMain.Spec.WorkspaceName == "" || secondPkgRevFromMain.Spec.WorkspaceName == "" { + if time.Now().After(finalDeadline) { + t.Fatal("'main' package revisions not created in time") + return } - if pkgrev.Spec.PackageName == packageNameSecond && pkgrev.Spec.Revision == "main" { - secondPkgRevFromMain = pkgrev + time.Sleep(5 * time.Second) + + t.ListE(ctx, &list, client.InNamespace(t.namespace)) + for _, pkgrev := range list.Items { + if pkgrev.Spec.PackageName == packageNameFirst && pkgrev.Spec.Revision == "main" { + firstPkgRevFromMain = pkgrev + t.Logf("Found first package revision: %+v", firstPkgRevFromMain.Name) + } + if pkgrev.Spec.PackageName == packageNameSecond && pkgrev.Spec.Revision == "main" { + secondPkgRevFromMain = pkgrev + t.Logf("Found second package revision: %+v", secondPkgRevFromMain.Name) + } } } - // Propose deletion of both main packages + t.Log("Propose deletion of both main packages") firstPkgRevFromMain.Spec.Lifecycle = porchapi.PackageRevisionLifecycleDeletionProposed t.UpdateApprovalF(ctx, &firstPkgRevFromMain, metav1.UpdateOptions{}) secondPkgRevFromMain.Spec.Lifecycle = porchapi.PackageRevisionLifecycleDeletionProposed t.UpdateApprovalF(ctx, &secondPkgRevFromMain, metav1.UpdateOptions{}) - // Delete the first package revision from main + t.Log("Delete the first package revision from main") t.DeleteE(ctx, &porchapi.PackageRevision{ ObjectMeta: metav1.ObjectMeta{ Namespace: t.namespace, @@ -1262,10 +1269,10 @@ func (t *PorchSuite) TestDeleteFromMain(ctx context.Context) { }, }) - // We need to wait for the sync - time.Sleep(75 * time.Second) + // t.Log("Wait for the sync") + // time.Sleep(75 * time.Second) - // Delete the second package revision from main + t.Log("Delete the second package revision from main") t.DeleteE(ctx, &porchapi.PackageRevision{ ObjectMeta: metav1.ObjectMeta{ Namespace: t.namespace, @@ -1276,6 +1283,7 @@ func (t *PorchSuite) TestDeleteFromMain(ctx context.Context) { // Propose and delete the original package revisions (cleanup) t.ListE(ctx, &list, client.InNamespace(t.namespace)) for _, pkgrev := range list.Items { + t.Logf("Propose deletion and delete package revision: %s", pkgrev.Name) pkgrev.Spec.Lifecycle = porchapi.PackageRevisionLifecycleDeletionProposed t.UpdateApprovalF(ctx, &pkgrev, metav1.UpdateOptions{}) t.DeleteE(ctx, &porchapi.PackageRevision{ diff --git a/test/e2e/suite.go b/test/e2e/suite.go index cf6aaf7b..bee7f246 100644 --- a/test/e2e/suite.go +++ b/test/e2e/suite.go @@ -130,7 +130,7 @@ func (t *TestSuite) Initialize(ctx context.Context) { t.clientset = cs } - t.local = t.IsUsingDevPorch() + _, t.local = t.IsUsingDevPorch() namespace := fmt.Sprintf("porch-test-%d", time.Now().UnixMicro()) t.CreateF(ctx, &coreapi.Namespace{ @@ -154,7 +154,7 @@ func (t *TestSuite) Initialize(ctx context.Context) { }) } -func (t *TestSuite) IsUsingDevPorch() bool { +func (t *TestSuite) IsUsingDevPorch() (bool, bool) { porch := aggregatorv1.APIService{} ctx := context.TODO() t.GetF(ctx, client.ObjectKey{ @@ -166,13 +166,20 @@ func (t *TestSuite) IsUsingDevPorch() bool { Name: porch.Spec.Service.Name, }, &service) - return len(service.Spec.Selector) == 0 + isPorchLocal := len(service.Spec.Selector) == 0 + areAllLocal := service.Spec.Type == coreapi.ServiceTypeExternalName + return isPorchLocal, areAllLocal } func (t *TestSuite) CreateGitRepo() GitConfig { // Deploy Git server via k8s client. t.Logf("creating git server in cluster") - return t.createInClusterGitServer(context.TODO(), t.IsUsingDevPorch()) + isPorchLocal, areAllLocal := t.IsUsingDevPorch() + if areAllLocal { + return createLocalGitServer(t.T) + } else { + return t.createInClusterGitServer(context.TODO(), isPorchLocal) + } } type ErrorHandler func(format string, args ...interface{}) @@ -549,7 +556,7 @@ func (t *TestSuite) createInClusterGitServer(ctx context.Context, exposeByLoadBa giveUp := time.Now().Add(time.Minute) for { - time.Sleep(5 * time.Second) + time.Sleep(1 * time.Second) var deployment appsv1.Deployment t.GetF(ctx, deploymentKey, &deployment) @@ -599,7 +606,7 @@ func (t *TestSuite) createInClusterGitServer(ctx context.Context, exposeByLoadBa gitUrl := fmt.Sprintf("http://%s.%s.svc.cluster.local:8080", serviceKey.Name, serviceKey.Namespace) giveUp = time.Now().Add(time.Minute) for { - time.Sleep(5 * time.Second) + time.Sleep(1 * time.Second) if time.Now().After(giveUp) { t.Fatalf("git-server-service not ready on time") return GitConfig{} From 8601b023fe9f3a439aa86f7679f5e9ddd6974e27 Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Mon, 27 May 2024 09:29:37 +0200 Subject: [PATCH 03/23] Make validating webhook work with local porch-server --- .vscode/launch.json | 8 +++----- pkg/apiserver/webhooks.go | 2 +- pkg/cmd/server/start.go | 10 +++++++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index d84da3c8..7c1ea84b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,17 +12,15 @@ "program": "${workspaceFolder}/cmd/porch/main.go", "args": [ "--secure-port=4443", - "--v=7", - "--standalone-debug-mode", + // "--v=7", + // "--standalone-debug-mode", "--kubeconfig=${env:KUBECONFIG}", - "--cache-directory=${workspaceFolder}/.cache", "--function-runner=172.18.255.201:9445", "--repo-sync-frequency=60s", - // "--cert-dir=${workspaceFolder}/.build/pki/empty1", ], "cwd": "${workspaceFolder}", "env": { - "CERT_STORAGE_DIR": "${workspaceFolder}/.build/pki/empty2", + "CERT_STORAGE_DIR": "${workspaceFolder}/.build/pki/tmp", "CERT_NAMESPACE": "porch-system" } }, diff --git a/pkg/apiserver/webhooks.go b/pkg/apiserver/webhooks.go index 709853ed..b2735b85 100644 --- a/pkg/apiserver/webhooks.go +++ b/pkg/apiserver/webhooks.go @@ -134,7 +134,7 @@ func createCerts(webhookNs string, certStorageDir string) ([]byte, error) { Bytes: x509.MarshalPKCS1PrivateKey(serverPrivateKey), }) - err = os.MkdirAll(certStorageDir, 0666) + err = os.MkdirAll(certStorageDir, 0777) if err != nil { return nil, err } diff --git a/pkg/cmd/server/start.go b/pkg/cmd/server/start.go index 599195d1..4eb3634f 100644 --- a/pkg/cmd/server/start.go +++ b/pkg/cmd/server/start.go @@ -43,8 +43,8 @@ import ( const ( defaultEtcdPathPrefix = "/registry/porch.kpt.dev" - OpenAPITitle = "Porch" - OpenAPIVersion = "0.1" + OpenAPITitle = "Porch" + OpenAPIVersion = "0.1" ) // PorchServerOptions contains state for master/api server @@ -132,6 +132,10 @@ func (o *PorchServerOptions) Complete() error { o.RecommendedOptions.Admission = nil o.RecommendedOptions.Authentication.RemoteKubeConfigFileOptional = true } + } else { + // This is needed in case the porch-server runs outside of the cluster, but without the --standalone-debug-mode flag. + o.RecommendedOptions.Authentication.RemoteKubeConfigFile = o.CoreAPIKubeconfigPath + o.RecommendedOptions.Authorization.RemoteKubeConfigFile = o.CoreAPIKubeconfigPath } if o.CacheDirectory == "" { @@ -169,7 +173,7 @@ func (o *PorchServerOptions) Config() (*apiserver.Config, error) { } serverConfig := genericapiserver.NewRecommendedConfig(apiserver.Codecs) - + serverConfig.OpenAPIConfig = genericapiserver.DefaultOpenAPIConfig(sampleopenapi.GetOpenAPIDefinitions, openapi.NewDefinitionNamer(apiserver.Scheme)) serverConfig.OpenAPIConfig.Info.Title = OpenAPITitle serverConfig.OpenAPIConfig.Info.Version = OpenAPIVersion From 5e6b1ca0baab21b72a86e778dcc95f86705aee4a Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Mon, 27 May 2024 17:21:26 +0200 Subject: [PATCH 04/23] Fix kpt repo url in e2e tests --- .vscode/launch.json | 2 +- test/e2e/e2e_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 7c1ea84b..39bddca4 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -33,7 +33,7 @@ "args": [ "-test.v", "-test.run", - "TestE2E/PorchSuite/TestDeleteFinal" + "TestE2E/PorchSuite/TestGitRepositoryWithReleaseTagsAndDirectory" ], "env": { "E2E": "1"} }, diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 2eb8e485..fa2891bf 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -41,7 +41,7 @@ import ( const ( testBlueprintsRepo = "https://github.com/platkrm/test-blueprints.git" - kptRepo = "https://github.com/GoogleContainerTools/kpt.git" + kptRepo = "https://github.com/kptdev/kpt.git" ) var ( From bd3a7bba64cb59053e6f96a1cc2c5815323885c3 Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Mon, 27 May 2024 18:13:57 +0200 Subject: [PATCH 05/23] Fix create-deployment-kpt.sh: only manipulate the 'porch-controllers' Deployment resource, as opposed to all resources in the 9-controllers.yaml file --- scripts/create-deployment-kpt.sh | 34 ++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/scripts/create-deployment-kpt.sh b/scripts/create-deployment-kpt.sh index 31fbeaeb..149f959f 100755 --- a/scripts/create-deployment-kpt.sh +++ b/scripts/create-deployment-kpt.sh @@ -126,22 +126,25 @@ function load-custom-images { } function main() { - + echo "Loading images into kind cluster ${KIND_CONTEXT_NAME}..." load-custom-images + echo "Preparing porch kpt package in ${DESTINATION}..." + rm -rf ${DESTINATION}/porch || true kpt pkg get https://github.com/nephio-project/catalog/tree/main/nephio/core/porch ${DESTINATION} - - yq -i eval 'del(.spec.template.spec.containers[0].env)' "${DESTINATION}/porch/9-controllers.yaml" - yq -i eval '.spec.template.spec.containers[0].env = []' "${DESTINATION}/porch/9-controllers.yaml" - - IFS=',' read -ra RECONCILERS <<< "$ENABLED_RECONCILERS" - for i in "${RECONCILERS[@]}"; do - # Update the porch-controllers Deployment env variables to enable the reconciler. - RECONCILER_ENV_VAR="ENABLE_$(echo "$i" | tr '[:lower:]' '[:upper:]')" - reconciler="$RECONCILER_ENV_VAR" \ - yq -i eval '.spec.template.spec.containers[0].env += {"name": env(reconciler), "value": "true"}' \ - "${DESTINATION}/porch/9-controllers.yaml" - done + kpt fn eval ${DESTINATION}/porch \ + --image gcr.io/kpt-fn/starlark:v0.5.0 \ + --match-kind Deployment \ + --match-name porch-controllers \ + --match-namespace porch-system \ + -- "reconcilers=$ENABLED_RECONCILERS" 'source= +reconcilers = ctx.resource_list["functionConfig"]["data"]["reconcilers"].split(",") +for resource in ctx.resource_list["items"]: + c = resource["spec"]["template"]["spec"]["containers"][0] + c["env"] = [] + for r in reconcilers: + c["env"].append({"name": "ENABLE_" + r.upper(), "value": "true"}) +' customize-pkg-images \ "porch-server:v2.0.0" \ @@ -159,7 +162,12 @@ function main() { "porch-wrapper-server:v2.0.0" \ "${WRAPPER_SERVER_IMAGE}" + echo "Deploying porch with newly built images..." deploy-porch-dev-pkg + + echo + echo Done. + echo } validate From 96f8612beab8eb247f494af6e74b9d45b7b5ea9c Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Mon, 27 May 2024 18:34:21 +0200 Subject: [PATCH 06/23] Fix test/e2e/cli bug --- scripts/clean-kind-only-e2e-test.sh | 6 +++++- test/e2e/cli/cluster.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/clean-kind-only-e2e-test.sh b/scripts/clean-kind-only-e2e-test.sh index 681c777c..cc4a587f 100755 --- a/scripts/clean-kind-only-e2e-test.sh +++ b/scripts/clean-kind-only-e2e-test.sh @@ -29,4 +29,8 @@ kubectl rollout status deployment porch-controllers --namespace porch-system kubectl rollout status deployment porch-server --namespace porch-system kubectl rollout status deployment function-runner --namespace porch-system sleep 2 -E2E=1 go test -v ./test/e2e + +echo "--- test/e2e ---" +E2E=1 go test -failfast -v ./test/e2e +echo "--- test/e2e/cli ---" +E2E=1 go test -failfast -v ./test/e2e/cli diff --git a/test/e2e/cli/cluster.go b/test/e2e/cli/cluster.go index bcbcb584..5dec0279 100644 --- a/test/e2e/cli/cluster.go +++ b/test/e2e/cli/cluster.go @@ -28,7 +28,7 @@ const ( func GetGitServerImageName(t *testing.T) string { cmd := exec.Command("kubectl", "get", "pods", "--selector=app=function-runner", "--namespace=porch-system", - "--output=jsonpath={.items[*].spec.containers[*].image}") + "--output=jsonpath={.items[0].spec.containers[0].image}") var stderr bytes.Buffer var stdout bytes.Buffer From 1a380be4c5ccc1e3c8c1c8d02a17e9a3997734b9 Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Tue, 28 May 2024 00:21:00 +0200 Subject: [PATCH 07/23] Make git server for CLI tests accessible from local host --- test/e2e/cli/testdata/git-server.yaml | 3 +++ test/e2e/cli/testdata/rpkg-clone/config.yaml | 2 +- test/e2e/cli/testdata/rpkg-copy/config.yaml | 2 +- test/e2e/cli/testdata/rpkg-init-deploy/config.yaml | 4 ++-- test/e2e/cli/testdata/rpkg-init/config.yaml | 4 ++-- test/e2e/cli/testdata/rpkg-lifecycle/config.yaml | 2 +- test/e2e/cli/testdata/rpkg-push/config.yaml | 2 +- test/e2e/cli/testdata/rpkg-update/config.yaml | 2 +- 8 files changed, 12 insertions(+), 9 deletions(-) diff --git a/test/e2e/cli/testdata/git-server.yaml b/test/e2e/cli/testdata/git-server.yaml index 78f15803..45c71716 100644 --- a/test/e2e/cli/testdata/git-server.yaml +++ b/test/e2e/cli/testdata/git-server.yaml @@ -30,7 +30,10 @@ kind: Service metadata: name: git-server namespace: test-git-namespace + annotations: + metallb.universe.tf/loadBalancerIPs: "172.18.255.203" spec: + type: LoadBalancer selector: app: git-server ports: diff --git a/test/e2e/cli/testdata/rpkg-clone/config.yaml b/test/e2e/cli/testdata/rpkg-clone/config.yaml index b169c580..9cd42972 100644 --- a/test/e2e/cli/testdata/rpkg-clone/config.yaml +++ b/test/e2e/cli/testdata/rpkg-clone/config.yaml @@ -5,7 +5,7 @@ commands: - register - --namespace=rpkg-clone - --name=git - - http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-clone + - http://172.18.255.203:8080/rpkg-clone - args: - porchctl - rpkg diff --git a/test/e2e/cli/testdata/rpkg-copy/config.yaml b/test/e2e/cli/testdata/rpkg-copy/config.yaml index 5e90830c..24e4512f 100644 --- a/test/e2e/cli/testdata/rpkg-copy/config.yaml +++ b/test/e2e/cli/testdata/rpkg-copy/config.yaml @@ -5,7 +5,7 @@ commands: - register - --namespace=rpkg-copy - --name=git - - http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-copy + - http://172.18.255.203:8080/rpkg-copy - args: - porchctl - rpkg diff --git a/test/e2e/cli/testdata/rpkg-init-deploy/config.yaml b/test/e2e/cli/testdata/rpkg-init-deploy/config.yaml index 82f091dc..db03e9aa 100644 --- a/test/e2e/cli/testdata/rpkg-init-deploy/config.yaml +++ b/test/e2e/cli/testdata/rpkg-init-deploy/config.yaml @@ -6,7 +6,7 @@ commands: - --namespace=rpkg-init-deploy - --name=git - --deployment - - http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-init-deploy + - http://172.18.255.203:8080/rpkg-init-deploy - args: - porchctl - repo @@ -87,4 +87,4 @@ commands: - --namespace=rpkg-init-deploy stdout: | NAME TYPE CONTENT DEPLOYMENT READY ADDRESS - git git Package true True http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-init-deploy + git git Package true True http://172.18.255.203:8080/rpkg-init-deploy diff --git a/test/e2e/cli/testdata/rpkg-init/config.yaml b/test/e2e/cli/testdata/rpkg-init/config.yaml index 46354cdb..1d9837fb 100644 --- a/test/e2e/cli/testdata/rpkg-init/config.yaml +++ b/test/e2e/cli/testdata/rpkg-init/config.yaml @@ -5,7 +5,7 @@ commands: - register - --namespace=rpkg-init - --name=git - - http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-init + - http://172.18.255.203:8080/rpkg-init - args: - porchctl - repo @@ -14,7 +14,7 @@ commands: - --output=custom-columns=NAME:.metadata.name,ADDRESS:.spec.git.repo,BRANCH:.spec.git.branch,DIR:.spec.git.directory stdout: | NAME ADDRESS BRANCH DIR - git http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-init main / + git http://172.18.255.203:8080/rpkg-init main / - args: - porchctl - rpkg diff --git a/test/e2e/cli/testdata/rpkg-lifecycle/config.yaml b/test/e2e/cli/testdata/rpkg-lifecycle/config.yaml index d560517f..cce16d7d 100644 --- a/test/e2e/cli/testdata/rpkg-lifecycle/config.yaml +++ b/test/e2e/cli/testdata/rpkg-lifecycle/config.yaml @@ -5,7 +5,7 @@ commands: - register - --namespace=rpkg-lifecycle - --name=git - - http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-lifecycle + - http://172.18.255.203:8080/rpkg-lifecycle - args: - porchctl - rpkg diff --git a/test/e2e/cli/testdata/rpkg-push/config.yaml b/test/e2e/cli/testdata/rpkg-push/config.yaml index 2effb864..5666b314 100644 --- a/test/e2e/cli/testdata/rpkg-push/config.yaml +++ b/test/e2e/cli/testdata/rpkg-push/config.yaml @@ -5,7 +5,7 @@ commands: - register - --namespace=rpkg-push - --name=git - - http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-push + - http://172.18.255.203:8080/rpkg-push - args: - porchctl - rpkg diff --git a/test/e2e/cli/testdata/rpkg-update/config.yaml b/test/e2e/cli/testdata/rpkg-update/config.yaml index 67158872..b795875c 100644 --- a/test/e2e/cli/testdata/rpkg-update/config.yaml +++ b/test/e2e/cli/testdata/rpkg-update/config.yaml @@ -5,7 +5,7 @@ commands: - register - --namespace=rpkg-update - --name=git - - http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-update + - http://172.18.255.203:8080/rpkg-update - args: - porchctl - rpkg From 01900eb9d608bb4925a0ea08f42ffa9562e18302 Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Tue, 28 May 2024 00:28:05 +0200 Subject: [PATCH 08/23] Update e2e-test/cli golden output --- test/e2e/cli/testdata/rpkg-init/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/cli/testdata/rpkg-init/config.yaml b/test/e2e/cli/testdata/rpkg-init/config.yaml index 1d9837fb..ec64656d 100644 --- a/test/e2e/cli/testdata/rpkg-init/config.yaml +++ b/test/e2e/cli/testdata/rpkg-init/config.yaml @@ -13,7 +13,7 @@ commands: - --namespace=rpkg-init - --output=custom-columns=NAME:.metadata.name,ADDRESS:.spec.git.repo,BRANCH:.spec.git.branch,DIR:.spec.git.directory stdout: | - NAME ADDRESS BRANCH DIR + NAME ADDRESS BRANCH DIR git http://172.18.255.203:8080/rpkg-init main / - args: - porchctl From 923d65300176ade0eb387ff56dd97f29e281a0c3 Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Tue, 28 May 2024 00:51:12 +0200 Subject: [PATCH 09/23] Separate e2e CLI tests for local porch server --- test/e2e/cli/cli_test.go | 9 +- .../cli/testdata-local-server/git-server.yaml | 42 ++++ .../repo-register/config.yaml | 46 ++++ .../rpkg-clone/config.yaml | 158 ++++++++++++++ .../rpkg-copy/config.yaml | 99 +++++++++ .../rpkg-get/config.yaml | 44 ++++ .../rpkg-init-deploy/config.yaml | 90 ++++++++ .../rpkg-init/config.yaml | 91 ++++++++ .../rpkg-lifecycle/config.yaml | 205 ++++++++++++++++++ .../rpkg-push/config.yaml | 185 ++++++++++++++++ .../rpkg-update/config.yaml | 150 +++++++++++++ test/e2e/cli/testdata/git-server.yaml | 3 - test/e2e/cli/testdata/rpkg-clone/config.yaml | 2 +- test/e2e/cli/testdata/rpkg-copy/config.yaml | 2 +- .../cli/testdata/rpkg-init-deploy/config.yaml | 4 +- test/e2e/cli/testdata/rpkg-init/config.yaml | 6 +- .../cli/testdata/rpkg-lifecycle/config.yaml | 2 +- test/e2e/cli/testdata/rpkg-push/config.yaml | 2 +- test/e2e/cli/testdata/rpkg-update/config.yaml | 2 +- 19 files changed, 1128 insertions(+), 14 deletions(-) create mode 100644 test/e2e/cli/testdata-local-server/git-server.yaml create mode 100644 test/e2e/cli/testdata-local-server/repo-register/config.yaml create mode 100644 test/e2e/cli/testdata-local-server/rpkg-clone/config.yaml create mode 100644 test/e2e/cli/testdata-local-server/rpkg-copy/config.yaml create mode 100644 test/e2e/cli/testdata-local-server/rpkg-get/config.yaml create mode 100644 test/e2e/cli/testdata-local-server/rpkg-init-deploy/config.yaml create mode 100644 test/e2e/cli/testdata-local-server/rpkg-init/config.yaml create mode 100644 test/e2e/cli/testdata-local-server/rpkg-lifecycle/config.yaml create mode 100644 test/e2e/cli/testdata-local-server/rpkg-push/config.yaml create mode 100644 test/e2e/cli/testdata-local-server/rpkg-update/config.yaml diff --git a/test/e2e/cli/cli_test.go b/test/e2e/cli/cli_test.go index 264513c4..9c529357 100644 --- a/test/e2e/cli/cli_test.go +++ b/test/e2e/cli/cli_test.go @@ -41,7 +41,14 @@ func TestPorch(t *testing.T) { t.Skip("set E2E to run this test") } - abs, err := filepath.Abs(filepath.Join(".", "testdata")) + var testdataDir string + if e2e == "local-server" { + testdataDir = "testdata-local-server" + } else { + testdataDir = "testdata" + } + + abs, err := filepath.Abs(filepath.Join(".", testdataDir)) if err != nil { t.Fatalf("Failed to get absolute path to testdata directory: %v", err) } diff --git a/test/e2e/cli/testdata-local-server/git-server.yaml b/test/e2e/cli/testdata-local-server/git-server.yaml new file mode 100644 index 00000000..45c71716 --- /dev/null +++ b/test/e2e/cli/testdata-local-server/git-server.yaml @@ -0,0 +1,42 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: test-git-namespace +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: git-server + namespace: test-git-namespace +spec: + replicas: 1 + selector: + matchLabels: + app: git-server + template: + metadata: + labels: + app: git-server + spec: + containers: + - name: git-server + image: GIT_SERVER_IMAGE + ports: + - containerPort: 8080 + protocol: TCP +--- +apiVersion: v1 +kind: Service +metadata: + name: git-server + namespace: test-git-namespace + annotations: + metallb.universe.tf/loadBalancerIPs: "172.18.255.203" +spec: + type: LoadBalancer + selector: + app: git-server + ports: + - protocol: TCP + port: 8080 + targetPort: 8080 diff --git a/test/e2e/cli/testdata-local-server/repo-register/config.yaml b/test/e2e/cli/testdata-local-server/repo-register/config.yaml new file mode 100644 index 00000000..95f1eea2 --- /dev/null +++ b/test/e2e/cli/testdata-local-server/repo-register/config.yaml @@ -0,0 +1,46 @@ +commands: + - args: + - porchctl + - repo + - register + - https://github.com/platkrm/test-blueprints.git + - --namespace=repo-register + - --description + - Test Blueprints + - args: + - porchctl + - repo + - get + - --namespace=repo-register + - --output=custom-columns=NAME:.metadata.name,ADDRESS:.spec.git.repo,BRANCH:.spec.git.branch,DIR:.spec.git.directory + stdout: | + NAME ADDRESS BRANCH DIR + test-blueprints https://github.com/platkrm/test-blueprints.git main / + - args: + - porchctl + - repo + - get + - --namespace=repo-register + - --output=custom-columns=NAME:.metadata.name,CONTENT:.spec.content,DESC:.spec.description + stdout: | + NAME CONTENT DESC + test-blueprints Package Test Blueprints + - args: + - porchctl + - repo + - get + - --namespace=repo-register + stdout: | + NAME TYPE CONTENT DEPLOYMENT READY ADDRESS + test-blueprints git Package True https://github.com/platkrm/test-blueprints.git + - args: + - porchctl + - repo + - unregister + - --namespace=repo-register + - test-blueprints + - args: + - porchctl + - repo + - get + - --namespace=repo-register diff --git a/test/e2e/cli/testdata-local-server/rpkg-clone/config.yaml b/test/e2e/cli/testdata-local-server/rpkg-clone/config.yaml new file mode 100644 index 00000000..9cd42972 --- /dev/null +++ b/test/e2e/cli/testdata-local-server/rpkg-clone/config.yaml @@ -0,0 +1,158 @@ +commands: + - args: + - porchctl + - repo + - register + - --namespace=rpkg-clone + - --name=git + - http://172.18.255.203:8080/rpkg-clone + - args: + - porchctl + - rpkg + - clone + - --namespace=rpkg-clone + - https://github.com/platkrm/test-blueprints.git/basens@basens/v1 + - --repository=git + - --workspace=clone-2 + - basens-clone + stdout: "git-3465eed5831e5c372243d048631c8ef1666b47d6 created\n" + - args: + - porchctl + - rpkg + - clone + - --namespace=rpkg-clone + - https://github.com/platkrm/test-blueprints.git/basens@basens/v1 + - --repository=git + - --workspace=clone-3 + - basens-clone + stderr: "error: `clone` cannot create a new revision for package \"basens-clone\" that already exists in repo \"git\"; make subsequent revisions using `copy`\n" + exitCode: 1 + - args: + - porchctl + - repo + - register + - https://github.com/platkrm/test-blueprints.git + - --namespace=rpkg-clone + - args: + - porchctl + - rpkg + - get + - --namespace=rpkg-clone + - --name=empty + - --revision=v1 + - --output=jsonpath={.metadata.name} + stdout: test-blueprints-e78ee77d9560703561c2656c97c77e9abb8c4c53 + - args: + - porchctl + - rpkg + - clone + - --namespace=rpkg-clone + - test-blueprints-e78ee77d9560703561c2656c97c77e9abb8c4c53 + - --repository=git + - --workspace=clone-1 + - empty-clone + stdout: "git-b67f9ce14d378317ba83c9504eab9cc024932dd3 created\n" + - args: + - porchctl + - rpkg + - pull + - --namespace=rpkg-clone + - git-3465eed5831e5c372243d048631c8ef1666b47d6 + stdout: | + apiVersion: config.kubernetes.io/v1 + items: + - apiVersion: "" + kind: KptRevisionMetadata + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/path: .KptRevisionMetadata + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: .KptRevisionMetadata + name: git-3465eed5831e5c372243d048631c8ef1666b47d6 + namespace: rpkg-clone + uid: uid:basens-clone:clone-2 + - apiVersion: kpt.dev/v1 + info: + description: sample description + kind: Kptfile + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/path: Kptfile + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: Kptfile + internal.kpt.dev/upstream-identifier: kpt.dev|Kptfile|default|basens-clone + name: basens-clone + upstream: + git: + directory: basens + ref: basens/v1 + repo: https://github.com/platkrm/test-blueprints.git + type: git + upstreamLock: + git: + commit: 67f29546028f0a48c6bbb08614934d0e070cdd3a + directory: basens + ref: basens/v1 + repo: https://github.com/platkrm/test-blueprints.git + type: git + - apiVersion: v1 + kind: Namespace + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/path: namespace.yaml + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: namespace.yaml + internal.kpt.dev/upstream-identifier: '|Namespace|default|example' + name: example + kind: ResourceList + yaml: true + - args: + - porchctl + - rpkg + - pull + - --namespace=rpkg-clone + - git-b67f9ce14d378317ba83c9504eab9cc024932dd3 + stdout: | + apiVersion: config.kubernetes.io/v1 + items: + - apiVersion: "" + kind: KptRevisionMetadata + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/path: .KptRevisionMetadata + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: .KptRevisionMetadata + name: git-b67f9ce14d378317ba83c9504eab9cc024932dd3 + namespace: rpkg-clone + uid: uid:empty-clone:clone-1 + - apiVersion: kpt.dev/v1 + info: + description: Empty Blueprint + kind: Kptfile + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/path: Kptfile + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: Kptfile + internal.kpt.dev/upstream-identifier: kpt.dev|Kptfile|default|empty-clone + name: empty-clone + upstream: + git: + directory: empty + ref: empty/v1 + repo: https://github.com/platkrm/test-blueprints.git + type: git + upstreamLock: + git: + commit: 3de8635354eda8e7de756494a4e0eb5c12af01ab + directory: empty + ref: empty/v1 + repo: https://github.com/platkrm/test-blueprints.git + type: git + kind: ResourceList + yaml: true diff --git a/test/e2e/cli/testdata-local-server/rpkg-copy/config.yaml b/test/e2e/cli/testdata-local-server/rpkg-copy/config.yaml new file mode 100644 index 00000000..24e4512f --- /dev/null +++ b/test/e2e/cli/testdata-local-server/rpkg-copy/config.yaml @@ -0,0 +1,99 @@ +commands: + - args: + - porchctl + - repo + - register + - --namespace=rpkg-copy + - --name=git + - http://172.18.255.203:8080/rpkg-copy + - args: + - porchctl + - rpkg + - clone + - --namespace=rpkg-copy + - https://github.com/platkrm/test-blueprints.git + - --directory=basens + - --ref=basens/v1 + - --repository=git + - --workspace=copy-1 + - basens-edit + stdout: "git-eb5afe755bedd142f142c6a9363649c667ef77a5 created\n" + - args: + - porchctl + - rpkg + - propose + - --namespace=rpkg-copy + - git-eb5afe755bedd142f142c6a9363649c667ef77a5 + stdout: "git-eb5afe755bedd142f142c6a9363649c667ef77a5 proposed\n" + - args: + - porchctl + - rpkg + - approve + - --namespace=rpkg-copy + - git-eb5afe755bedd142f142c6a9363649c667ef77a5 + stdout: "git-eb5afe755bedd142f142c6a9363649c667ef77a5 approved\n" + - args: + - porchctl + - rpkg + - copy + - --namespace=rpkg-copy + - --workspace=copy-2 + - git-eb5afe755bedd142f142c6a9363649c667ef77a5 + stdout: "git-a29df72d1135fd010ea49f4d4877001dee423be6 created\n" + - args: + - porchctl + - rpkg + - pull + - --namespace=rpkg-copy + - git-a29df72d1135fd010ea49f4d4877001dee423be6 + stdout: | + apiVersion: config.kubernetes.io/v1 + items: + - apiVersion: "" + kind: KptRevisionMetadata + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/path: .KptRevisionMetadata + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: .KptRevisionMetadata + name: git-a29df72d1135fd010ea49f4d4877001dee423be6 + namespace: rpkg-copy + uid: uid:basens-edit:copy-2 + - apiVersion: kpt.dev/v1 + info: + description: sample description + kind: Kptfile + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/path: Kptfile + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: Kptfile + internal.kpt.dev/upstream-identifier: kpt.dev|Kptfile|default|basens-edit + name: basens-edit + upstream: + git: + directory: basens + ref: basens/v1 + repo: https://github.com/platkrm/test-blueprints.git + type: git + upstreamLock: + git: + commit: 67f29546028f0a48c6bbb08614934d0e070cdd3a + directory: basens + ref: basens/v1 + repo: https://github.com/platkrm/test-blueprints.git + type: git + - apiVersion: v1 + kind: Namespace + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/path: namespace.yaml + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: namespace.yaml + internal.kpt.dev/upstream-identifier: '|Namespace|default|example' + name: example + kind: ResourceList + yaml: true diff --git a/test/e2e/cli/testdata-local-server/rpkg-get/config.yaml b/test/e2e/cli/testdata-local-server/rpkg-get/config.yaml new file mode 100644 index 00000000..c62ff142 --- /dev/null +++ b/test/e2e/cli/testdata-local-server/rpkg-get/config.yaml @@ -0,0 +1,44 @@ +commands: + - args: + - porchctl + - repo + - register + - https://github.com/platkrm/test-blueprints.git + - --namespace=rpkg-get + - --description + - Test Blueprints + - args: + - porchctl + - rpkg + - get + - --namespace=rpkg-get + - --output=custom-columns=NAME:.metadata.name,PKG:.spec.packageName,REPO:.spec.repository,REV:.spec.revision + stdout: | + NAME PKG REPO REV + test-blueprints-9626794e984ff13c9a4c64df5af0f15ec3a146bf basens test-blueprints main + test-blueprints-526fa27229adcc3b6a9a544c455c344a3b4d7597 basens test-blueprints v1 + test-blueprints-499689d1e0c6fced058158330d922c004367d6cd basens test-blueprints v2 + test-blueprints-913ab85d2d49621636a0ffa514a2a008e6a7012e basens test-blueprints v3 + test-blueprints-58fffeb908ead18e2c05c873e61bff11a5292963 empty test-blueprints main + test-blueprints-e78ee77d9560703561c2656c97c77e9abb8c4c53 empty test-blueprints v1 + - args: + - porchctl + - rpkg + - get + - --namespace=rpkg-get + - test-blueprints-526fa27229adcc3b6a9a544c455c344a3b4d7597 + stdout: | + NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY + test-blueprints-526fa27229adcc3b6a9a544c455c344a3b4d7597 basens v1 v1 false Published test-blueprints + - args: + - porchctl + - rpkg + - get + - --namespace=rpkg-get + - --name=basens + stdout: | + NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY + test-blueprints-9626794e984ff13c9a4c64df5af0f15ec3a146bf basens main main false Published test-blueprints + test-blueprints-526fa27229adcc3b6a9a544c455c344a3b4d7597 basens v1 v1 false Published test-blueprints + test-blueprints-499689d1e0c6fced058158330d922c004367d6cd basens v2 v2 false Published test-blueprints + test-blueprints-913ab85d2d49621636a0ffa514a2a008e6a7012e basens v3 v3 true Published test-blueprints diff --git a/test/e2e/cli/testdata-local-server/rpkg-init-deploy/config.yaml b/test/e2e/cli/testdata-local-server/rpkg-init-deploy/config.yaml new file mode 100644 index 00000000..db03e9aa --- /dev/null +++ b/test/e2e/cli/testdata-local-server/rpkg-init-deploy/config.yaml @@ -0,0 +1,90 @@ +commands: + - args: + - porchctl + - repo + - register + - --namespace=rpkg-init-deploy + - --name=git + - --deployment + - http://172.18.255.203:8080/rpkg-init-deploy + - args: + - porchctl + - repo + - get + - --namespace=rpkg-init-deploy + - --output=custom-columns=NAME:.metadata.name,DEPLOYMENT:.spec.deployment + stdout: | + NAME DEPLOYMENT + git true + - args: + - porchctl + - rpkg + - init + - --namespace=rpkg-init-deploy + - --description + - Test Package Description + - --keywords=test,package + - --site + - http://kpt.dev/deploy-package + - --repository=git + - --workspace=deploy + - deploy-package + stdout: "git-628abd0a0903f5de6cb3604d917724f6fc1b5e08 created\n" + - args: + - porchctl + - rpkg + - pull + - --namespace=rpkg-init-deploy + - git-628abd0a0903f5de6cb3604d917724f6fc1b5e08 + stdout: | + apiVersion: config.kubernetes.io/v1 + items: + - apiVersion: "" + kind: KptRevisionMetadata + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/path: .KptRevisionMetadata + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: .KptRevisionMetadata + name: git-628abd0a0903f5de6cb3604d917724f6fc1b5e08 + namespace: rpkg-init-deploy + uid: uid:deploy-package:deploy + - apiVersion: kpt.dev/v1 + info: + description: Test Package Description + keywords: + - test + - package + site: http://kpt.dev/deploy-package + kind: Kptfile + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/local-config: "true" + config.kubernetes.io/path: Kptfile + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: Kptfile + name: deploy-package + - apiVersion: v1 + data: + name: example + kind: ConfigMap + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/local-config: "true" + config.kubernetes.io/path: package-context.yaml + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: package-context.yaml + name: kptfile.kpt.dev + kind: ResourceList + yaml: true + - args: + - porchctl + - repo + - get + - --namespace=rpkg-init-deploy + stdout: | + NAME TYPE CONTENT DEPLOYMENT READY ADDRESS + git git Package true True http://172.18.255.203:8080/rpkg-init-deploy diff --git a/test/e2e/cli/testdata-local-server/rpkg-init/config.yaml b/test/e2e/cli/testdata-local-server/rpkg-init/config.yaml new file mode 100644 index 00000000..ec64656d --- /dev/null +++ b/test/e2e/cli/testdata-local-server/rpkg-init/config.yaml @@ -0,0 +1,91 @@ +commands: + - args: + - porchctl + - repo + - register + - --namespace=rpkg-init + - --name=git + - http://172.18.255.203:8080/rpkg-init + - args: + - porchctl + - repo + - get + - --namespace=rpkg-init + - --output=custom-columns=NAME:.metadata.name,ADDRESS:.spec.git.repo,BRANCH:.spec.git.branch,DIR:.spec.git.directory + stdout: | + NAME ADDRESS BRANCH DIR + git http://172.18.255.203:8080/rpkg-init main / + - args: + - porchctl + - rpkg + - init + - --namespace=rpkg-init + - --description + - Test Package Description + - --keywords=test,package + - --site + - http://kpt.dev/init-package + - --repository=git + - --workspace=init-1 + - init-package + stdout: "git-95686470a1fd3a3ba726cce4c8f449f6bbe2b02a created\n" + - args: + - porchctl + - rpkg + - pull + - --namespace=rpkg-init + - git-95686470a1fd3a3ba726cce4c8f449f6bbe2b02a + stdout: | + apiVersion: config.kubernetes.io/v1 + items: + - apiVersion: "" + kind: KptRevisionMetadata + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/path: .KptRevisionMetadata + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: .KptRevisionMetadata + name: git-95686470a1fd3a3ba726cce4c8f449f6bbe2b02a + namespace: rpkg-init + uid: uid:init-package:init-1 + - apiVersion: kpt.dev/v1 + info: + description: Test Package Description + keywords: + - test + - package + site: http://kpt.dev/init-package + kind: Kptfile + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/local-config: "true" + config.kubernetes.io/path: Kptfile + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: Kptfile + name: init-package + - apiVersion: v1 + data: + name: example + kind: ConfigMap + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/local-config: "true" + config.kubernetes.io/path: package-context.yaml + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: package-context.yaml + name: kptfile.kpt.dev + kind: ResourceList + yaml: true + - args: + - porchctl + - rpkg + - init + - --namespace=rpkg-init + - --repository=git + - --workspace=init-2 + - init-package + stderr: "error: `init` cannot create a new revision for package \"init-package\" that already exists in repo \"git\"; make subsequent revisions using `copy`\n" + exitCode: 1 diff --git a/test/e2e/cli/testdata-local-server/rpkg-lifecycle/config.yaml b/test/e2e/cli/testdata-local-server/rpkg-lifecycle/config.yaml new file mode 100644 index 00000000..cce16d7d --- /dev/null +++ b/test/e2e/cli/testdata-local-server/rpkg-lifecycle/config.yaml @@ -0,0 +1,205 @@ +commands: + - args: + - porchctl + - repo + - register + - --namespace=rpkg-lifecycle + - --name=git + - http://172.18.255.203:8080/rpkg-lifecycle + - args: + - porchctl + - rpkg + - init + - --namespace=rpkg-lifecycle + - --repository=git + - --workspace=lifecycle + - lifecycle-package + stdout: "git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 created\n" + - args: + - porchctl + - rpkg + - propose + - --namespace=rpkg-lifecycle + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + stdout: | + git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 proposed + - args: + - porchctl + - rpkg + - propose-delete + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + - --namespace=rpkg-lifecycle + exitCode: 1 + stderr: | + can only propose published packages for deletion; package git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 is not published + Error: errors: + can only propose published packages for deletion; package git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 is not published + - args: + - porchctl + - rpkg + - get + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + - --namespace=rpkg-lifecycle + - --output=custom-columns=NAME:.metadata.name,PKG:.spec.packageName,REV:.spec.revision,LIFECYCLE:.spec.lifecycle + stdout: | + NAME PKG REV LIFECYCLE + git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 lifecycle-package Proposed + - args: + - porchctl + - rpkg + - reject + - --namespace=rpkg-lifecycle + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + stdout: | + git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 rejected + - args: + - porchctl + - rpkg + - get + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + - --namespace=rpkg-lifecycle + stdout: | + NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY + git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 lifecycle-package lifecycle false Draft git + - args: + - porchctl + - rpkg + - propose-delete + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + - --namespace=rpkg-lifecycle + exitCode: 1 + stderr: | + can only propose published packages for deletion; package git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 is not published + Error: errors: + can only propose published packages for deletion; package git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 is not published + - args: + - porchctl + - rpkg + - propose + - --namespace=rpkg-lifecycle + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + stdout: | + git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 proposed + - args: + - porchctl + - rpkg + - get + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + - --namespace=rpkg-lifecycle + stdout: | + NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY + git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 lifecycle-package lifecycle false Proposed git + - args: + - porchctl + - rpkg + - approve + - --namespace=rpkg-lifecycle + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + stdout: | + git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 approved + - args: + - porchctl + - rpkg + - get + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + - --namespace=rpkg-lifecycle + stdout: | + NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY + git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 lifecycle-package lifecycle v1 true Published git + - args: + - porchctl + - rpkg + - delete + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + - --namespace=rpkg-lifecycle + exitCode: 1 + stderr: | + git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 failed (admission webhook "packagerevdeletion.google.com" denied the request: failed to delete package revision "git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034": published PackageRevisions must be proposed for deletion by setting spec.lifecycle to 'DeletionProposed' prior to deletion) + Error: errors: + admission webhook "packagerevdeletion.google.com" denied the request: failed to delete package revision "git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034": published PackageRevisions must be proposed for deletion by setting spec.lifecycle to 'DeletionProposed' prior to deletion + - args: + - porchctl + - rpkg + - propose-delete + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + - --namespace=rpkg-lifecycle + stdout: | + git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 proposed for deletion + - args: + - porchctl + - rpkg + - propose-delete + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + - --namespace=rpkg-lifecycle + stderr: | + git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 is already proposed for deletion + - args: + - porchctl + - rpkg + - get + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + - --namespace=rpkg-lifecycle + stdout: | + NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY + git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 lifecycle-package lifecycle v1 true DeletionProposed git + - args: + - porchctl + - rpkg + - reject + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + - --namespace=rpkg-lifecycle + stdout: | + git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 no longer proposed for deletion + - args: + - porchctl + - rpkg + - reject + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + - --namespace=rpkg-lifecycle + stderr: | + cannot reject git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 with lifecycle 'Published' + Error: errors: + cannot reject git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 with lifecycle 'Published' + exitCode: 1 + - args: + - porchctl + - rpkg + - get + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + - --namespace=rpkg-lifecycle + stdout: | + NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY + git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 lifecycle-package lifecycle v1 true Published git + - args: + - porchctl + - rpkg + - propose-delete + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + - --namespace=rpkg-lifecycle + stdout: | + git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 proposed for deletion + - args: + - porchctl + - rpkg + - get + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + - --namespace=rpkg-lifecycle + stdout: | + NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY + git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 lifecycle-package lifecycle v1 true DeletionProposed git + - args: + - porchctl + - rpkg + - delete + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + - --namespace=rpkg-lifecycle + stdout: | + git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 deleted + - args: + - porchctl + - rpkg + - get + - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 + - --namespace=rpkg-lifecycle + stderr: "Error: the server could not find the requested resource (get packagerevisions.porch.kpt.dev git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034) \n" + exitCode: 1 diff --git a/test/e2e/cli/testdata-local-server/rpkg-push/config.yaml b/test/e2e/cli/testdata-local-server/rpkg-push/config.yaml new file mode 100644 index 00000000..5666b314 --- /dev/null +++ b/test/e2e/cli/testdata-local-server/rpkg-push/config.yaml @@ -0,0 +1,185 @@ +commands: + - args: + - porchctl + - repo + - register + - --namespace=rpkg-push + - --name=git + - http://172.18.255.203:8080/rpkg-push + - args: + - porchctl + - rpkg + - init + - --namespace=rpkg-push + - --repository=git + - --workspace=push + - test-package + stdout: "git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f created\n" + - args: + - porchctl + - rpkg + - pull + - --namespace=rpkg-push + - git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f + stdout: | + apiVersion: config.kubernetes.io/v1 + items: + - apiVersion: "" + kind: KptRevisionMetadata + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/path: .KptRevisionMetadata + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: .KptRevisionMetadata + name: git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f + namespace: rpkg-push + uid: uid:test-package:push + - apiVersion: kpt.dev/v1 + info: + description: sample description + kind: Kptfile + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/local-config: "true" + config.kubernetes.io/path: Kptfile + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: Kptfile + name: test-package + - apiVersion: v1 + data: + name: example + kind: ConfigMap + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/local-config: "true" + config.kubernetes.io/path: package-context.yaml + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: package-context.yaml + name: kptfile.kpt.dev + kind: ResourceList + yaml: true + - args: + - porchctl + - rpkg + - push + - --namespace=rpkg-push + - git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f + stdin: | + apiVersion: config.kubernetes.io/v1 + items: + - apiVersion: "" + kind: KptRevisionMetadata + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/path: .KptRevisionMetadata + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: .KptRevisionMetadata + name: git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f + namespace: rpkg-push + uid: uid:test-package:push + - apiVersion: kpt.dev/v1 + info: + description: sample description + kind: Kptfile + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/local-config: "true" + config.kubernetes.io/path: Kptfile + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: Kptfile + name: test-package + - apiVersion: v1 + data: + name: example + kind: ConfigMap + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/local-config: "true" + config.kubernetes.io/path: package-context.yaml + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: package-context.yaml + name: kptfile.kpt.dev + kind: ResourceList + yaml: true + exitCode: 1 + stderr: "Error: Internal error occurred: resourceVersion must be specified for an update \n" + - args: + - porchctl + - rpkg + - pull + - --namespace=rpkg-push + - git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f + - /tmp/porch-e2e/rpkg-push-git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f + - args: + - kpt + - fn + - eval + - --image + - gcr.io/kpt-fn/search-replace:v0.2.0 + - --match-kind + - Kptfile + - /tmp/porch-e2e/rpkg-push-git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f + - -- + - by-path=info.description + - put-value=Updated Test Package Description + stderr: "[RUNNING] \"gcr.io/kpt-fn/search-replace:v0.2.0\" on 1 resource(s)\n Results:\n [info] info.description: Mutated field value to \"Updated Test Package Description\"\n" + - args: + - porchctl + - rpkg + - push + - --namespace=rpkg-push + - git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f + - /tmp/porch-e2e/rpkg-push-git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f + stdout: "git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f pushed\n" + - args: + - porchctl + - rpkg + - pull + - --namespace=rpkg-push + - git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f + stdout: | + apiVersion: config.kubernetes.io/v1 + items: + - apiVersion: "" + kind: KptRevisionMetadata + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/path: .KptRevisionMetadata + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: .KptRevisionMetadata + name: git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f + namespace: rpkg-push + uid: uid:test-package:push + - apiVersion: kpt.dev/v1 + info: + description: Updated Test Package Description + kind: Kptfile + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/local-config: "true" + config.kubernetes.io/path: Kptfile + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: Kptfile + name: test-package + - apiVersion: v1 + data: + name: example + kind: ConfigMap + metadata: + annotations: + config.kubernetes.io/index: "0" + config.kubernetes.io/local-config: "true" + config.kubernetes.io/path: package-context.yaml + internal.config.kubernetes.io/index: "0" + internal.config.kubernetes.io/path: package-context.yaml + name: kptfile.kpt.dev + kind: ResourceList + yaml: true diff --git a/test/e2e/cli/testdata-local-server/rpkg-update/config.yaml b/test/e2e/cli/testdata-local-server/rpkg-update/config.yaml new file mode 100644 index 00000000..b795875c --- /dev/null +++ b/test/e2e/cli/testdata-local-server/rpkg-update/config.yaml @@ -0,0 +1,150 @@ +commands: + - args: + - porchctl + - repo + - register + - --namespace=rpkg-update + - --name=git + - http://172.18.255.203:8080/rpkg-update + - args: + - porchctl + - rpkg + - clone + - --namespace=rpkg-update + - https://github.com/platkrm/test-blueprints.git + - --directory=basens + - --ref=basens/v1 + - --repository=git + - --workspace=update-1 + - basens-edit + stdout: "git-3f036055f7ba68706372cbe0c4b14d553794f7c4 created\n" + - args: + - porchctl + - rpkg + - clone + - --namespace=rpkg-update + - git-3f036055f7ba68706372cbe0c4b14d553794f7c4 + - --directory=basens + - --ref=basens/v1 + - --repository=git + - --workspace=update-2 + - basens-edit-clone + stdout: "git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 created\n" + - args: + - porchctl + - rpkg + - copy + - --namespace=rpkg-update + - --workspace=update-3 + - --replay-strategy=true + - git-3f036055f7ba68706372cbe0c4b14d553794f7c4 + stdout: "git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 created\n" + - args: + - porchctl + - rpkg + - propose + - --namespace=rpkg-update + - git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 + stdout: "git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 proposed\n" + - args: + - porchctl + - rpkg + - approve + - --namespace=rpkg-update + - git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 + stdout: "git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 approved\n" + - args: + - porchctl + - rpkg + - get + - --namespace=rpkg-update + stdout: | + NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY + git-3f036055f7ba68706372cbe0c4b14d553794f7c4 basens-edit update-1 false Draft git + git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 basens-edit update-3 v1 true Published git + git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 basens-edit-clone update-2 false Draft git + - args: + - porchctl + - rpkg + - update + - --namespace=rpkg-update + - --discover=upstream + - git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 + stdout: | + PACKAGE REVISION UPSTREAM REPOSITORY UPSTREAM UPDATES + git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 git v1 + - args: + - porchctl + - rpkg + - update + - --namespace=rpkg-update + - --discover=upstream + stdout: | + PACKAGE REVISION UPSTREAM REPOSITORY UPSTREAM UPDATES + git-3f036055f7ba68706372cbe0c4b14d553794f7c4 No update available + git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 No update available + git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 git v1 + - args: + - porchctl + - rpkg + - update + - --namespace=rpkg-update + - --discover=downstream + stdout: | + PACKAGE REVISION DOWNSTREAM PACKAGE DOWNSTREAM UPDATE + git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 (draft "update-1")->v1 + - args: + - porchctl + - rpkg + - update + - --namespace=rpkg-update + - --revision=v1 + - git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 + stdout: "git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 updated\n" + - args: + - porchctl + - rpkg + - update + - --namespace=rpkg-update + - --discover=upstream + stdout: | + PACKAGE REVISION UPSTREAM REPOSITORY UPSTREAM UPDATES + git-3f036055f7ba68706372cbe0c4b14d553794f7c4 No update available + git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 No update available + git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 git No update available + - args: + - porchctl + - rpkg + - pull + - --namespace=rpkg-update + - git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 + - /tmp/porch-e2e/pkg-update-git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 + - args: + - kpt + - fn + - eval + - --image + - gcr.io/kpt-fn/search-replace:v0.2.0 + - --match-kind + - Kptfile + - /tmp/porch-e2e/pkg-update-git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 + - -- + - by-path=upstreamLock.git.ref + - put-value=invalid + stderr: "[RUNNING] \"gcr.io/kpt-fn/search-replace:v0.2.0\" on 1 resource(s)\n Results:\n [info] upstreamLock.git.ref: Mutated field value to \"invalid\"\n" + - args: + - porchctl + - rpkg + - push + - --namespace=rpkg-update + - git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 + - /tmp/porch-e2e/pkg-update-git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 + stdout: "git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 pushed\n" + - args: + - porchctl + - rpkg + - update + - --namespace=rpkg-update + - --discover=upstream + stderr: "Error: could not parse upstreamLock in Kptfile of package \"git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0\": malformed upstreamLock.Git.Ref \"invalid\" \n" + exitCode: 1 diff --git a/test/e2e/cli/testdata/git-server.yaml b/test/e2e/cli/testdata/git-server.yaml index 45c71716..78f15803 100644 --- a/test/e2e/cli/testdata/git-server.yaml +++ b/test/e2e/cli/testdata/git-server.yaml @@ -30,10 +30,7 @@ kind: Service metadata: name: git-server namespace: test-git-namespace - annotations: - metallb.universe.tf/loadBalancerIPs: "172.18.255.203" spec: - type: LoadBalancer selector: app: git-server ports: diff --git a/test/e2e/cli/testdata/rpkg-clone/config.yaml b/test/e2e/cli/testdata/rpkg-clone/config.yaml index 9cd42972..b169c580 100644 --- a/test/e2e/cli/testdata/rpkg-clone/config.yaml +++ b/test/e2e/cli/testdata/rpkg-clone/config.yaml @@ -5,7 +5,7 @@ commands: - register - --namespace=rpkg-clone - --name=git - - http://172.18.255.203:8080/rpkg-clone + - http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-clone - args: - porchctl - rpkg diff --git a/test/e2e/cli/testdata/rpkg-copy/config.yaml b/test/e2e/cli/testdata/rpkg-copy/config.yaml index 24e4512f..5e90830c 100644 --- a/test/e2e/cli/testdata/rpkg-copy/config.yaml +++ b/test/e2e/cli/testdata/rpkg-copy/config.yaml @@ -5,7 +5,7 @@ commands: - register - --namespace=rpkg-copy - --name=git - - http://172.18.255.203:8080/rpkg-copy + - http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-copy - args: - porchctl - rpkg diff --git a/test/e2e/cli/testdata/rpkg-init-deploy/config.yaml b/test/e2e/cli/testdata/rpkg-init-deploy/config.yaml index db03e9aa..82f091dc 100644 --- a/test/e2e/cli/testdata/rpkg-init-deploy/config.yaml +++ b/test/e2e/cli/testdata/rpkg-init-deploy/config.yaml @@ -6,7 +6,7 @@ commands: - --namespace=rpkg-init-deploy - --name=git - --deployment - - http://172.18.255.203:8080/rpkg-init-deploy + - http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-init-deploy - args: - porchctl - repo @@ -87,4 +87,4 @@ commands: - --namespace=rpkg-init-deploy stdout: | NAME TYPE CONTENT DEPLOYMENT READY ADDRESS - git git Package true True http://172.18.255.203:8080/rpkg-init-deploy + git git Package true True http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-init-deploy diff --git a/test/e2e/cli/testdata/rpkg-init/config.yaml b/test/e2e/cli/testdata/rpkg-init/config.yaml index ec64656d..46354cdb 100644 --- a/test/e2e/cli/testdata/rpkg-init/config.yaml +++ b/test/e2e/cli/testdata/rpkg-init/config.yaml @@ -5,7 +5,7 @@ commands: - register - --namespace=rpkg-init - --name=git - - http://172.18.255.203:8080/rpkg-init + - http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-init - args: - porchctl - repo @@ -13,8 +13,8 @@ commands: - --namespace=rpkg-init - --output=custom-columns=NAME:.metadata.name,ADDRESS:.spec.git.repo,BRANCH:.spec.git.branch,DIR:.spec.git.directory stdout: | - NAME ADDRESS BRANCH DIR - git http://172.18.255.203:8080/rpkg-init main / + NAME ADDRESS BRANCH DIR + git http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-init main / - args: - porchctl - rpkg diff --git a/test/e2e/cli/testdata/rpkg-lifecycle/config.yaml b/test/e2e/cli/testdata/rpkg-lifecycle/config.yaml index cce16d7d..d560517f 100644 --- a/test/e2e/cli/testdata/rpkg-lifecycle/config.yaml +++ b/test/e2e/cli/testdata/rpkg-lifecycle/config.yaml @@ -5,7 +5,7 @@ commands: - register - --namespace=rpkg-lifecycle - --name=git - - http://172.18.255.203:8080/rpkg-lifecycle + - http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-lifecycle - args: - porchctl - rpkg diff --git a/test/e2e/cli/testdata/rpkg-push/config.yaml b/test/e2e/cli/testdata/rpkg-push/config.yaml index 5666b314..2effb864 100644 --- a/test/e2e/cli/testdata/rpkg-push/config.yaml +++ b/test/e2e/cli/testdata/rpkg-push/config.yaml @@ -5,7 +5,7 @@ commands: - register - --namespace=rpkg-push - --name=git - - http://172.18.255.203:8080/rpkg-push + - http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-push - args: - porchctl - rpkg diff --git a/test/e2e/cli/testdata/rpkg-update/config.yaml b/test/e2e/cli/testdata/rpkg-update/config.yaml index b795875c..67158872 100644 --- a/test/e2e/cli/testdata/rpkg-update/config.yaml +++ b/test/e2e/cli/testdata/rpkg-update/config.yaml @@ -5,7 +5,7 @@ commands: - register - --namespace=rpkg-update - --name=git - - http://172.18.255.203:8080/rpkg-update + - http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-update - args: - porchctl - rpkg From 452e803c0ecc843fbed55c9ea5b55cc930939eca Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Tue, 28 May 2024 00:59:35 +0200 Subject: [PATCH 10/23] document how to call the e2e CLI test properly with a local porch server --- .gitignore | 1 + docs/tutorials/porch-development-environment/README.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0193fe49..26a28f3c 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ coverage_unit.html !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json +__debug* ### VisualStudioCode Patch ### # Ignore all local history of files diff --git a/docs/tutorials/porch-development-environment/README.md b/docs/tutorials/porch-development-environment/README.md index 7a1c2d41..da9d226e 100644 --- a/docs/tutorials/porch-development-environment/README.md +++ b/docs/tutorials/porch-development-environment/README.md @@ -204,7 +204,7 @@ E2E=1 go test -v ./test/e2e To test porch via its CLI: ``` -E2E=1 go test -v ./test/e2e/cli +E2E=local-server go test -v ./test/e2e/cli ``` # Create Repositories using your local Porch server From a317693c7876ec32364a646cd9643cff12f58ba9 Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Tue, 28 May 2024 09:53:00 +0200 Subject: [PATCH 11/23] Remove duplicated testdata from test/e2e/cli --- test/e2e/cli/cli_test.go | 85 ++++++-- test/e2e/cli/cluster.go | 31 ++- test/e2e/cli/config.go | 2 + .../cli/testdata-local-server/git-server.yaml | 42 ---- .../repo-register/config.yaml | 46 ---- .../rpkg-clone/config.yaml | 158 -------------- .../rpkg-copy/config.yaml | 99 --------- .../rpkg-get/config.yaml | 44 ---- .../rpkg-init-deploy/config.yaml | 90 -------- .../rpkg-init/config.yaml | 91 -------- .../rpkg-lifecycle/config.yaml | 205 ------------------ .../rpkg-push/config.yaml | 185 ---------------- .../rpkg-update/config.yaml | 150 ------------- test/e2e/cli/testdata/git-server.yaml | 1 + test/e2e/cli/testdata/rpkg-init/config.yaml | 3 +- 15 files changed, 97 insertions(+), 1135 deletions(-) delete mode 100644 test/e2e/cli/testdata-local-server/git-server.yaml delete mode 100644 test/e2e/cli/testdata-local-server/repo-register/config.yaml delete mode 100644 test/e2e/cli/testdata-local-server/rpkg-clone/config.yaml delete mode 100644 test/e2e/cli/testdata-local-server/rpkg-copy/config.yaml delete mode 100644 test/e2e/cli/testdata-local-server/rpkg-get/config.yaml delete mode 100644 test/e2e/cli/testdata-local-server/rpkg-init-deploy/config.yaml delete mode 100644 test/e2e/cli/testdata-local-server/rpkg-init/config.yaml delete mode 100644 test/e2e/cli/testdata-local-server/rpkg-lifecycle/config.yaml delete mode 100644 test/e2e/cli/testdata-local-server/rpkg-push/config.yaml delete mode 100644 test/e2e/cli/testdata-local-server/rpkg-update/config.yaml diff --git a/test/e2e/cli/cli_test.go b/test/e2e/cli/cli_test.go index 9c529357..c5fb9ddb 100644 --- a/test/e2e/cli/cli_test.go +++ b/test/e2e/cli/cli_test.go @@ -31,8 +31,10 @@ import ( ) const ( - updateGoldenFiles = "UPDATE_GOLDEN_FILES" - testGitNamespace = "test-git-namespace" + updateGoldenFiles = "UPDATE_GOLDEN_FILES" + testGitName = "git-server" + testGitNamespace = "test-git-namespace" + defaultTestGitServerUrl = "http://" + testGitName + "." + testGitNamespace + ".svc.cluster.local:8080" ) func TestPorch(t *testing.T) { @@ -41,18 +43,11 @@ func TestPorch(t *testing.T) { t.Skip("set E2E to run this test") } - var testdataDir string - if e2e == "local-server" { - testdataDir = "testdata-local-server" - } else { - testdataDir = "testdata" - } - - abs, err := filepath.Abs(filepath.Join(".", testdataDir)) + abs, err := filepath.Abs(filepath.Join(".", "testdata")) if err != nil { t.Fatalf("Failed to get absolute path to testdata directory: %v", err) } - runTests(t, abs) + runTests(t, abs, e2e != "local-server") } func runUtilityCommand(t *testing.T, command string, args ...string) error { @@ -61,8 +56,14 @@ func runUtilityCommand(t *testing.T, command string, args ...string) error { return cmd.Run() } -func runTests(t *testing.T, path string) { - gitServerURL := startGitServer(t, path) +func runTests(t *testing.T, path string, isPorchInCluster bool) { + var searchAndReplace = map[string]string{} + + gitServerURL := startGitServer(t, path, isPorchInCluster) + if gitServerURL != defaultTestGitServerUrl { + searchAndReplace[defaultTestGitServerUrl] = gitServerURL + } + testCases := scanTestCases(t, path) // remove any tmp files from previous test runs @@ -81,12 +82,23 @@ func runTests(t *testing.T, path string) { t.Skipf("Skipping test: %s", tc.Skip) } repoURL := gitServerURL + "/" + strings.ReplaceAll(tc.TestCase, "/", "-") - runTestCase(t, repoURL, tc) + runTestCase(t, repoURL, tc, searchAndReplace) }) } } -func runTestCase(t *testing.T, repoURL string, tc TestCaseConfig) { +func normalizeWhitespace(s1 string) string { + parts := strings.Split(s1, " ") + words := make([]string, 0, len(parts)) + for _, part := range parts { + if part != "" { + words = append(words, part) + } + } + return strings.Join(words, " ") +} + +func runTestCase(t *testing.T, repoURL string, tc TestCaseConfig, searchAndReplace map[string]string) { KubectlCreateNamespace(t, tc.TestCase) t.Cleanup(func() { KubectlDeleteNamespace(t, tc.TestCase) @@ -99,6 +111,11 @@ func runTestCase(t *testing.T, repoURL string, tc TestCaseConfig) { for i := range tc.Commands { time.Sleep(1 * time.Second) command := &tc.Commands[i] + for i, arg := range command.Args { + for search, replace := range searchAndReplace { + command.Args[i] = strings.ReplaceAll(arg, search, replace) + } + } cmd := exec.Command(command.Args[0], command.Args[1:]...) var stdout, stderr bytes.Buffer @@ -117,6 +134,20 @@ func runTestCase(t *testing.T, repoURL string, tc TestCaseConfig) { cleanupStderr(t, &stderr) + stdoutStr := stdout.String() + stderrStr := stderr.String() + for search, replace := range searchAndReplace { + command.Stdout = strings.ReplaceAll(command.Stdout, search, replace) + command.Stderr = strings.ReplaceAll(command.Stderr, search, replace) + } + + if command.IgnoreWhitespace { + command.Stdout = normalizeWhitespace(command.Stdout) + command.Stderr = normalizeWhitespace(command.Stderr) + stdoutStr = normalizeWhitespace(stdoutStr) + stderrStr = normalizeWhitespace(stderrStr) + } + if os.Getenv(updateGoldenFiles) != "" { updateCommand(command, err, stdout.String(), stderr.String()) } @@ -124,10 +155,10 @@ func runTestCase(t *testing.T, repoURL string, tc TestCaseConfig) { if got, want := exitCode(err), command.ExitCode; got != want { t.Errorf("unexpected exit code from '%s'; got %d, want %d", strings.Join(command.Args, " "), got, want) } - if got, want := stdout.String(), command.Stdout; got != want { + if got, want := stdoutStr, command.Stdout; got != want { t.Errorf("unexpected stdout content from '%s'; (-want, +got) %s", strings.Join(command.Args, " "), cmp.Diff(want, got)) } - if got, want := stderr.String(), command.Stderr; got != want { + if got, want := stderrStr, command.Stderr; got != want { t.Errorf("unexpected stderr content from '%s'; (-want, +got) %s", strings.Join(command.Args, " "), cmp.Diff(want, got)) } @@ -198,9 +229,7 @@ func reorderYamlStdout(t *testing.T, buf *bytes.Buffer) { } } -func startGitServer(t *testing.T, path string) string { - gitServerURL := "http://git-server." + testGitNamespace + ".svc.cluster.local:8080" - +func startGitServer(t *testing.T, path string, isPorchInCluster bool) string { gitServerImage := GetGitServerImageName(t) t.Logf("Git Image: %s", gitServerImage) @@ -211,15 +240,25 @@ func startGitServer(t *testing.T, path string) string { } config := string(configBytes) config = strings.ReplaceAll(config, "GIT_SERVER_IMAGE", gitServerImage) + if !isPorchInCluster { + config = strings.ReplaceAll(config, "ClusterIP", "LoadBalancer") + } t.Cleanup(func() { KubectlDeleteNamespace(t, testGitNamespace) }) KubectlApply(t, config) - KubectlWaitForDeployment(t, testGitNamespace, "git-server") - KubectlWaitForService(t, testGitNamespace, "git-server") - KubectlWaitForGitDNS(t, gitServerURL) + KubectlWaitForDeployment(t, testGitNamespace, testGitName) + KubectlWaitForService(t, testGitNamespace, testGitName) + + gitServerURL := defaultTestGitServerUrl + if isPorchInCluster { + KubectlWaitForGitDNS(t, gitServerURL) + } else { + ip := KubectlWaitForLoadBalancerIp(t, testGitNamespace, testGitName) + gitServerURL = "http://" + ip + ":8080" + } return gitServerURL } diff --git a/test/e2e/cli/cluster.go b/test/e2e/cli/cluster.go index 5dec0279..3224f794 100644 --- a/test/e2e/cli/cluster.go +++ b/test/e2e/cli/cluster.go @@ -85,7 +85,7 @@ func KubectlWaitForDeployment(t *testing.T, namespace, name string) { } func KubectlWaitForService(t *testing.T, namespace, name string) { - args := []string{"get", "endpoints", "--namespace", namespace, name, "--output=jsonpath='{.subsets[*].addresses[*].ip}'"} + args := []string{"get", "endpoints", "--namespace", namespace, name, "--output=jsonpath={.subsets[*].addresses[*].ip}"} giveUp := time.Now().Add(1 * time.Minute) for { @@ -113,6 +113,35 @@ func KubectlWaitForService(t *testing.T, namespace, name string) { } } +func KubectlWaitForLoadBalancerIp(t *testing.T, namespace, name string) string { + args := []string{"get", "service", "--namespace", namespace, name, "--output=jsonpath={.status.loadBalancer.ingress[0].ip}"} + + giveUp := time.Now().Add(1 * time.Minute) + for { + cmd := exec.Command("kubectl", args...) + var stdout, stderr bytes.Buffer + cmd.Stdout = &stdout + cmd.Stderr = &stderr + + err := cmd.Run() + ip := stdout.String() + if err == nil && len(ip) > 0 { // Loadbalancer assigned an external IP + t.Logf("LoadBalancer external IP: %s", ip) + return ip + } + + if time.Now().After(giveUp) { + var msg string + if err != nil { + msg = err.Error() + } + t.Fatalf("LoadBalancer service %s/%s hasn't been assigned an external IP on time. Giving up: %s", namespace, name, msg) + } + + time.Sleep(5 * time.Second) + } +} + // Kubernetes DNS needs time to propagate the updated address // Wait until we can register the repository and list its contents. func KubectlWaitForGitDNS(t *testing.T, gitServerURL string) { diff --git a/test/e2e/cli/config.go b/test/e2e/cli/config.go index d1d66e2e..9c6abc25 100644 --- a/test/e2e/cli/config.go +++ b/test/e2e/cli/config.go @@ -36,6 +36,8 @@ type Command struct { ExitCode int `yaml:"exitCode,omitempty"` // Yaml indicates that stdout is yaml and the test will reformat it for stable ordering Yaml bool `yaml:"yaml,omitempty"` + // IgnoreWhitespace inidicates that whitespace differences should be ignored in the output + IgnoreWhitespace bool `yaml:"ignoreWhitespace,omitempty"` } type TestCaseConfig struct { diff --git a/test/e2e/cli/testdata-local-server/git-server.yaml b/test/e2e/cli/testdata-local-server/git-server.yaml deleted file mode 100644 index 45c71716..00000000 --- a/test/e2e/cli/testdata-local-server/git-server.yaml +++ /dev/null @@ -1,42 +0,0 @@ -apiVersion: v1 -kind: Namespace -metadata: - name: test-git-namespace ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: git-server - namespace: test-git-namespace -spec: - replicas: 1 - selector: - matchLabels: - app: git-server - template: - metadata: - labels: - app: git-server - spec: - containers: - - name: git-server - image: GIT_SERVER_IMAGE - ports: - - containerPort: 8080 - protocol: TCP ---- -apiVersion: v1 -kind: Service -metadata: - name: git-server - namespace: test-git-namespace - annotations: - metallb.universe.tf/loadBalancerIPs: "172.18.255.203" -spec: - type: LoadBalancer - selector: - app: git-server - ports: - - protocol: TCP - port: 8080 - targetPort: 8080 diff --git a/test/e2e/cli/testdata-local-server/repo-register/config.yaml b/test/e2e/cli/testdata-local-server/repo-register/config.yaml deleted file mode 100644 index 95f1eea2..00000000 --- a/test/e2e/cli/testdata-local-server/repo-register/config.yaml +++ /dev/null @@ -1,46 +0,0 @@ -commands: - - args: - - porchctl - - repo - - register - - https://github.com/platkrm/test-blueprints.git - - --namespace=repo-register - - --description - - Test Blueprints - - args: - - porchctl - - repo - - get - - --namespace=repo-register - - --output=custom-columns=NAME:.metadata.name,ADDRESS:.spec.git.repo,BRANCH:.spec.git.branch,DIR:.spec.git.directory - stdout: | - NAME ADDRESS BRANCH DIR - test-blueprints https://github.com/platkrm/test-blueprints.git main / - - args: - - porchctl - - repo - - get - - --namespace=repo-register - - --output=custom-columns=NAME:.metadata.name,CONTENT:.spec.content,DESC:.spec.description - stdout: | - NAME CONTENT DESC - test-blueprints Package Test Blueprints - - args: - - porchctl - - repo - - get - - --namespace=repo-register - stdout: | - NAME TYPE CONTENT DEPLOYMENT READY ADDRESS - test-blueprints git Package True https://github.com/platkrm/test-blueprints.git - - args: - - porchctl - - repo - - unregister - - --namespace=repo-register - - test-blueprints - - args: - - porchctl - - repo - - get - - --namespace=repo-register diff --git a/test/e2e/cli/testdata-local-server/rpkg-clone/config.yaml b/test/e2e/cli/testdata-local-server/rpkg-clone/config.yaml deleted file mode 100644 index 9cd42972..00000000 --- a/test/e2e/cli/testdata-local-server/rpkg-clone/config.yaml +++ /dev/null @@ -1,158 +0,0 @@ -commands: - - args: - - porchctl - - repo - - register - - --namespace=rpkg-clone - - --name=git - - http://172.18.255.203:8080/rpkg-clone - - args: - - porchctl - - rpkg - - clone - - --namespace=rpkg-clone - - https://github.com/platkrm/test-blueprints.git/basens@basens/v1 - - --repository=git - - --workspace=clone-2 - - basens-clone - stdout: "git-3465eed5831e5c372243d048631c8ef1666b47d6 created\n" - - args: - - porchctl - - rpkg - - clone - - --namespace=rpkg-clone - - https://github.com/platkrm/test-blueprints.git/basens@basens/v1 - - --repository=git - - --workspace=clone-3 - - basens-clone - stderr: "error: `clone` cannot create a new revision for package \"basens-clone\" that already exists in repo \"git\"; make subsequent revisions using `copy`\n" - exitCode: 1 - - args: - - porchctl - - repo - - register - - https://github.com/platkrm/test-blueprints.git - - --namespace=rpkg-clone - - args: - - porchctl - - rpkg - - get - - --namespace=rpkg-clone - - --name=empty - - --revision=v1 - - --output=jsonpath={.metadata.name} - stdout: test-blueprints-e78ee77d9560703561c2656c97c77e9abb8c4c53 - - args: - - porchctl - - rpkg - - clone - - --namespace=rpkg-clone - - test-blueprints-e78ee77d9560703561c2656c97c77e9abb8c4c53 - - --repository=git - - --workspace=clone-1 - - empty-clone - stdout: "git-b67f9ce14d378317ba83c9504eab9cc024932dd3 created\n" - - args: - - porchctl - - rpkg - - pull - - --namespace=rpkg-clone - - git-3465eed5831e5c372243d048631c8ef1666b47d6 - stdout: | - apiVersion: config.kubernetes.io/v1 - items: - - apiVersion: "" - kind: KptRevisionMetadata - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/path: .KptRevisionMetadata - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: .KptRevisionMetadata - name: git-3465eed5831e5c372243d048631c8ef1666b47d6 - namespace: rpkg-clone - uid: uid:basens-clone:clone-2 - - apiVersion: kpt.dev/v1 - info: - description: sample description - kind: Kptfile - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/path: Kptfile - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: Kptfile - internal.kpt.dev/upstream-identifier: kpt.dev|Kptfile|default|basens-clone - name: basens-clone - upstream: - git: - directory: basens - ref: basens/v1 - repo: https://github.com/platkrm/test-blueprints.git - type: git - upstreamLock: - git: - commit: 67f29546028f0a48c6bbb08614934d0e070cdd3a - directory: basens - ref: basens/v1 - repo: https://github.com/platkrm/test-blueprints.git - type: git - - apiVersion: v1 - kind: Namespace - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/path: namespace.yaml - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: namespace.yaml - internal.kpt.dev/upstream-identifier: '|Namespace|default|example' - name: example - kind: ResourceList - yaml: true - - args: - - porchctl - - rpkg - - pull - - --namespace=rpkg-clone - - git-b67f9ce14d378317ba83c9504eab9cc024932dd3 - stdout: | - apiVersion: config.kubernetes.io/v1 - items: - - apiVersion: "" - kind: KptRevisionMetadata - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/path: .KptRevisionMetadata - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: .KptRevisionMetadata - name: git-b67f9ce14d378317ba83c9504eab9cc024932dd3 - namespace: rpkg-clone - uid: uid:empty-clone:clone-1 - - apiVersion: kpt.dev/v1 - info: - description: Empty Blueprint - kind: Kptfile - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/path: Kptfile - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: Kptfile - internal.kpt.dev/upstream-identifier: kpt.dev|Kptfile|default|empty-clone - name: empty-clone - upstream: - git: - directory: empty - ref: empty/v1 - repo: https://github.com/platkrm/test-blueprints.git - type: git - upstreamLock: - git: - commit: 3de8635354eda8e7de756494a4e0eb5c12af01ab - directory: empty - ref: empty/v1 - repo: https://github.com/platkrm/test-blueprints.git - type: git - kind: ResourceList - yaml: true diff --git a/test/e2e/cli/testdata-local-server/rpkg-copy/config.yaml b/test/e2e/cli/testdata-local-server/rpkg-copy/config.yaml deleted file mode 100644 index 24e4512f..00000000 --- a/test/e2e/cli/testdata-local-server/rpkg-copy/config.yaml +++ /dev/null @@ -1,99 +0,0 @@ -commands: - - args: - - porchctl - - repo - - register - - --namespace=rpkg-copy - - --name=git - - http://172.18.255.203:8080/rpkg-copy - - args: - - porchctl - - rpkg - - clone - - --namespace=rpkg-copy - - https://github.com/platkrm/test-blueprints.git - - --directory=basens - - --ref=basens/v1 - - --repository=git - - --workspace=copy-1 - - basens-edit - stdout: "git-eb5afe755bedd142f142c6a9363649c667ef77a5 created\n" - - args: - - porchctl - - rpkg - - propose - - --namespace=rpkg-copy - - git-eb5afe755bedd142f142c6a9363649c667ef77a5 - stdout: "git-eb5afe755bedd142f142c6a9363649c667ef77a5 proposed\n" - - args: - - porchctl - - rpkg - - approve - - --namespace=rpkg-copy - - git-eb5afe755bedd142f142c6a9363649c667ef77a5 - stdout: "git-eb5afe755bedd142f142c6a9363649c667ef77a5 approved\n" - - args: - - porchctl - - rpkg - - copy - - --namespace=rpkg-copy - - --workspace=copy-2 - - git-eb5afe755bedd142f142c6a9363649c667ef77a5 - stdout: "git-a29df72d1135fd010ea49f4d4877001dee423be6 created\n" - - args: - - porchctl - - rpkg - - pull - - --namespace=rpkg-copy - - git-a29df72d1135fd010ea49f4d4877001dee423be6 - stdout: | - apiVersion: config.kubernetes.io/v1 - items: - - apiVersion: "" - kind: KptRevisionMetadata - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/path: .KptRevisionMetadata - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: .KptRevisionMetadata - name: git-a29df72d1135fd010ea49f4d4877001dee423be6 - namespace: rpkg-copy - uid: uid:basens-edit:copy-2 - - apiVersion: kpt.dev/v1 - info: - description: sample description - kind: Kptfile - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/path: Kptfile - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: Kptfile - internal.kpt.dev/upstream-identifier: kpt.dev|Kptfile|default|basens-edit - name: basens-edit - upstream: - git: - directory: basens - ref: basens/v1 - repo: https://github.com/platkrm/test-blueprints.git - type: git - upstreamLock: - git: - commit: 67f29546028f0a48c6bbb08614934d0e070cdd3a - directory: basens - ref: basens/v1 - repo: https://github.com/platkrm/test-blueprints.git - type: git - - apiVersion: v1 - kind: Namespace - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/path: namespace.yaml - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: namespace.yaml - internal.kpt.dev/upstream-identifier: '|Namespace|default|example' - name: example - kind: ResourceList - yaml: true diff --git a/test/e2e/cli/testdata-local-server/rpkg-get/config.yaml b/test/e2e/cli/testdata-local-server/rpkg-get/config.yaml deleted file mode 100644 index c62ff142..00000000 --- a/test/e2e/cli/testdata-local-server/rpkg-get/config.yaml +++ /dev/null @@ -1,44 +0,0 @@ -commands: - - args: - - porchctl - - repo - - register - - https://github.com/platkrm/test-blueprints.git - - --namespace=rpkg-get - - --description - - Test Blueprints - - args: - - porchctl - - rpkg - - get - - --namespace=rpkg-get - - --output=custom-columns=NAME:.metadata.name,PKG:.spec.packageName,REPO:.spec.repository,REV:.spec.revision - stdout: | - NAME PKG REPO REV - test-blueprints-9626794e984ff13c9a4c64df5af0f15ec3a146bf basens test-blueprints main - test-blueprints-526fa27229adcc3b6a9a544c455c344a3b4d7597 basens test-blueprints v1 - test-blueprints-499689d1e0c6fced058158330d922c004367d6cd basens test-blueprints v2 - test-blueprints-913ab85d2d49621636a0ffa514a2a008e6a7012e basens test-blueprints v3 - test-blueprints-58fffeb908ead18e2c05c873e61bff11a5292963 empty test-blueprints main - test-blueprints-e78ee77d9560703561c2656c97c77e9abb8c4c53 empty test-blueprints v1 - - args: - - porchctl - - rpkg - - get - - --namespace=rpkg-get - - test-blueprints-526fa27229adcc3b6a9a544c455c344a3b4d7597 - stdout: | - NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY - test-blueprints-526fa27229adcc3b6a9a544c455c344a3b4d7597 basens v1 v1 false Published test-blueprints - - args: - - porchctl - - rpkg - - get - - --namespace=rpkg-get - - --name=basens - stdout: | - NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY - test-blueprints-9626794e984ff13c9a4c64df5af0f15ec3a146bf basens main main false Published test-blueprints - test-blueprints-526fa27229adcc3b6a9a544c455c344a3b4d7597 basens v1 v1 false Published test-blueprints - test-blueprints-499689d1e0c6fced058158330d922c004367d6cd basens v2 v2 false Published test-blueprints - test-blueprints-913ab85d2d49621636a0ffa514a2a008e6a7012e basens v3 v3 true Published test-blueprints diff --git a/test/e2e/cli/testdata-local-server/rpkg-init-deploy/config.yaml b/test/e2e/cli/testdata-local-server/rpkg-init-deploy/config.yaml deleted file mode 100644 index db03e9aa..00000000 --- a/test/e2e/cli/testdata-local-server/rpkg-init-deploy/config.yaml +++ /dev/null @@ -1,90 +0,0 @@ -commands: - - args: - - porchctl - - repo - - register - - --namespace=rpkg-init-deploy - - --name=git - - --deployment - - http://172.18.255.203:8080/rpkg-init-deploy - - args: - - porchctl - - repo - - get - - --namespace=rpkg-init-deploy - - --output=custom-columns=NAME:.metadata.name,DEPLOYMENT:.spec.deployment - stdout: | - NAME DEPLOYMENT - git true - - args: - - porchctl - - rpkg - - init - - --namespace=rpkg-init-deploy - - --description - - Test Package Description - - --keywords=test,package - - --site - - http://kpt.dev/deploy-package - - --repository=git - - --workspace=deploy - - deploy-package - stdout: "git-628abd0a0903f5de6cb3604d917724f6fc1b5e08 created\n" - - args: - - porchctl - - rpkg - - pull - - --namespace=rpkg-init-deploy - - git-628abd0a0903f5de6cb3604d917724f6fc1b5e08 - stdout: | - apiVersion: config.kubernetes.io/v1 - items: - - apiVersion: "" - kind: KptRevisionMetadata - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/path: .KptRevisionMetadata - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: .KptRevisionMetadata - name: git-628abd0a0903f5de6cb3604d917724f6fc1b5e08 - namespace: rpkg-init-deploy - uid: uid:deploy-package:deploy - - apiVersion: kpt.dev/v1 - info: - description: Test Package Description - keywords: - - test - - package - site: http://kpt.dev/deploy-package - kind: Kptfile - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/local-config: "true" - config.kubernetes.io/path: Kptfile - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: Kptfile - name: deploy-package - - apiVersion: v1 - data: - name: example - kind: ConfigMap - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/local-config: "true" - config.kubernetes.io/path: package-context.yaml - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: package-context.yaml - name: kptfile.kpt.dev - kind: ResourceList - yaml: true - - args: - - porchctl - - repo - - get - - --namespace=rpkg-init-deploy - stdout: | - NAME TYPE CONTENT DEPLOYMENT READY ADDRESS - git git Package true True http://172.18.255.203:8080/rpkg-init-deploy diff --git a/test/e2e/cli/testdata-local-server/rpkg-init/config.yaml b/test/e2e/cli/testdata-local-server/rpkg-init/config.yaml deleted file mode 100644 index ec64656d..00000000 --- a/test/e2e/cli/testdata-local-server/rpkg-init/config.yaml +++ /dev/null @@ -1,91 +0,0 @@ -commands: - - args: - - porchctl - - repo - - register - - --namespace=rpkg-init - - --name=git - - http://172.18.255.203:8080/rpkg-init - - args: - - porchctl - - repo - - get - - --namespace=rpkg-init - - --output=custom-columns=NAME:.metadata.name,ADDRESS:.spec.git.repo,BRANCH:.spec.git.branch,DIR:.spec.git.directory - stdout: | - NAME ADDRESS BRANCH DIR - git http://172.18.255.203:8080/rpkg-init main / - - args: - - porchctl - - rpkg - - init - - --namespace=rpkg-init - - --description - - Test Package Description - - --keywords=test,package - - --site - - http://kpt.dev/init-package - - --repository=git - - --workspace=init-1 - - init-package - stdout: "git-95686470a1fd3a3ba726cce4c8f449f6bbe2b02a created\n" - - args: - - porchctl - - rpkg - - pull - - --namespace=rpkg-init - - git-95686470a1fd3a3ba726cce4c8f449f6bbe2b02a - stdout: | - apiVersion: config.kubernetes.io/v1 - items: - - apiVersion: "" - kind: KptRevisionMetadata - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/path: .KptRevisionMetadata - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: .KptRevisionMetadata - name: git-95686470a1fd3a3ba726cce4c8f449f6bbe2b02a - namespace: rpkg-init - uid: uid:init-package:init-1 - - apiVersion: kpt.dev/v1 - info: - description: Test Package Description - keywords: - - test - - package - site: http://kpt.dev/init-package - kind: Kptfile - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/local-config: "true" - config.kubernetes.io/path: Kptfile - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: Kptfile - name: init-package - - apiVersion: v1 - data: - name: example - kind: ConfigMap - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/local-config: "true" - config.kubernetes.io/path: package-context.yaml - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: package-context.yaml - name: kptfile.kpt.dev - kind: ResourceList - yaml: true - - args: - - porchctl - - rpkg - - init - - --namespace=rpkg-init - - --repository=git - - --workspace=init-2 - - init-package - stderr: "error: `init` cannot create a new revision for package \"init-package\" that already exists in repo \"git\"; make subsequent revisions using `copy`\n" - exitCode: 1 diff --git a/test/e2e/cli/testdata-local-server/rpkg-lifecycle/config.yaml b/test/e2e/cli/testdata-local-server/rpkg-lifecycle/config.yaml deleted file mode 100644 index cce16d7d..00000000 --- a/test/e2e/cli/testdata-local-server/rpkg-lifecycle/config.yaml +++ /dev/null @@ -1,205 +0,0 @@ -commands: - - args: - - porchctl - - repo - - register - - --namespace=rpkg-lifecycle - - --name=git - - http://172.18.255.203:8080/rpkg-lifecycle - - args: - - porchctl - - rpkg - - init - - --namespace=rpkg-lifecycle - - --repository=git - - --workspace=lifecycle - - lifecycle-package - stdout: "git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 created\n" - - args: - - porchctl - - rpkg - - propose - - --namespace=rpkg-lifecycle - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - stdout: | - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 proposed - - args: - - porchctl - - rpkg - - propose-delete - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - - --namespace=rpkg-lifecycle - exitCode: 1 - stderr: | - can only propose published packages for deletion; package git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 is not published - Error: errors: - can only propose published packages for deletion; package git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 is not published - - args: - - porchctl - - rpkg - - get - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - - --namespace=rpkg-lifecycle - - --output=custom-columns=NAME:.metadata.name,PKG:.spec.packageName,REV:.spec.revision,LIFECYCLE:.spec.lifecycle - stdout: | - NAME PKG REV LIFECYCLE - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 lifecycle-package Proposed - - args: - - porchctl - - rpkg - - reject - - --namespace=rpkg-lifecycle - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - stdout: | - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 rejected - - args: - - porchctl - - rpkg - - get - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - - --namespace=rpkg-lifecycle - stdout: | - NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 lifecycle-package lifecycle false Draft git - - args: - - porchctl - - rpkg - - propose-delete - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - - --namespace=rpkg-lifecycle - exitCode: 1 - stderr: | - can only propose published packages for deletion; package git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 is not published - Error: errors: - can only propose published packages for deletion; package git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 is not published - - args: - - porchctl - - rpkg - - propose - - --namespace=rpkg-lifecycle - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - stdout: | - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 proposed - - args: - - porchctl - - rpkg - - get - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - - --namespace=rpkg-lifecycle - stdout: | - NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 lifecycle-package lifecycle false Proposed git - - args: - - porchctl - - rpkg - - approve - - --namespace=rpkg-lifecycle - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - stdout: | - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 approved - - args: - - porchctl - - rpkg - - get - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - - --namespace=rpkg-lifecycle - stdout: | - NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 lifecycle-package lifecycle v1 true Published git - - args: - - porchctl - - rpkg - - delete - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - - --namespace=rpkg-lifecycle - exitCode: 1 - stderr: | - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 failed (admission webhook "packagerevdeletion.google.com" denied the request: failed to delete package revision "git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034": published PackageRevisions must be proposed for deletion by setting spec.lifecycle to 'DeletionProposed' prior to deletion) - Error: errors: - admission webhook "packagerevdeletion.google.com" denied the request: failed to delete package revision "git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034": published PackageRevisions must be proposed for deletion by setting spec.lifecycle to 'DeletionProposed' prior to deletion - - args: - - porchctl - - rpkg - - propose-delete - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - - --namespace=rpkg-lifecycle - stdout: | - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 proposed for deletion - - args: - - porchctl - - rpkg - - propose-delete - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - - --namespace=rpkg-lifecycle - stderr: | - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 is already proposed for deletion - - args: - - porchctl - - rpkg - - get - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - - --namespace=rpkg-lifecycle - stdout: | - NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 lifecycle-package lifecycle v1 true DeletionProposed git - - args: - - porchctl - - rpkg - - reject - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - - --namespace=rpkg-lifecycle - stdout: | - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 no longer proposed for deletion - - args: - - porchctl - - rpkg - - reject - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - - --namespace=rpkg-lifecycle - stderr: | - cannot reject git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 with lifecycle 'Published' - Error: errors: - cannot reject git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 with lifecycle 'Published' - exitCode: 1 - - args: - - porchctl - - rpkg - - get - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - - --namespace=rpkg-lifecycle - stdout: | - NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 lifecycle-package lifecycle v1 true Published git - - args: - - porchctl - - rpkg - - propose-delete - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - - --namespace=rpkg-lifecycle - stdout: | - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 proposed for deletion - - args: - - porchctl - - rpkg - - get - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - - --namespace=rpkg-lifecycle - stdout: | - NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 lifecycle-package lifecycle v1 true DeletionProposed git - - args: - - porchctl - - rpkg - - delete - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - - --namespace=rpkg-lifecycle - stdout: | - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 deleted - - args: - - porchctl - - rpkg - - get - - git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034 - - --namespace=rpkg-lifecycle - stderr: "Error: the server could not find the requested resource (get packagerevisions.porch.kpt.dev git-017a8366a5e0d9b35ae6dc489d4d3f68046d6034) \n" - exitCode: 1 diff --git a/test/e2e/cli/testdata-local-server/rpkg-push/config.yaml b/test/e2e/cli/testdata-local-server/rpkg-push/config.yaml deleted file mode 100644 index 5666b314..00000000 --- a/test/e2e/cli/testdata-local-server/rpkg-push/config.yaml +++ /dev/null @@ -1,185 +0,0 @@ -commands: - - args: - - porchctl - - repo - - register - - --namespace=rpkg-push - - --name=git - - http://172.18.255.203:8080/rpkg-push - - args: - - porchctl - - rpkg - - init - - --namespace=rpkg-push - - --repository=git - - --workspace=push - - test-package - stdout: "git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f created\n" - - args: - - porchctl - - rpkg - - pull - - --namespace=rpkg-push - - git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f - stdout: | - apiVersion: config.kubernetes.io/v1 - items: - - apiVersion: "" - kind: KptRevisionMetadata - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/path: .KptRevisionMetadata - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: .KptRevisionMetadata - name: git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f - namespace: rpkg-push - uid: uid:test-package:push - - apiVersion: kpt.dev/v1 - info: - description: sample description - kind: Kptfile - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/local-config: "true" - config.kubernetes.io/path: Kptfile - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: Kptfile - name: test-package - - apiVersion: v1 - data: - name: example - kind: ConfigMap - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/local-config: "true" - config.kubernetes.io/path: package-context.yaml - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: package-context.yaml - name: kptfile.kpt.dev - kind: ResourceList - yaml: true - - args: - - porchctl - - rpkg - - push - - --namespace=rpkg-push - - git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f - stdin: | - apiVersion: config.kubernetes.io/v1 - items: - - apiVersion: "" - kind: KptRevisionMetadata - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/path: .KptRevisionMetadata - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: .KptRevisionMetadata - name: git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f - namespace: rpkg-push - uid: uid:test-package:push - - apiVersion: kpt.dev/v1 - info: - description: sample description - kind: Kptfile - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/local-config: "true" - config.kubernetes.io/path: Kptfile - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: Kptfile - name: test-package - - apiVersion: v1 - data: - name: example - kind: ConfigMap - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/local-config: "true" - config.kubernetes.io/path: package-context.yaml - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: package-context.yaml - name: kptfile.kpt.dev - kind: ResourceList - yaml: true - exitCode: 1 - stderr: "Error: Internal error occurred: resourceVersion must be specified for an update \n" - - args: - - porchctl - - rpkg - - pull - - --namespace=rpkg-push - - git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f - - /tmp/porch-e2e/rpkg-push-git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f - - args: - - kpt - - fn - - eval - - --image - - gcr.io/kpt-fn/search-replace:v0.2.0 - - --match-kind - - Kptfile - - /tmp/porch-e2e/rpkg-push-git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f - - -- - - by-path=info.description - - put-value=Updated Test Package Description - stderr: "[RUNNING] \"gcr.io/kpt-fn/search-replace:v0.2.0\" on 1 resource(s)\n Results:\n [info] info.description: Mutated field value to \"Updated Test Package Description\"\n" - - args: - - porchctl - - rpkg - - push - - --namespace=rpkg-push - - git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f - - /tmp/porch-e2e/rpkg-push-git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f - stdout: "git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f pushed\n" - - args: - - porchctl - - rpkg - - pull - - --namespace=rpkg-push - - git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f - stdout: | - apiVersion: config.kubernetes.io/v1 - items: - - apiVersion: "" - kind: KptRevisionMetadata - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/path: .KptRevisionMetadata - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: .KptRevisionMetadata - name: git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f - namespace: rpkg-push - uid: uid:test-package:push - - apiVersion: kpt.dev/v1 - info: - description: Updated Test Package Description - kind: Kptfile - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/local-config: "true" - config.kubernetes.io/path: Kptfile - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: Kptfile - name: test-package - - apiVersion: v1 - data: - name: example - kind: ConfigMap - metadata: - annotations: - config.kubernetes.io/index: "0" - config.kubernetes.io/local-config: "true" - config.kubernetes.io/path: package-context.yaml - internal.config.kubernetes.io/index: "0" - internal.config.kubernetes.io/path: package-context.yaml - name: kptfile.kpt.dev - kind: ResourceList - yaml: true diff --git a/test/e2e/cli/testdata-local-server/rpkg-update/config.yaml b/test/e2e/cli/testdata-local-server/rpkg-update/config.yaml deleted file mode 100644 index b795875c..00000000 --- a/test/e2e/cli/testdata-local-server/rpkg-update/config.yaml +++ /dev/null @@ -1,150 +0,0 @@ -commands: - - args: - - porchctl - - repo - - register - - --namespace=rpkg-update - - --name=git - - http://172.18.255.203:8080/rpkg-update - - args: - - porchctl - - rpkg - - clone - - --namespace=rpkg-update - - https://github.com/platkrm/test-blueprints.git - - --directory=basens - - --ref=basens/v1 - - --repository=git - - --workspace=update-1 - - basens-edit - stdout: "git-3f036055f7ba68706372cbe0c4b14d553794f7c4 created\n" - - args: - - porchctl - - rpkg - - clone - - --namespace=rpkg-update - - git-3f036055f7ba68706372cbe0c4b14d553794f7c4 - - --directory=basens - - --ref=basens/v1 - - --repository=git - - --workspace=update-2 - - basens-edit-clone - stdout: "git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 created\n" - - args: - - porchctl - - rpkg - - copy - - --namespace=rpkg-update - - --workspace=update-3 - - --replay-strategy=true - - git-3f036055f7ba68706372cbe0c4b14d553794f7c4 - stdout: "git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 created\n" - - args: - - porchctl - - rpkg - - propose - - --namespace=rpkg-update - - git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 - stdout: "git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 proposed\n" - - args: - - porchctl - - rpkg - - approve - - --namespace=rpkg-update - - git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 - stdout: "git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 approved\n" - - args: - - porchctl - - rpkg - - get - - --namespace=rpkg-update - stdout: | - NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY - git-3f036055f7ba68706372cbe0c4b14d553794f7c4 basens-edit update-1 false Draft git - git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 basens-edit update-3 v1 true Published git - git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 basens-edit-clone update-2 false Draft git - - args: - - porchctl - - rpkg - - update - - --namespace=rpkg-update - - --discover=upstream - - git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 - stdout: | - PACKAGE REVISION UPSTREAM REPOSITORY UPSTREAM UPDATES - git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 git v1 - - args: - - porchctl - - rpkg - - update - - --namespace=rpkg-update - - --discover=upstream - stdout: | - PACKAGE REVISION UPSTREAM REPOSITORY UPSTREAM UPDATES - git-3f036055f7ba68706372cbe0c4b14d553794f7c4 No update available - git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 No update available - git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 git v1 - - args: - - porchctl - - rpkg - - update - - --namespace=rpkg-update - - --discover=downstream - stdout: | - PACKAGE REVISION DOWNSTREAM PACKAGE DOWNSTREAM UPDATE - git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 (draft "update-1")->v1 - - args: - - porchctl - - rpkg - - update - - --namespace=rpkg-update - - --revision=v1 - - git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 - stdout: "git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 updated\n" - - args: - - porchctl - - rpkg - - update - - --namespace=rpkg-update - - --discover=upstream - stdout: | - PACKAGE REVISION UPSTREAM REPOSITORY UPSTREAM UPDATES - git-3f036055f7ba68706372cbe0c4b14d553794f7c4 No update available - git-7fcdd499f0790ac3bd8f805e3e5e00825641eb60 No update available - git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 git No update available - - args: - - porchctl - - rpkg - - pull - - --namespace=rpkg-update - - git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 - - /tmp/porch-e2e/pkg-update-git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 - - args: - - kpt - - fn - - eval - - --image - - gcr.io/kpt-fn/search-replace:v0.2.0 - - --match-kind - - Kptfile - - /tmp/porch-e2e/pkg-update-git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 - - -- - - by-path=upstreamLock.git.ref - - put-value=invalid - stderr: "[RUNNING] \"gcr.io/kpt-fn/search-replace:v0.2.0\" on 1 resource(s)\n Results:\n [info] upstreamLock.git.ref: Mutated field value to \"invalid\"\n" - - args: - - porchctl - - rpkg - - push - - --namespace=rpkg-update - - git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 - - /tmp/porch-e2e/pkg-update-git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 - stdout: "git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0 pushed\n" - - args: - - porchctl - - rpkg - - update - - --namespace=rpkg-update - - --discover=upstream - stderr: "Error: could not parse upstreamLock in Kptfile of package \"git-7ab0219ace10c1081a8b40a6b97d5da58bdb62e0\": malformed upstreamLock.Git.Ref \"invalid\" \n" - exitCode: 1 diff --git a/test/e2e/cli/testdata/git-server.yaml b/test/e2e/cli/testdata/git-server.yaml index 78f15803..32946775 100644 --- a/test/e2e/cli/testdata/git-server.yaml +++ b/test/e2e/cli/testdata/git-server.yaml @@ -31,6 +31,7 @@ metadata: name: git-server namespace: test-git-namespace spec: + type: ClusterIP selector: app: git-server ports: diff --git a/test/e2e/cli/testdata/rpkg-init/config.yaml b/test/e2e/cli/testdata/rpkg-init/config.yaml index 46354cdb..31bfc970 100644 --- a/test/e2e/cli/testdata/rpkg-init/config.yaml +++ b/test/e2e/cli/testdata/rpkg-init/config.yaml @@ -10,11 +10,12 @@ commands: - porchctl - repo - get + - --no-headers - --namespace=rpkg-init - --output=custom-columns=NAME:.metadata.name,ADDRESS:.spec.git.repo,BRANCH:.spec.git.branch,DIR:.spec.git.directory stdout: | - NAME ADDRESS BRANCH DIR git http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-init main / + ignoreWhitespace: true - args: - porchctl - rpkg From 0b10abed839a2660adf5cd95c82055472ecbb870 Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Tue, 28 May 2024 10:03:14 +0200 Subject: [PATCH 12/23] test/e2e/cli: Implement a better way to determine if porch server is running in-cluster or not --- .../porch-development-environment/README.md | 2 +- test/e2e/cli/cli_test.go | 9 +++++---- test/e2e/cli/cluster.go | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/docs/tutorials/porch-development-environment/README.md b/docs/tutorials/porch-development-environment/README.md index da9d226e..7a1c2d41 100644 --- a/docs/tutorials/porch-development-environment/README.md +++ b/docs/tutorials/porch-development-environment/README.md @@ -204,7 +204,7 @@ E2E=1 go test -v ./test/e2e To test porch via its CLI: ``` -E2E=local-server go test -v ./test/e2e/cli +E2E=1 go test -v ./test/e2e/cli ``` # Create Repositories using your local Porch server diff --git a/test/e2e/cli/cli_test.go b/test/e2e/cli/cli_test.go index c5fb9ddb..52fc2f24 100644 --- a/test/e2e/cli/cli_test.go +++ b/test/e2e/cli/cli_test.go @@ -47,7 +47,7 @@ func TestPorch(t *testing.T) { if err != nil { t.Fatalf("Failed to get absolute path to testdata directory: %v", err) } - runTests(t, abs, e2e != "local-server") + runTests(t, abs) } func runUtilityCommand(t *testing.T, command string, args ...string) error { @@ -56,10 +56,10 @@ func runUtilityCommand(t *testing.T, command string, args ...string) error { return cmd.Run() } -func runTests(t *testing.T, path string, isPorchInCluster bool) { +func runTests(t *testing.T, path string) { var searchAndReplace = map[string]string{} - gitServerURL := startGitServer(t, path, isPorchInCluster) + gitServerURL := startGitServer(t, path) if gitServerURL != defaultTestGitServerUrl { searchAndReplace[defaultTestGitServerUrl] = gitServerURL } @@ -229,7 +229,8 @@ func reorderYamlStdout(t *testing.T, buf *bytes.Buffer) { } } -func startGitServer(t *testing.T, path string, isPorchInCluster bool) string { +func startGitServer(t *testing.T, path string) string { + isPorchInCluster := IsPorchServerRunningInCluster(t) gitServerImage := GetGitServerImageName(t) t.Logf("Git Image: %s", gitServerImage) diff --git a/test/e2e/cli/cluster.go b/test/e2e/cli/cluster.go index 3224f794..d8f26fd4 100644 --- a/test/e2e/cli/cluster.go +++ b/test/e2e/cli/cluster.go @@ -26,6 +26,22 @@ const ( TestGitServerImage = "test-git-server" ) +func IsPorchServerRunningInCluster(t *testing.T) bool { + cmd := exec.Command("kubectl", "get", "--namespace=porch-system", "service", "api", + "--output=jsonpath={.spec.selector}") + + var stderr bytes.Buffer + var stdout bytes.Buffer + + cmd.Stderr = &stderr + cmd.Stdout = &stdout + + if err := cmd.Run(); err != nil || stderr.String() != "" { + t.Fatalf("Error when getting porch api Service: %v: %s", err, stderr.String()) + } + return stdout.String() != "" +} + func GetGitServerImageName(t *testing.T) string { cmd := exec.Command("kubectl", "get", "pods", "--selector=app=function-runner", "--namespace=porch-system", "--output=jsonpath={.items[0].spec.containers[0].image}") From fc50cf3951ad7f65d2c800842d9fdcfb99798f59 Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Tue, 28 May 2024 10:05:19 +0200 Subject: [PATCH 13/23] test/e2e: minor improvements --- scripts/clean-kind-only-e2e-test.sh | 12 ++++++++---- test/e2e/suite.go | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/clean-kind-only-e2e-test.sh b/scripts/clean-kind-only-e2e-test.sh index cc4a587f..d064f2ee 100755 --- a/scripts/clean-kind-only-e2e-test.sh +++ b/scripts/clean-kind-only-e2e-test.sh @@ -25,10 +25,14 @@ cd $PORCH_DIR kind delete cluster --name dev || true kind create cluster --name dev make run-in-kind-kpt IMAGE_TAG='test' KIND_CONTEXT_NAME='dev' KUBECONFIG=$KUBECONFIG -kubectl rollout status deployment porch-controllers --namespace porch-system -kubectl rollout status deployment porch-server --namespace porch-system -kubectl rollout status deployment function-runner --namespace porch-system -sleep 2 +for deployment in porch-controllers porch-server function-runner; do + kubectl rollout status deployment $deployment --namespace porch-system + kubectl wait --namespace porch-system deploy $deployment \ + --for=condition=available \ + --timeout=90s +done + +sleep 5 echo "--- test/e2e ---" E2E=1 go test -failfast -v ./test/e2e diff --git a/test/e2e/suite.go b/test/e2e/suite.go index bee7f246..cf5a8c7f 100644 --- a/test/e2e/suite.go +++ b/test/e2e/suite.go @@ -621,7 +621,7 @@ func (t *TestSuite) createInClusterGitServer(ctx context.Context, exposeByLoadBa if exposeByLoadBalancer { var svc coreapi.Service t.client.Get(ctx, serviceKey, &svc) - if len(svc.Status.LoadBalancer.Ingress) == 0 { + if len(svc.Status.LoadBalancer.Ingress) == 0 || svc.Status.LoadBalancer.Ingress[0].IP == "" { t.Logf("waiting for LoadBalancer to be assigned: %+v", svc) continue } From a095238e47cd608875890451f38dc9a73095dd29 Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Tue, 28 May 2024 10:27:04 +0200 Subject: [PATCH 14/23] test/e2e: minor improvements --- scripts/clean-kind-only-e2e-test.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/clean-kind-only-e2e-test.sh b/scripts/clean-kind-only-e2e-test.sh index d064f2ee..7e2b0711 100755 --- a/scripts/clean-kind-only-e2e-test.sh +++ b/scripts/clean-kind-only-e2e-test.sh @@ -31,6 +31,9 @@ for deployment in porch-controllers porch-server function-runner; do --for=condition=available \ --timeout=90s done +kubectl wait --namespace porch-system pod --selector=app=function-runner \ + --for=condition=ready \ + --timeout=90s sleep 5 From 85ad0bd10b235afab359a099990b8e75e31a323c Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Tue, 28 May 2024 12:21:42 +0200 Subject: [PATCH 15/23] test/e2e: Create a localhost webhook in case the porch server is running out-of-cluster --- .vscode/launch.json | 2 +- .../porch-development-environment/README.md | 2 +- pkg/apiserver/apiserver.go | 8 +- pkg/apiserver/webhooks.go | 135 ++++++++++++++---- pkg/apiserver/webhooks_test.go | 14 +- test/e2e/e2e_test.go | 1 + test/e2e/e2e_test_utils.go | 4 +- 7 files changed, 124 insertions(+), 42 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 39bddca4..06ab0034 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -21,7 +21,7 @@ "cwd": "${workspaceFolder}", "env": { "CERT_STORAGE_DIR": "${workspaceFolder}/.build/pki/tmp", - "CERT_NAMESPACE": "porch-system" + "WEBHOOK_HOST": "localhost" } }, { diff --git a/docs/tutorials/porch-development-environment/README.md b/docs/tutorials/porch-development-environment/README.md index 7a1c2d41..9767e715 100644 --- a/docs/tutorials/porch-development-environment/README.md +++ b/docs/tutorials/porch-development-environment/README.md @@ -197,7 +197,7 @@ make test ### Run the end-to-end tests -To test porch directly via its API: +To test porch directly via its Kubernetes API: ``` E2E=1 go test -v ./test/e2e ``` diff --git a/pkg/apiserver/apiserver.go b/pkg/apiserver/apiserver.go index b0492d0c..27732306 100644 --- a/pkg/apiserver/apiserver.go +++ b/pkg/apiserver/apiserver.go @@ -284,14 +284,12 @@ func (c completedConfig) New() (*PorchServer, error) { func (s *PorchServer) Run(ctx context.Context) error { porch.RunBackground(ctx, s.coreClient, s.cache) - webhookNs, found := os.LookupEnv("CERT_NAMESPACE") - if !found || strings.TrimSpace(webhookNs) == "" { - webhookNs = "porch-system" - } + // TODO: Reconsider if the existence of CERT_STORAGE_DIR was a good inidcator for webhook setup, + // but for now we keep backward compatiblity certStorageDir, found := os.LookupEnv("CERT_STORAGE_DIR") if found && strings.TrimSpace(certStorageDir) != "" { - if err := setupWebhooks(ctx, webhookNs, certStorageDir); err != nil { + if err := setupWebhooks(ctx); err != nil { klog.Errorf("%v\n", err) return err } diff --git a/pkg/apiserver/webhooks.go b/pkg/apiserver/webhooks.go index b2735b85..7f3e1518 100644 --- a/pkg/apiserver/webhooks.go +++ b/pkg/apiserver/webhooks.go @@ -30,6 +30,7 @@ import ( "net/http" "os" "path/filepath" + "strconv" "time" "github.com/nephio-project/porch/api/porch/v1alpha1" @@ -47,29 +48,77 @@ import ( ) const ( - webhookServicePort = 8443 - serverEndpoint = "/validate-deletion" + webhookServicePort int32 = 8443 + serverEndpoint = "/validate-deletion" ) -func setupWebhooks(ctx context.Context, webhookNs string, certStorageDir string) error { - caBytes, err := createCerts(webhookNs, certStorageDir) +type WebhookType string + +const ( + WebhookTypeService WebhookType = "service" + WebhookTypeUrl WebhookType = "url" +) + +// WebhookConfig defines the configuration for the PackageRevision deletion webhook +type WebhookConfig struct { + Type WebhookType + ServiceName string // only used if Type == WebhookTypeService + ServiceNamespace string // only used if Type == WebhookTypeService + Host string // only used if Type == WebhookTypeUrl + Path string + Port int32 + CertStorageDir string +} + +func NewWebhookConfig() *WebhookConfig { + var cfg WebhookConfig + // NOTE: CERT_NAMESPACE is supported for backward compatibility. + // TODO: We may consider using only WEBHOOK_SERVICE_NAMESPACE instead. + if hasEnv("CERT_NAMESPACE") || + hasEnv("WEBHOOK_SERVICE_NAME") || + hasEnv("WEBHOOK_SERVICE_NAMESPACE") || + !hasEnv("WEBHOOK_HOST") { + + cfg.Type = WebhookTypeService + cfg.ServiceName = getEnv("WEBHOOK_SERVICE_NAME", "api") + cfg.ServiceNamespace = getEnv("WEBHOOK_SERVICE_NAMESPACE", "porch-system") + cfg.ServiceNamespace = getEnv("CERT_NAMESPACE", cfg.ServiceNamespace) + cfg.Host = fmt.Sprintf("%s.%s.svc", cfg.ServiceName, cfg.ServiceNamespace) + } else { + cfg.Type = WebhookTypeUrl + cfg.Host = getEnv("WEBHOOK_HOST", "localhost") + } + cfg.Path = serverEndpoint + cfg.Port = getEnvInt32("WEBHOOK_PORT", webhookServicePort) + cfg.CertStorageDir = getEnv("CERT_STORAGE_DIR", "/tmp/cert") + return &cfg +} + +func setupWebhooks(ctx context.Context) error { + cfg := NewWebhookConfig() + caBytes, err := createCerts(cfg) if err != nil { return err } - if err := createValidatingWebhook(ctx, webhookNs, caBytes); err != nil { + if err := createValidatingWebhook(ctx, cfg, caBytes); err != nil { return err } - if err := runWebhookServer(certStorageDir); err != nil { + if err := runWebhookServer(cfg.CertStorageDir); err != nil { return err } return nil } -func createCerts(webhookNs string, certStorageDir string) ([]byte, error) { - klog.Infoln("creating self-signing TLS cert and key with namespace " + webhookNs + " in directory " + certStorageDir) - dnsNames := []string{"api", - "api." + webhookNs, "api." + webhookNs + ".svc"} - commonName := "api." + webhookNs + ".svc" +func createCerts(cfg *WebhookConfig) ([]byte, error) { + klog.Infof("creating self-signing TLS cert and key for %q in directory %s", cfg.Host, cfg.CertStorageDir) + commonName := cfg.Host + dnsNames := []string{commonName} + if cfg.Type == WebhookTypeService { + dnsNames = append(dnsNames, cfg.ServiceName) + dnsNames = append(dnsNames, fmt.Sprintf("%s.%s", cfg.ServiceName, cfg.ServiceNamespace)) + dnsNames = append(dnsNames, fmt.Sprintf("%s.%s.svc", cfg.ServiceName, cfg.ServiceNamespace)) + dnsNames = append(dnsNames, fmt.Sprintf("%s.%s.svc.cluster.local", cfg.ServiceName, cfg.ServiceNamespace)) + } var caPEM, serverCertPEM, serverPrivateKeyPEM *bytes.Buffer // CA config @@ -134,15 +183,15 @@ func createCerts(webhookNs string, certStorageDir string) ([]byte, error) { Bytes: x509.MarshalPKCS1PrivateKey(serverPrivateKey), }) - err = os.MkdirAll(certStorageDir, 0777) + err = os.MkdirAll(cfg.CertStorageDir, 0777) if err != nil { return nil, err } - err = WriteFile(filepath.Join(certStorageDir, "tls.crt"), serverCertPEM.Bytes()) + err = WriteFile(filepath.Join(cfg.CertStorageDir, "tls.crt"), serverCertPEM.Bytes()) if err != nil { return nil, err } - err = WriteFile(filepath.Join(certStorageDir, "tls.key"), serverPrivateKeyPEM.Bytes()) + err = WriteFile(filepath.Join(cfg.CertStorageDir, "tls.key"), serverPrivateKeyPEM.Bytes()) if err != nil { return nil, err } @@ -165,23 +214,20 @@ func WriteFile(filepath string, c []byte) error { return nil } -func createValidatingWebhook(ctx context.Context, webhookNs string, caCert []byte) error { - klog.Infoln("Creating validating webhook with namespace " + webhookNs) +func createValidatingWebhook(ctx context.Context, cfg *WebhookConfig, caCert []byte) error { + + klog.Infof("Creating validating webhook for %s:%d", cfg.Host, cfg.Port) - cfg := ctrl.GetConfigOrDie() - kubeClient, err := kubernetes.NewForConfig(cfg) + kubeConfig := ctrl.GetConfigOrDie() + kubeClient, err := kubernetes.NewForConfig(kubeConfig) if err != nil { return fmt.Errorf("failed to setup kubeClient: %v", err) } var ( - webhookNamespace = webhookNs validationCfgName = "packagerev-deletion-validating-webhook" - webhookService = "api" - path = serverEndpoint fail = admissionregistrationv1.Fail none = admissionregistrationv1.SideEffectClassNone - port = int32(webhookServicePort) ) validateConfig := &admissionregistrationv1.ValidatingWebhookConfiguration{ @@ -192,12 +238,6 @@ func createValidatingWebhook(ctx context.Context, webhookNs string, caCert []byt Name: "packagerevdeletion.google.com", ClientConfig: admissionregistrationv1.WebhookClientConfig{ CABundle: caCert, // CA bundle created earlier - Service: &admissionregistrationv1.ServiceReference{ - Name: webhookService, - Namespace: webhookNamespace, - Path: &path, - Port: &port, - }, }, Rules: []admissionregistrationv1.RuleWithOperations{{Operations: []admissionregistrationv1.OperationType{ admissionregistrationv1.Delete}, @@ -212,6 +252,20 @@ func createValidatingWebhook(ctx context.Context, webhookNs string, caCert []byt FailurePolicy: &fail, }}, } + switch cfg.Type { + case WebhookTypeService: + validateConfig.Webhooks[0].ClientConfig.Service = &admissionregistrationv1.ServiceReference{ + Name: cfg.ServiceName, + Namespace: cfg.ServiceNamespace, + Path: &cfg.Path, + Port: &cfg.Port, + } + case WebhookTypeUrl: + url := fmt.Sprintf("https://%s:%d%s", cfg.Host, cfg.Port, cfg.Path) + validateConfig.Webhooks[0].ClientConfig.URL = &url + default: + return fmt.Errorf("invalid webhook type: %s", cfg.Type) + } if err := kubeClient.AdmissionregistrationV1().ValidatingWebhookConfigurations().Delete(ctx, validationCfgName, metav1.DeleteOptions{}); err != nil { klog.Error("failed to delete existing webhook: %w", err) @@ -369,3 +423,28 @@ func writeErr(errMsg string, w *http.ResponseWriter) { klog.Errorf("could not write error message: %v", err) } } + +func hasEnv(key string) bool { + _, found := os.LookupEnv(key) + return found +} + +func getEnv(key string, defaultValue string) string { + value, found := os.LookupEnv(key) + if !found { + return defaultValue + } + return value +} + +func getEnvInt32(key string, defaultValue int32) int32 { + value, found := os.LookupEnv(key) + if !found { + return defaultValue + } + i64, err := strconv.ParseInt(value, 10, 32) + if err != nil { + panic("could not parse int32 from environment variable: " + key) + } + return int32(i64) // this is safe because of the size parameter of the ParseInt call +} diff --git a/pkg/apiserver/webhooks_test.go b/pkg/apiserver/webhooks_test.go index 84aad665..2a0c18fa 100644 --- a/pkg/apiserver/webhooks_test.go +++ b/pkg/apiserver/webhooks_test.go @@ -31,22 +31,26 @@ import ( ) func TestCreateCerts(t *testing.T) { - dir := t.TempDir() + webhookCfg := WebhookConfig{ + Type: WebhookTypeUrl, + Host: "localhost", + CertStorageDir: t.TempDir(), + } defer func() { - require.NoError(t, os.RemoveAll(dir)) + require.NoError(t, os.RemoveAll(webhookCfg.CertStorageDir)) }() - caCert, err := createCerts("", dir) + caCert, err := createCerts(&webhookCfg) require.NoError(t, err) caStr := strings.TrimSpace(string(caCert)) require.True(t, strings.HasPrefix(caStr, "-----BEGIN CERTIFICATE-----\n")) require.True(t, strings.HasSuffix(caStr, "\n-----END CERTIFICATE-----")) - crt, err := os.ReadFile(filepath.Join(dir, "tls.crt")) + crt, err := os.ReadFile(filepath.Join(webhookCfg.CertStorageDir, "tls.crt")) require.NoError(t, err) - key, err := os.ReadFile(filepath.Join(dir, "tls.key")) + key, err := os.ReadFile(filepath.Join(webhookCfg.CertStorageDir, "tls.key")) require.NoError(t, err) crtStr := strings.TrimSpace(string(crt)) diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index fa2891bf..8f75fcbf 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -240,6 +240,7 @@ func (t *PorchSuite) TestGitRepository(ctx context.Context) { func (t *PorchSuite) TestGitRepositoryWithReleaseTagsAndDirectory(ctx context.Context) { t.registerGitRepositoryF(ctx, kptRepo, "kpt-repo", "package-examples") + t.Log("Listing PackageRevisions in " + t.namespace) var list porchapi.PackageRevisionList t.ListF(ctx, &list, client.InNamespace(t.namespace)) diff --git a/test/e2e/e2e_test_utils.go b/test/e2e/e2e_test_utils.go index d86a4187..ce559589 100644 --- a/test/e2e/e2e_test_utils.go +++ b/test/e2e/e2e_test_utils.go @@ -208,7 +208,7 @@ func (t *TestSuite) mustNotExist(ctx context.Context, obj client.Object) { } } -// waitUntilRepositoryReady waits for up to 10 seconds for the repository with the +// waitUntilRepositoryReady waits for up to 60 seconds for the repository with the // provided name and namespace is ready, i.e. the Ready condition is true. // It also queries for Functions and PackageRevisions, to ensure these are also // ready - this is an artifact of the way we've implemented the aggregated apiserver, @@ -219,7 +219,7 @@ func (t *TestSuite) waitUntilRepositoryReady(ctx context.Context, name, namespac Namespace: namespace, } var innerErr error - err := wait.PollImmediateWithContext(ctx, time.Second, 10*time.Second, func(ctx context.Context) (bool, error) { + err := wait.PollImmediateWithContext(ctx, time.Second, 60*time.Second, func(ctx context.Context) (bool, error) { var repo configapi.Repository if err := t.client.Get(ctx, nn, &repo); err != nil { innerErr = err From 7645cb1165b023a2453b63c97fe3205289af0b44 Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Tue, 28 May 2024 13:54:16 +0200 Subject: [PATCH 16/23] Fix: delegating webhook port from config to the actual server --- pkg/apiserver/webhooks.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pkg/apiserver/webhooks.go b/pkg/apiserver/webhooks.go index 7f3e1518..30ae02ee 100644 --- a/pkg/apiserver/webhooks.go +++ b/pkg/apiserver/webhooks.go @@ -48,8 +48,7 @@ import ( ) const ( - webhookServicePort int32 = 8443 - serverEndpoint = "/validate-deletion" + serverEndpoint = "/validate-deletion" ) type WebhookType string @@ -89,7 +88,7 @@ func NewWebhookConfig() *WebhookConfig { cfg.Host = getEnv("WEBHOOK_HOST", "localhost") } cfg.Path = serverEndpoint - cfg.Port = getEnvInt32("WEBHOOK_PORT", webhookServicePort) + cfg.Port = getEnvInt32("WEBHOOK_PORT", 8443) cfg.CertStorageDir = getEnv("CERT_STORAGE_DIR", "/tmp/cert") return &cfg } @@ -103,7 +102,7 @@ func setupWebhooks(ctx context.Context) error { if err := createValidatingWebhook(ctx, cfg, caBytes); err != nil { return err } - if err := runWebhookServer(cfg.CertStorageDir); err != nil { + if err := runWebhookServer(cfg); err != nil { return err } return nil @@ -280,9 +279,9 @@ func createValidatingWebhook(ctx context.Context, cfg *WebhookConfig, caCert []b return nil } -func runWebhookServer(certStorageDir string) error { - certFile := filepath.Join(certStorageDir, "tls.crt") - keyFile := filepath.Join(certStorageDir, "tls.key") +func runWebhookServer(cfg *WebhookConfig) error { + certFile := filepath.Join(cfg.CertStorageDir, "tls.crt") + keyFile := filepath.Join(cfg.CertStorageDir, "tls.key") cert, err := tls.LoadX509KeyPair(certFile, keyFile) if err != nil { @@ -291,7 +290,7 @@ func runWebhookServer(certStorageDir string) error { klog.Infoln("Starting webhook server") http.HandleFunc(serverEndpoint, validateDeletion) server := http.Server{ - Addr: fmt.Sprintf(":%d", webhookServicePort), + Addr: fmt.Sprintf(":%d", cfg.Port), TLSConfig: &tls.Config{ Certificates: []tls.Certificate{cert}, }, From a59f38e3255dd849ed9feb2bcbf46ec871c39fd7 Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Tue, 28 May 2024 15:26:43 +0200 Subject: [PATCH 17/23] Increase wait time in clean-...-test.sh --- scripts/clean-kind-only-e2e-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/clean-kind-only-e2e-test.sh b/scripts/clean-kind-only-e2e-test.sh index 7e2b0711..60cff70b 100755 --- a/scripts/clean-kind-only-e2e-test.sh +++ b/scripts/clean-kind-only-e2e-test.sh @@ -35,7 +35,7 @@ kubectl wait --namespace porch-system pod --selector=app=function-runner \ --for=condition=ready \ --timeout=90s -sleep 5 +sleep 15 echo "--- test/e2e ---" E2E=1 go test -failfast -v ./test/e2e From 724be632c70fa3090bbf6a5436ea7a2362ed54b6 Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Tue, 28 May 2024 16:18:35 +0200 Subject: [PATCH 18/23] Bump up local kube-apiserver version to 1.30.1 to keep it aligned with the go-client module --- build/Dockerfile.apiserver | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/build/Dockerfile.apiserver b/build/Dockerfile.apiserver index 0cacc1ce..629970ad 100644 --- a/build/Dockerfile.apiserver +++ b/build/Dockerfile.apiserver @@ -15,14 +15,13 @@ FROM golang:1.22.2-bookworm as builder WORKDIR /workspace/src -RUN git clone https://github.com/kubernetes/kubernetes --branch v1.23.2 --depth=1 +RUN git clone https://github.com/kubernetes/kubernetes --branch v1.30.1 --depth=1 WORKDIR /workspace/src/kubernetes RUN apt-get update && apt-get install --yes rsync -RUN make generated_files -RUN CGO_ENABLED=0 go build -o /workspace/artifacts/kube-apiserver ./cmd/kube-apiserver +RUN make kube-apiserver FROM gcr.io/distroless/static -COPY --from=builder /workspace/artifacts/kube-apiserver /kube-apiserver +COPY --from=builder /workspace/src/kubernetes/_output/local/bin/linux/amd64/kube-apiserver /kube-apiserver #USER 65532:65532 From de4c87d570ccbcf51337c2072c8108ae8fe4d066 Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Wed, 29 May 2024 14:10:56 +0200 Subject: [PATCH 19/23] Revert irrelevant changes to simplify the PR --- deployments/local/porch-api-endpoints.yaml | 3 ++- docs/tutorials/porch-development-environment/README.md | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/deployments/local/porch-api-endpoints.yaml b/deployments/local/porch-api-endpoints.yaml index e6723091..98abbde6 100644 --- a/deployments/local/porch-api-endpoints.yaml +++ b/deployments/local/porch-api-endpoints.yaml @@ -9,7 +9,8 @@ subsets: - addresses: - ip: 172.17.0.1 ports: - - name: api + - appProtocol: https + name: api port: 4443 protocol: TCP - name: webhooks diff --git a/docs/tutorials/porch-development-environment/README.md b/docs/tutorials/porch-development-environment/README.md index 9767e715..7a1c2d41 100644 --- a/docs/tutorials/porch-development-environment/README.md +++ b/docs/tutorials/porch-development-environment/README.md @@ -197,7 +197,7 @@ make test ### Run the end-to-end tests -To test porch directly via its Kubernetes API: +To test porch directly via its API: ``` E2E=1 go test -v ./test/e2e ``` From db4adae4162ccfae97932d666e520a1250980809 Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Mon, 3 Jun 2024 14:15:06 +0200 Subject: [PATCH 20/23] Fixing changes proposed by nagygergo during review Co-authored-by: Gergely Nagy --- .vscode/launch.json | 3 ++- test/e2e/e2e_test.go | 35 ++++++----------------------------- test/e2e/e2e_test_utils.go | 19 ++++++++++++------- 3 files changed, 20 insertions(+), 37 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 06ab0034..1bd0aedf 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -15,8 +15,9 @@ // "--v=7", // "--standalone-debug-mode", "--kubeconfig=${env:KUBECONFIG}", + "--cache-directory=${workspaceFolder}/.cache", "--function-runner=172.18.255.201:9445", - "--repo-sync-frequency=60s", + "--repo-sync-frequency=60s" ], "cwd": "${workspaceFolder}", "env": { diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 8f75fcbf..647761fb 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -1080,7 +1080,7 @@ func (t *PorchSuite) TestProposeDeleteAndUndo(ctx context.Context) { t.UpdateApprovalF(ctx, &pkg, metav1.UpdateOptions{}) t.mustExist(ctx, client.ObjectKey{Namespace: t.namespace, Name: created.Name}, &pkg) - t.waitUntilMainBranchPackageRevisionExists(ctx, packageName) + _ = t.waitUntilPackageRevisionExists(ctx, repository, packageName, "main") var list porchapi.PackageRevisionList t.ListF(ctx, &list, client.InNamespace(t.namespace)) @@ -1232,35 +1232,14 @@ func (t *PorchSuite) TestDeleteFromMain(ctx context.Context) { t.mustExist(ctx, client.ObjectKey{Namespace: t.namespace, Name: createdSecond.Name}, &pkgSecond) t.Log("Wait for the 'main' revisions to get created") - var firstPkgRevFromMain porchapi.PackageRevision - var secondPkgRevFromMain porchapi.PackageRevision - var list porchapi.PackageRevisionList - finalDeadline := time.Now().Add(5 * time.Minute) - for firstPkgRevFromMain.Spec.WorkspaceName == "" || secondPkgRevFromMain.Spec.WorkspaceName == "" { - if time.Now().After(finalDeadline) { - t.Fatal("'main' package revisions not created in time") - return - } - time.Sleep(5 * time.Second) - - t.ListE(ctx, &list, client.InNamespace(t.namespace)) - for _, pkgrev := range list.Items { - if pkgrev.Spec.PackageName == packageNameFirst && pkgrev.Spec.Revision == "main" { - firstPkgRevFromMain = pkgrev - t.Logf("Found first package revision: %+v", firstPkgRevFromMain.Name) - } - if pkgrev.Spec.PackageName == packageNameSecond && pkgrev.Spec.Revision == "main" { - secondPkgRevFromMain = pkgrev - t.Logf("Found second package revision: %+v", secondPkgRevFromMain.Name) - } - } - } + firstPkgRevFromMain := t.waitUntilPackageRevisionExists(ctx, repository, packageNameFirst, "main") + secondPkgRevFromMain := t.waitUntilPackageRevisionExists(ctx, repository, packageNameSecond, "main") t.Log("Propose deletion of both main packages") firstPkgRevFromMain.Spec.Lifecycle = porchapi.PackageRevisionLifecycleDeletionProposed - t.UpdateApprovalF(ctx, &firstPkgRevFromMain, metav1.UpdateOptions{}) + t.UpdateApprovalF(ctx, firstPkgRevFromMain, metav1.UpdateOptions{}) secondPkgRevFromMain.Spec.Lifecycle = porchapi.PackageRevisionLifecycleDeletionProposed - t.UpdateApprovalF(ctx, &secondPkgRevFromMain, metav1.UpdateOptions{}) + t.UpdateApprovalF(ctx, secondPkgRevFromMain, metav1.UpdateOptions{}) t.Log("Delete the first package revision from main") t.DeleteE(ctx, &porchapi.PackageRevision{ @@ -1270,9 +1249,6 @@ func (t *PorchSuite) TestDeleteFromMain(ctx context.Context) { }, }) - // t.Log("Wait for the sync") - // time.Sleep(75 * time.Second) - t.Log("Delete the second package revision from main") t.DeleteE(ctx, &porchapi.PackageRevision{ ObjectMeta: metav1.ObjectMeta{ @@ -1282,6 +1258,7 @@ func (t *PorchSuite) TestDeleteFromMain(ctx context.Context) { }) // Propose and delete the original package revisions (cleanup) + var list porchapi.PackageRevisionList t.ListE(ctx, &list, client.InNamespace(t.namespace)) for _, pkgrev := range list.Items { t.Logf("Propose deletion and delete package revision: %s", pkgrev.Name) diff --git a/test/e2e/e2e_test_utils.go b/test/e2e/e2e_test_utils.go index ce559589..4703a4ce 100644 --- a/test/e2e/e2e_test_utils.go +++ b/test/e2e/e2e_test_utils.go @@ -333,24 +333,29 @@ func (t *TestSuite) waitUntilObjectDeleted(ctx context.Context, gvk schema.Group } } -func (t *TestSuite) waitUntilMainBranchPackageRevisionExists(ctx context.Context, pkgName string) { - err := wait.PollImmediateWithContext(ctx, time.Second, 120*time.Second, func(ctx context.Context) (done bool, err error) { +func (t *TestSuite) waitUntilPackageRevisionExists(ctx context.Context, repository string, pkgName string, revision string) *porchapi.PackageRevision { + + var foundPkgRev *porchapi.PackageRevision + timeout := 120 * time.Second + err := wait.PollImmediateWithContext(ctx, time.Second, timeout, func(ctx context.Context) (done bool, err error) { var pkgRevList porchapi.PackageRevisionList if err := t.client.List(ctx, &pkgRevList); err != nil { t.Logf("error listing packages: %v", err) return false, nil } for _, pkgRev := range pkgRevList.Items { - pkgName := pkgRev.Spec.PackageName - pkgRevision := pkgRev.Spec.Revision - if pkgRevision == "main" && - pkgName == pkgRev.Spec.PackageName { + if pkgRev.Spec.RepositoryName == repository && + pkgRev.Spec.PackageName == pkgName && + pkgRev.Spec.Revision == revision { + + foundPkgRev = &pkgRev return true, nil } } return false, nil }) if err != nil { - t.Fatalf("Main branch package revision for %s not found", pkgName) + t.Fatalf("Package revision (%v/%v/%v) not found in time (%v)", repository, pkgName, revision, timeout) } + return foundPkgRev } From e6efac30f674e1e2807db4a6041dc92f3b05524e Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Tue, 4 Jun 2024 13:37:41 +0200 Subject: [PATCH 21/23] Add make target for running E2E tests in a clean kind cluster --- Makefile | 14 +++++++++----- pkg/apiserver/webhooks.go | 2 +- scripts/clean-kind-only-e2e-test.sh | 11 ++++++----- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index db538960..76ebc9b4 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,6 @@ # limitations under the License. MYGOBIN := $(shell go env GOPATH)/bin -KUBECONFIG=$(CURDIR)/deployments/local/kubeconfig BUILDDIR=$(CURDIR)/.build CACHEDIR=$(CURDIR)/.cache DEPLOYCONFIGDIR=$(BUILDDIR)/deploy @@ -163,6 +162,11 @@ tidy: .PHONY: test-e2e test-e2e: E2E=1 go test -v -race --count=1 -failfast ./test/e2e + E2E=1 go test -v -race --count=1 -failfast ./test/e2e/cli + +.PHONY: test-e2e-clean +test-e2e-clean: + ./scripts/clean-kind-only-e2e-test.sh .PHONY: configure-git configure-git: @@ -178,13 +182,13 @@ PORCHCTL = $(BUILDDIR)/porchctl .PHONY: run-local run-local: porch - KUBECONFIG=$(KUBECONFIG) kubectl apply -f deployments/local/localconfig.yaml - KUBECONFIG=$(KUBECONFIG) kubectl apply -f api/porchconfig/v1alpha1/ - KUBECONFIG=$(KUBECONFIG) kubectl apply -f internal/api/porchinternal/v1alpha1/ + KUBECONFIG=$(CURDIR)/deployments/local/kubeconfig kubectl apply -f deployments/local/localconfig.yaml + KUBECONFIG=$(CURDIR)/deployments/local/kubeconfig kubectl apply -f api/porchconfig/v1alpha1/ + KUBECONFIG=$(CURDIR)/deployments/local/kubeconfig kubectl apply -f internal/api/porchinternal/v1alpha1/ $(PORCH) \ --secure-port 9443 \ --standalone-debug-mode \ - --kubeconfig="$(KUBECONFIG)" \ + --kubeconfig="$(CURDIR)/deployments/local/kubeconfig" \ --cache-directory="$(CACHEDIR)" \ --function-runner 192.168.8.202:9445 \ --repo-sync-frequency=60s diff --git a/pkg/apiserver/webhooks.go b/pkg/apiserver/webhooks.go index 30ae02ee..2c90cc7e 100644 --- a/pkg/apiserver/webhooks.go +++ b/pkg/apiserver/webhooks.go @@ -288,7 +288,7 @@ func runWebhookServer(cfg *WebhookConfig) error { return err } klog.Infoln("Starting webhook server") - http.HandleFunc(serverEndpoint, validateDeletion) + http.HandleFunc(cfg.Path, validateDeletion) server := http.Server{ Addr: fmt.Sprintf(":%d", cfg.Port), TLSConfig: &tls.Config{ diff --git a/scripts/clean-kind-only-e2e-test.sh b/scripts/clean-kind-only-e2e-test.sh index 60cff70b..51551c3c 100755 --- a/scripts/clean-kind-only-e2e-test.sh +++ b/scripts/clean-kind-only-e2e-test.sh @@ -19,12 +19,13 @@ set -u # Must predefine variables set -o pipefail # Check errors in piped commands PORCH_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" - cd $PORCH_DIR -kind delete cluster --name dev || true -kind create cluster --name dev -make run-in-kind-kpt IMAGE_TAG='test' KIND_CONTEXT_NAME='dev' KUBECONFIG=$KUBECONFIG +kind_cluster="porch-e2e" + +kind delete cluster --name "$kind_cluster" || true +kind create cluster --name "$kind_cluster" +make run-in-kind-kpt IMAGE_TAG='test' KIND_CONTEXT_NAME="$kind_cluster" KUBECONFIG="$KUBECONFIG" for deployment in porch-controllers porch-server function-runner; do kubectl rollout status deployment $deployment --namespace porch-system kubectl wait --namespace porch-system deploy $deployment \ @@ -35,7 +36,7 @@ kubectl wait --namespace porch-system pod --selector=app=function-runner \ --for=condition=ready \ --timeout=90s -sleep 15 +sleep 20 echo "--- test/e2e ---" E2E=1 go test -failfast -v ./test/e2e From 2dc1e6b6f0e894e57a4eaa1771cfad5652e9e8d2 Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Tue, 4 Jun 2024 13:50:30 +0200 Subject: [PATCH 22/23] Proper way for detect what parts of porch are in-cluster --- test/e2e/suite.go | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/test/e2e/suite.go b/test/e2e/suite.go index cf5a8c7f..fb06994c 100644 --- a/test/e2e/suite.go +++ b/test/e2e/suite.go @@ -130,7 +130,7 @@ func (t *TestSuite) Initialize(ctx context.Context) { t.clientset = cs } - _, t.local = t.IsUsingDevPorch() + t.local = !t.IsTestRunnerInCluster() namespace := fmt.Sprintf("porch-test-%d", time.Now().UnixMicro()) t.CreateF(ctx, &coreapi.Namespace{ @@ -154,7 +154,7 @@ func (t *TestSuite) Initialize(ctx context.Context) { }) } -func (t *TestSuite) IsUsingDevPorch() (bool, bool) { +func (t *TestSuite) IsPorchServerInCluster() bool { porch := aggregatorv1.APIService{} ctx := context.TODO() t.GetF(ctx, client.ObjectKey{ @@ -166,19 +166,33 @@ func (t *TestSuite) IsUsingDevPorch() (bool, bool) { Name: porch.Spec.Service.Name, }, &service) - isPorchLocal := len(service.Spec.Selector) == 0 - areAllLocal := service.Spec.Type == coreapi.ServiceTypeExternalName - return isPorchLocal, areAllLocal + return len(service.Spec.Selector) > 0 +} + +func (t *TestSuite) IsTestRunnerInCluster() bool { + porch := aggregatorv1.APIService{} + ctx := context.TODO() + t.GetF(ctx, client.ObjectKey{ + Name: "v1alpha1.porch.kpt.dev", + }, &porch) + service := coreapi.Service{} + err := t.client.Get(ctx, client.ObjectKey{ + Namespace: porch.Spec.Service.Namespace, + Name: "function-runner", + }, &service) + if err != nil { + return false + } + return len(service.Spec.Selector) > 0 } func (t *TestSuite) CreateGitRepo() GitConfig { // Deploy Git server via k8s client. t.Logf("creating git server in cluster") - isPorchLocal, areAllLocal := t.IsUsingDevPorch() - if areAllLocal { - return createLocalGitServer(t.T) + if t.IsTestRunnerInCluster() { + return t.createInClusterGitServer(context.TODO(), !t.IsPorchServerInCluster()) } else { - return t.createInClusterGitServer(context.TODO(), isPorchLocal) + return createLocalGitServer(t.T) } } From 67e2e44485e17c274da6016ed9951abd45a0641e Mon Sep 17 00:00:00 2001 From: Istvan Kispal Date: Tue, 4 Jun 2024 15:09:57 +0200 Subject: [PATCH 23/23] Minor improvement --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 76ebc9b4..c5e5ca1e 100644 --- a/Makefile +++ b/Makefile @@ -161,8 +161,8 @@ tidy: .PHONY: test-e2e test-e2e: - E2E=1 go test -v -race --count=1 -failfast ./test/e2e - E2E=1 go test -v -race --count=1 -failfast ./test/e2e/cli + E2E=1 go test -v -failfast ./test/e2e + E2E=1 go test -v -failfast ./test/e2e/cli .PHONY: test-e2e-clean test-e2e-clean: