Skip to content

Commit

Permalink
Porch
Browse files Browse the repository at this point in the history
Split git_test To Use Git Server (kptdev#2797)

Enable e2e tests to use git server

Add CreatePackageRevision Test (kptdev#2800)

Simple test that creates a package by cloning from upstream repository.

Cache apply-setters:v0.1 function (kptdev#2799)

Some blueprints we encounter in tests use the older version of the function.

Return Git PackageRevisionResources Correctly (kptdev#2801)

Newly created Git package returned package resources at its old commit
SHA where no package contents existed, thus returning empty resources.
As package changes, advance the reference to return up-to-date package
revision contents.

Make Git Server hostable in cluster (kptdev#2798)

* Make Git Server hostable in cluster
* Add makefile targets to build and push its images

Add PackageRevision Approval API (kptdev#2810)

* Add PackageRevision .../approval subresource
* Generate client

Add Clone Package Test (kptdev#2807)

* Add Clone Package Test
* Fix issues with git server's reporting of symbolic references
  • Loading branch information
martinmaly committed Feb 18, 2022
1 parent d8404ca commit d3e9eab
Show file tree
Hide file tree
Showing 28 changed files with 2,419 additions and 713 deletions.
2 changes: 2 additions & 0 deletions porch/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,14 @@ push-images:
docker buildx build --push --tag "$(IMAGE_REPO)/porch:$(IMAGE_TAG)" -f "${CURDIR}/hack/Dockerfile" "${KPTDIR}"
make -C controllers/ push-image
make -C func/ push-image
make -C test/ push-image

.PHONY: build-images
build-images:
docker buildx build --load --tag "$(IMAGE_REPO)/porch:$(IMAGE_TAG)" -f "${CURDIR}/hack/Dockerfile" "${KPTDIR}"
make -C controllers/ build-image
make -C func/ build-image
make -C test/ build-image

.PHONY: apply-dev-config
apply-dev-config:
Expand Down
1 change: 1 addition & 0 deletions porch/api/porch/v1alpha1/types_packagerevisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
)

// +genclient
// +genclient:method=UpdateApproval,verb=update,subresource=approval,input=github.com/GoogleContainerTools/kpt/porch/api/porch/v1alpha1.PackageRevision,result=github.com/GoogleContainerTools/kpt/porch/api/porch/v1alpha1.PackageRevision
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// PackageRevision
Expand Down
5 changes: 3 additions & 2 deletions porch/apiserver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/GoogleContainerTools/kpt/porch/controllers v0.0.0-00010101000000-000000000000
github.com/GoogleContainerTools/kpt/porch/engine v0.0.0-00010101000000-000000000000
github.com/GoogleContainerTools/kpt/porch/repository v0.0.0-00010101000000-000000000000
github.com/go-git/go-git/v5 v5.4.3-0.20220119145113-935af59cf64f
github.com/spf13/cobra v1.3.0
github.com/spf13/pflag v1.0.5
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.20.0
Expand All @@ -23,9 +24,11 @@ require (
k8s.io/client-go v0.23.3
k8s.io/component-base v0.23.3
k8s.io/klog/v2 v2.40.1
k8s.io/kube-aggregator v0.23.3
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65
k8s.io/utils v0.0.0-20211208161948-7d6a63dca704
sigs.k8s.io/controller-runtime v0.11.0
sigs.k8s.io/kustomize/kyaml v0.13.3
)

replace (
Expand Down Expand Up @@ -68,7 +71,6 @@ require (
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.3.1 // indirect
github.com/go-git/go-git/v5 v5.4.3-0.20220119145113-935af59cf64f // indirect
github.com/go-logr/logr v1.2.1 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
Expand Down Expand Up @@ -145,7 +147,6 @@ require (
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.27 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/kustomize/api v0.11.1 // indirect
sigs.k8s.io/kustomize/kyaml v0.13.3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
3 changes: 3 additions & 0 deletions porch/apiserver/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,7 @@ k8s.io/client-go v0.22.2/go.mod h1:sAlhrkVDf50ZHx6z4K0S40wISNTarf1r800F+RlCF6U=
k8s.io/client-go v0.23.3 h1:23QYUmCQ/W6hW78xIwm3XqZrrKZM+LWDqW2zfo+szJs=
k8s.io/client-go v0.23.3/go.mod h1:47oMd+YvAOqZM7pcQ6neJtBiFH7alOyfunYN48VsmwE=
k8s.io/code-generator v0.22.2/go.mod h1:eV77Y09IopzeXOJzndrDyCI88UBok2h6WxAlBwpxa+o=
k8s.io/code-generator v0.23.3/go.mod h1:S0Q1JVA+kSzTI1oUvbKAxZY/DYbA/ZUb4Uknog12ETk=
k8s.io/component-base v0.20.1/go.mod h1:guxkoJnNoh8LNrbtiQOlyp2Y2XFCZQmrcg2n/DeYNLk=
k8s.io/component-base v0.20.4/go.mod h1:t4p9EdiagbVCJKrQ1RsA5/V4rFQNDfRlevJajlGwgjI=
k8s.io/component-base v0.20.6/go.mod h1:6f1MPBAeI+mvuts3sIdtpjljHWBQ2cIy38oBIWMYnrM=
Expand All @@ -1649,6 +1650,8 @@ k8s.io/klog/v2 v2.9.0/go.mod h1:hy9LJ/NvuK+iVyP4Ehqva4HxZG/oXyIS3n3Jmire4Ec=
k8s.io/klog/v2 v2.30.0/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/klog/v2 v2.40.1 h1:P4RRucWk/lFOlDdkAr3mc7iWFkgKrZY9qZMAgek06S4=
k8s.io/klog/v2 v2.40.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/kube-aggregator v0.23.3 h1:9IP+D+YzIbGor/TArN3pYf9Thj19wYhzLRGRrFaKFSs=
k8s.io/kube-aggregator v0.23.3/go.mod h1:pt5QJ3QaIdhZzNlUvN5wndbM0LNT4BvhszGkzy2QdFo=
k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd/go.mod h1:WOJ3KddDSol4tAGcJo0Tvi+dK12EcqSLqcWsryKMpfM=
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e/go.mod h1:vHXdDvt9+2spS2Rx9ql3I8tycm3H9FDfdUoIuKCefvw=
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 h1:E3J9oCLlaobFUqsjG9DfKbP2BmgwBL2p7pn0A3dG9W4=
Expand Down
97 changes: 83 additions & 14 deletions porch/apiserver/pkg/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
coreapi "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/kustomize/kyaml/yaml"
)

func TestE2E(t *testing.T) {
Expand All @@ -37,12 +39,13 @@ func Run(suite interface{}, t *testing.T) {
ctx := context.Background()

t.Run(st.Elem().Name(), func(t *testing.T) {
var ts *TestSuite = sv.Elem().FieldByName("TestSuite").Addr().Interface().(*TestSuite)

ts.T = t
if init, ok := suite.(Initializer); ok {
init.Initialize(ctx, t)
init.Initialize(ctx)
}

var ts *TestSuite = sv.Elem().FieldByName("TestSuite").Addr().Interface().(*TestSuite)

for i, max := 0, st.NumMethod(); i < max; i++ {
m := st.Method(i)
if strings.HasPrefix(m.Name, "Test") {
Expand All @@ -61,13 +64,17 @@ type PorchSuite struct {

var _ Initializer = &PorchSuite{}

func (p *PorchSuite) Initialize(ctx context.Context) {
p.TestSuite.Initialize(ctx)
}

func (t *PorchSuite) TestGitRepository(ctx context.Context) {
if t.ptc.Git.Repo == "" {
t.Skipf("Skipping TestGitRepository; no Git repository specified.")
}
config := t.CreateGitRepo()

var secret string
if t.ptc.Git.Username != "" || t.ptc.Git.Token != "" {

// Create auth secret if necessary
if config.Username != "" || config.Password != "" {
const credSecret = "git-repository-auth"
immutable := true
t.CreateF(ctx, &coreapi.Secret{
Expand All @@ -77,17 +84,17 @@ func (t *PorchSuite) TestGitRepository(ctx context.Context) {
},
Immutable: &immutable,
Data: map[string][]byte{
"username": []byte(t.ptc.Git.Username),
"token": []byte(t.ptc.Git.Token),
"username": []byte(config.Username),
"password": []byte(config.Password),
},
// TODO: Store as SecretTypeBasicAuth ?
Type: coreapi.SecretTypeOpaque,
Type: coreapi.SecretTypeBasicAuth,
})

secret = credSecret

t.Cleanup(func() {
t.DeleteL(ctx, &coreapi.Secret{
t.DeleteE(ctx, &coreapi.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: credSecret,
Namespace: t.namespace,
Expand All @@ -96,6 +103,7 @@ func (t *PorchSuite) TestGitRepository(ctx context.Context) {
})
}

// Register repository
t.CreateF(ctx, &configapi.Repository{
ObjectMeta: metav1.ObjectMeta{
Name: "git",
Expand All @@ -107,8 +115,9 @@ func (t *PorchSuite) TestGitRepository(ctx context.Context) {
Type: configapi.RepositoryTypeGit,
Content: configapi.RepositoryContentPackage,
Git: &configapi.GitRepository{
Repo: t.ptc.Git.Repo,
Branch: "main",
Repo: config.Repo,
Branch: config.Branch,
Directory: config.Directory,
SecretRef: configapi.SecretRef{
Name: secret,
},
Expand All @@ -117,13 +126,69 @@ func (t *PorchSuite) TestGitRepository(ctx context.Context) {
})

t.Cleanup(func() {
t.DeleteL(ctx, &configapi.Repository{
t.DeleteE(ctx, &configapi.Repository{
ObjectMeta: metav1.ObjectMeta{
Name: "git",
Namespace: t.namespace,
},
})
})

// Create Package Revision
t.CreateF(ctx, &porchapi.PackageRevision{
ObjectMeta: metav1.ObjectMeta{
Name: "git:test-bucket:v1",
Namespace: t.namespace,
},
Spec: porchapi.PackageRevisionSpec{
PackageName: "test-bucket",
Revision: "v1",
RepositoryName: "git",
Tasks: []porchapi.Task{
{
Type: "clone",
Clone: &porchapi.PackageCloneTaskSpec{
Upstream: porchapi.UpstreamPackage{
Type: "git",
Git: &porchapi.GitPackage{
Repo: "https://github.com/GoogleCloudPlatform/blueprints.git",
Ref: "bucket-blueprint-v0.4.3",
Directory: "catalog/bucket",
},
},
},
},
{
Type: "eval",
Eval: &porchapi.FunctionEvalTaskSpec{
Image: "gcr.io/kpt-fn/set-namespace:v0.2.0",
ConfigMap: map[string]string{
"namespace": "bucket-namespace",
},
},
},
},
},
})

// Get package resources
var resources porchapi.PackageRevisionResources
t.GetF(ctx, client.ObjectKey{
Namespace: t.namespace,
Name: "git:test-bucket:v1",
}, &resources)

bucket, ok := resources.Spec.Resources["bucket.yaml"]
if !ok {
t.Errorf("'bucket.yaml' not found among package resources")
}
node, err := yaml.Parse(bucket)
if err != nil {
t.Errorf("yaml.Parse(\"bucket.yaml\") failed: %v", err)
}
if got, want := node.GetNamespace(), "bucket-namespace"; got != want {
t.Errorf("StorageBucket namespace: got %q, want %q", got, want)
}
}

func (t *PorchSuite) TestFunctionRepository(ctx context.Context) {
Expand Down Expand Up @@ -194,3 +259,7 @@ func (t *PorchSuite) TestPublicGitRepository(ctx context.Context) {
t.Errorf("Found no package revisions in %s; expected at least one", repo)
}
}

func (t *PorchSuite) TestDevPorch(ctx context.Context) {
t.IsUsingDevPorch()
}
Loading

0 comments on commit d3e9eab

Please sign in to comment.