Skip to content

Commit

Permalink
Add proper test to PAckageVariant inject package functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
kispaljr committed Aug 26, 2024
1 parent c6568ac commit 4a77852
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 77 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.cache/
default.etcd/
apiserver.local.config/
__debug_bin*
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/controllers",
"program": "${workspaceFolder}/controllers/main.go",
"cwd": "${workspaceFolder}",
"env": {
"ENABLE_PACKAGEVARIANTS": "true",
Expand All @@ -44,7 +44,7 @@
"args": [
"-test.v",
"-test.run",
"TestE2E/PorchSuite/TestGitRepositoryWithReleaseTagsAndDirectory"
"TestE2E/PorchSuite/TestPackageVariantMutationInjectPackage"
],
"env": { "E2E": "1"}
},
Expand Down
1 change: 1 addition & 0 deletions controllers/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ require (
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand Down
3 changes: 1 addition & 2 deletions controllers/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lne
github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ func (i *injectPackage) Apply(ctx context.Context, prr *porchapi.PackageRevision
// Load the PackageRevisionResources
var prrToInject porchapi.PackageRevisionResources
if err := i.client.Get(ctx, client.ObjectKeyFromObject(prToInject), &prrToInject); err != nil {
return err
return fmt.Errorf("couldn't read the package revision that should be inserted (%s/%s/%s): %w", i.config.Package.Repo, i.config.Package.Package, i.config.Package.Revision, err)
}

// Inject the resources
for filename, content := range prrToInject.Spec.Resources {
newResources[i.config.Subdir+"/"+filename] = content
}

prr.Spec.Resources = newResources

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,22 @@ func (r *PackageVariantReconciler) Reconcile(ctx context.Context, req ctrl.Reque
}
ctx = WithPackageRevisions(ctx, PackageRevisions(prList.Items))

skipStatusUpdate := false
defer func() {
if err := r.Client.Status().Update(ctx, pv); err != nil {
klog.Errorf("could not update status: %s\n", err.Error())
if !skipStatusUpdate {
if err := r.Client.Status().Update(ctx, pv); err != nil {
klog.Errorf("could not update status: %s\n", err.Error())
}
}

}()

if !pv.ObjectMeta.DeletionTimestamp.IsZero() {
// This object is being deleted, so we need to make sure the packagerevisions owned by this object
// are deleted. Normally, garbage collection can handle this, but we have a special case here because
// (a) we cannot delete published packagerevisions and instead have to propose deletion of them
// (b) we may want to orphan packagerevisions instead of deleting them.
skipStatusUpdate = true
for _, pr := range prList.Items {
if r.hasOurOwnerReference(pv, pr.OwnerReferences) {
r.deleteOrOrphan(ctx, &pr, pv)
Expand Down
18 changes: 10 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/GoogleContainerTools/kpt-functions-catalog/functions/go/apply-setters v0.2.0
github.com/GoogleContainerTools/kpt-functions-catalog/functions/go/set-namespace v0.4.1
github.com/GoogleContainerTools/kpt-functions-catalog/functions/go/starlark v0.4.3
github.com/GoogleContainerTools/kpt-functions-sdk/go/fn v0.0.0-20220506190241-f85503febd54
github.com/GoogleContainerTools/kpt-functions-sdk/go/fn v0.0.0-20230427202446-3255accc518d
github.com/bluekeyes/go-gitdiff v0.6.1
github.com/bytecodealliance/wasmtime-go v0.39.0
github.com/cpuguy83/go-md2man/v2 v2.0.2
Expand All @@ -24,6 +24,7 @@ require (
github.com/google/uuid v1.6.0
github.com/hexops/gotextdiff v1.0.3
github.com/nephio-project/porch/api v0.0.0-20240722132258-c4b36b7a5fb1
github.com/nephio-project/porch/controllers v0.0.0-20240813115737-12b79b20e318
github.com/otiai10/copy v1.7.0
github.com/philopon/go-toposort v0.0.0-20170620085441-9be86dbd762f
github.com/prep/wasmexec v0.0.0-20220807105708-6554945c1dec
Expand All @@ -39,7 +40,7 @@ require (
golang.org/x/mod v0.16.0
golang.org/x/oauth2 v0.18.0
golang.org/x/tools v0.19.0
google.golang.org/api v0.126.0
google.golang.org/api v0.142.0
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.33.0
Expand All @@ -55,7 +56,7 @@ require (
k8s.io/klog/v2 v2.120.1
k8s.io/kube-aggregator v0.29.2
k8s.io/kubectl v0.29.2
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
k8s.io/utils v0.0.0-20240310230437-4693a0247e57
sigs.k8s.io/cli-utils v0.35.0
sigs.k8s.io/controller-runtime v0.17.2
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3
Expand All @@ -69,6 +70,7 @@ require (
dario.cat/mergo v1.0.0 // indirect
github.com/360EntSecGroup-Skylar/excelize v1.4.1 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/GoogleContainerTools/kpt-functions-sdk/go/api v0.0.0-20220720212527-133180134b93 // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/NYTimes/gziphandler v1.1.1 // indirect
Expand Down Expand Up @@ -112,9 +114,9 @@ require (
github.com/google/cel-go v0.17.7 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
Expand Down Expand Up @@ -171,7 +173,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/exp v0.0.0-20220916125017-b168a2c6b86b // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
Expand All @@ -181,7 +183,7 @@ require (
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
Expand Down
Loading

0 comments on commit 4a77852

Please sign in to comment.