Skip to content

Commit

Permalink
Merge porch into main
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmaly committed Feb 22, 2022
2 parents 9bee31b + 0aec520 commit 0fa4a0a
Show file tree
Hide file tree
Showing 258 changed files with 33,470 additions and 243 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/porch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2022 Google LLC
#
# 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.

name: Porch

on:
push:
paths-ignore:
- "docs/**"
- "site/**"
pull_request:
paths-ignore:
- "docs/**"
- "site/**"

jobs:
tests:
name: Porch Unit Tests
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.17
uses: actions/setup-go@v2
with:
go-version: 1.17.6
- name: Run Porch Unit Tests
uses: actions/checkout@v2
- name: Verify format / headers etc
run: hack/verify-fix-all.sh
working-directory: ./porch
- name: Build
run: make porch
working-directory: ./porch
- name: Test
run: make test
working-directory: ./porch
- name: Tidy
run: make tidy
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ require (
github.com/google/go-cmp v0.5.6
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/igorsobreira/titlecase v0.0.0-20140109233139-4156b5b858ac
github.com/otiai10/copy v1.6.0
github.com/otiai10/copy v1.7.0
github.com/philopon/go-toposort v0.0.0-20170620085441-9be86dbd762f
github.com/spf13/cobra v1.3.0
github.com/stretchr/testify v1.7.0
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca
github.com/xlab/treeprint v1.1.0
golang.org/x/mod v0.5.1
gotest.tools v2.2.0+incompatible
k8s.io/api v0.23.2
Expand Down
11 changes: 6 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -493,13 +493,13 @@ github.com/onsi/gomega v1.17.0 h1:9Luw4uT5HTjHTN8+aNcSThgH1vdXnmdJ8xIfZ4wyTRE=
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/otiai10/copy v1.6.0 h1:IinKAryFFuPONZ7cm6T6E2QX/vcJwSnlaA5lfoaXIiQ=
github.com/otiai10/copy v1.6.0/go.mod h1:XWfuS3CrI0R6IE0FbgHsEazaXO8G0LpMp9o8tos0x4E=
github.com/otiai10/copy v1.7.0 h1:hVoPiN+t+7d2nzzwMiDHPSOogsWAStewq3TwU05+clE=
github.com/otiai10/copy v1.7.0/go.mod h1:rmRl6QPdJj6EiUqXQ/4Nn2lLXoNQjFCQbbNrxgc/t3U=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
github.com/otiai10/mint v1.3.2 h1:VYWnrP5fXmz1MXvjuUvcBrXSjGE6xjON+axB/UrpO3E=
github.com/otiai10/mint v1.3.2/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
github.com/otiai10/mint v1.3.3 h1:7JgpsBaN0uMkyju4tbYHu0mnM55hNKVYLsXmwr15NQI=
github.com/otiai10/mint v1.3.3/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
Expand Down Expand Up @@ -613,8 +613,9 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca h1:1CFlNzQhALwjS9mBAUkycX616GzgsuYUOCHA5+HSlXI=
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg=
github.com/xlab/treeprint v1.1.0 h1:G/1DjNkPpfZCFt9CSh6b5/nY4VimlbHF3Rh4obvtzDk=
github.com/xlab/treeprint v1.1.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
9 changes: 8 additions & 1 deletion internal/cmddiff/cmddiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import (
"github.com/GoogleContainerTools/kpt/internal/util/argutil"
"github.com/GoogleContainerTools/kpt/internal/util/cmdutil"
"github.com/GoogleContainerTools/kpt/internal/util/diff"
"github.com/GoogleContainerTools/kpt/internal/util/pathutil"
"github.com/spf13/cobra"
"sigs.k8s.io/kustomize/kyaml/filesys"
)

// NewRunner returns a command runner.
Expand Down Expand Up @@ -100,7 +102,12 @@ func (r *Runner) preRunE(_ *cobra.Command, args []string) error {
return err
}

p, err := pkg.New(resolvedPath)
absResolvedPath, _, err := pathutil.ResolveAbsAndRelPaths(resolvedPath)
if err != nil {
return err
}

p, err := pkg.New(filesys.FileSystemOrOnDisk{}, absResolvedPath)
if err != nil {
return err
}
Expand Down
9 changes: 8 additions & 1 deletion internal/cmdget/cmdget.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ import (
"github.com/GoogleContainerTools/kpt/internal/util/cmdutil"
"github.com/GoogleContainerTools/kpt/internal/util/get"
"github.com/GoogleContainerTools/kpt/internal/util/parse"
"github.com/GoogleContainerTools/kpt/internal/util/pathutil"
kptfilev1 "github.com/GoogleContainerTools/kpt/pkg/api/kptfile/v1"
"github.com/spf13/cobra"
"sigs.k8s.io/kustomize/kyaml/filesys"
)

// NewRunner returns a command runner
Expand Down Expand Up @@ -90,7 +92,12 @@ func (r *Runner) preRunE(_ *cobra.Command, args []string) error {
}

r.Get.Git = &t.Git
p, err := pkg.New(t.Destination)
absDestPath, _, err := pathutil.ResolveAbsAndRelPaths(t.Destination)
if err != nil {
return err
}

p, err := pkg.New(filesys.FileSystemOrOnDisk{}, absDestPath)
if err != nil {
return errors.E(op, types.UniquePath(t.Destination), err)
}
Expand Down
9 changes: 8 additions & 1 deletion internal/cmdinit/cmdinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ import (
"github.com/GoogleContainerTools/kpt/internal/printer"
"github.com/GoogleContainerTools/kpt/internal/util/cmdutil"
"github.com/GoogleContainerTools/kpt/internal/util/man"
"github.com/GoogleContainerTools/kpt/internal/util/pathutil"
kptfilev1 "github.com/GoogleContainerTools/kpt/pkg/api/kptfile/v1"
"github.com/spf13/cobra"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/filesys"
"sigs.k8s.io/kustomize/kyaml/yaml"
)

Expand Down Expand Up @@ -75,7 +77,12 @@ func (r *Runner) runE(c *cobra.Command, args []string) error {
if len(args) == 0 {
args = append(args, pkg.CurDir)
}
p, err := pkg.New(args[0])

absPath, _, err := pathutil.ResolveAbsAndRelPaths(args[0])
if err != nil {
return err
}
p, err := pkg.New(filesys.FileSystemOrOnDisk{}, absPath)
if err != nil {
return err
}
Expand Down
19 changes: 13 additions & 6 deletions internal/cmdliveinit/cmdliveinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ import (
"github.com/GoogleContainerTools/kpt/internal/printer"
"github.com/GoogleContainerTools/kpt/internal/types"
"github.com/GoogleContainerTools/kpt/internal/util/attribution"
"github.com/GoogleContainerTools/kpt/internal/util/pathutil"
kptfilev1 "github.com/GoogleContainerTools/kpt/pkg/api/kptfile/v1"
rgfilev1alpha1 "github.com/GoogleContainerTools/kpt/pkg/api/resourcegroup/v1alpha1"
"github.com/GoogleContainerTools/kpt/pkg/kptfile/kptfileutil"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
k8scmdutil "k8s.io/kubectl/pkg/cmd/util"
"sigs.k8s.io/cli-utils/pkg/common"
"sigs.k8s.io/cli-utils/pkg/config"
"sigs.k8s.io/kustomize/kyaml/filesys"
"sigs.k8s.io/kustomize/kyaml/yaml"
)

Expand Down Expand Up @@ -60,7 +62,7 @@ func (i *InvInKfExistsError) Error() string {
return "inventory information already set within Kptfile for package"
}

func NewRunner(ctx context.Context, factory cmdutil.Factory,
func NewRunner(ctx context.Context, factory k8scmdutil.Factory,
ioStreams genericclioptions.IOStreams) *Runner {
r := &Runner{
ctx: ctx,
Expand All @@ -84,7 +86,7 @@ func NewRunner(ctx context.Context, factory cmdutil.Factory,
return r
}

func NewCommand(ctx context.Context, f cmdutil.Factory,
func NewCommand(ctx context.Context, f k8scmdutil.Factory,
ioStreams genericclioptions.IOStreams) *cobra.Command {
return NewRunner(ctx, f, ioStreams).Command
}
Expand All @@ -93,7 +95,7 @@ type Runner struct {
ctx context.Context
Command *cobra.Command

factory cmdutil.Factory
factory k8scmdutil.Factory
ioStreams genericclioptions.IOStreams
Force bool // Set inventory values even if already set in Kptfile
Name string // Inventory object name
Expand All @@ -119,7 +121,12 @@ func (r *Runner) runE(_ *cobra.Command, args []string) error {
return errors.E(op, err)
}

p, err := pkg.New(dir)
absPath, _, err := pathutil.ResolveAbsAndRelPaths(dir)
if err != nil {
return err
}

p, err := pkg.New(filesys.FileSystemOrOnDisk{}, absPath)
if err != nil {
return errors.E(op, err)
}
Expand All @@ -143,7 +150,7 @@ func (r *Runner) runE(_ *cobra.Command, args []string) error {
// the inventory information in the Kptfile.
type ConfigureInventoryInfo struct {
Pkg *pkg.Pkg
Factory cmdutil.Factory
Factory k8scmdutil.Factory
Quiet bool

Name string
Expand Down
3 changes: 2 additions & 1 deletion internal/cmdliveinit/cmdliveinit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/stretchr/testify/assert"
"k8s.io/cli-runtime/pkg/genericclioptions"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
"sigs.k8s.io/kustomize/kyaml/filesys"
)

var (
Expand Down Expand Up @@ -293,7 +294,7 @@ func TestCmd_Run(t *testing.T) {
// Otherwise, validate the kptfile values and/or resourcegroup values.
var actualInv kptfilev1.Inventory
assert.NoError(t, err)
kf, err := pkg.ReadKptfile(w.WorkspaceDirectory)
kf, err := pkg.ReadKptfile(filesys.FileSystemOrOnDisk{}, w.WorkspaceDirectory)
assert.NoError(t, err)

switch tc.rgfilename {
Expand Down
12 changes: 9 additions & 3 deletions internal/cmdmigrate/migratecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/GoogleContainerTools/kpt/internal/pkg"
"github.com/GoogleContainerTools/kpt/internal/types"
"github.com/GoogleContainerTools/kpt/internal/util/argutil"
"github.com/GoogleContainerTools/kpt/internal/util/pathutil"
"github.com/GoogleContainerTools/kpt/pkg/kptfile/kptfileutil"
"github.com/GoogleContainerTools/kpt/pkg/live"
"github.com/spf13/cobra"
Expand All @@ -31,6 +32,7 @@ import (
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/manifestreader"
"sigs.k8s.io/cli-utils/pkg/object"
"sigs.k8s.io/kustomize/kyaml/filesys"
)

// MigrateRunner encapsulates fields for the kpt migrate command.
Expand Down Expand Up @@ -212,7 +214,11 @@ func (mr *MigrateRunner) applyCRD() error {
func (mr *MigrateRunner) updateKptfile(ctx context.Context, args []string, prevID string) error {
fmt.Fprint(mr.ioStreams.Out, " updating Kptfile inventory values...")
if !mr.dryRun {
p, err := pkg.New(args[0])
absPath, _, err := pathutil.ResolveAbsAndRelPaths(args[0])
if err != nil {
return err
}
p, err := pkg.New(filesys.FileSystemOrOnDisk{}, absPath)
if err != nil {
return err
}
Expand Down Expand Up @@ -458,7 +464,7 @@ func (mr *MigrateRunner) migrateKptfileToRG(args []string) error {
fmt.Fprint(mr.ioStreams.Out, " reading existing Kptfile...")
if !mr.dryRun {
dir := args[0]
p, err := pkg.New(dir)
p, err := pkg.New(filesys.FileSystemOrOnDisk{}, dir)
if err != nil {
return err
}
Expand Down Expand Up @@ -550,7 +556,7 @@ func (mr *MigrateRunner) migrateCMToRG(stdinBytes []byte, args []string) error {
func (mr *MigrateRunner) createRGfile(ctx context.Context, args []string, prevID string) error {
fmt.Fprint(mr.ioStreams.Out, " creating ResourceGroup object file...")
if !mr.dryRun {
p, err := pkg.New(args[0])
p, err := pkg.New(filesys.FileSystemOrOnDisk{}, args[0])
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions internal/cmdmigrate/migratecmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/manifestreader"
"sigs.k8s.io/cli-utils/pkg/object"
"sigs.k8s.io/kustomize/kyaml/filesys"
)

var testNamespace = "test-inventory-namespace"
Expand Down Expand Up @@ -158,7 +159,7 @@ func TestKptMigrate_updateKptfile(t *testing.T) {
return
}
assert.NoError(t, err)
kf, err := pkg.ReadKptfile(dir)
kf, err := pkg.ReadKptfile(filesys.FileSystemOrOnDisk{}, dir)
if !assert.NoError(t, err) {
t.FailNow()
}
Expand Down Expand Up @@ -257,7 +258,7 @@ func TestKptMigrate_migrateKptfileToRG(t *testing.T) {
return
}
assert.NoError(t, err)
kf, err := pkg.ReadKptfile(dir)
kf, err := pkg.ReadKptfile(filesys.FileSystemOrOnDisk{}, dir)
if !assert.NoError(t, err) {
t.FailNow()
}
Expand Down
12 changes: 10 additions & 2 deletions internal/cmdrender/cmdrender.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import (
"github.com/GoogleContainerTools/kpt/internal/printer"
"github.com/GoogleContainerTools/kpt/internal/util/argutil"
"github.com/GoogleContainerTools/kpt/internal/util/cmdutil"
"github.com/GoogleContainerTools/kpt/internal/util/pathutil"
"github.com/GoogleContainerTools/kpt/internal/util/render"
"github.com/spf13/cobra"
"sigs.k8s.io/kustomize/kyaml/filesys"
)

// NewRunner returns a command runner
Expand Down Expand Up @@ -108,12 +111,17 @@ func (r *Runner) runE(c *cobra.Command, _ []string) error {
// capture the content to be written
output = &outContent
}
executor := Executor{
PkgPath: r.pkgPath,
absPkgPath, _, err := pathutil.ResolveAbsAndRelPaths(r.pkgPath)
if err != nil {
return err
}
executor := render.Renderer{
PkgPath: absPkgPath,
ResultsDirPath: r.resultsDirPath,
Output: output,
ImagePullPolicy: cmdutil.StringToImagePullPolicy(r.imagePullPolicy),
AllowExec: r.allowExec,
FileSystem: filesys.FileSystemOrOnDisk{},
}
if err := executor.Execute(r.ctx); err != nil {
return err
Expand Down
9 changes: 7 additions & 2 deletions internal/cmdupdate/cmdupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ import (
"github.com/GoogleContainerTools/kpt/internal/types"
"github.com/GoogleContainerTools/kpt/internal/util/argutil"
"github.com/GoogleContainerTools/kpt/internal/util/cmdutil"
"github.com/GoogleContainerTools/kpt/internal/util/pathutil"
"github.com/GoogleContainerTools/kpt/internal/util/update"
kptfilev1 "github.com/GoogleContainerTools/kpt/pkg/api/kptfile/v1"
"github.com/spf13/cobra"
"sigs.k8s.io/kustomize/kyaml/filesys"
)

// NewRunner returns a command runner.
Expand Down Expand Up @@ -94,8 +96,11 @@ func (r *Runner) preRunE(_ *cobra.Command, args []string) error {
if err != nil {
return err
}

p, err := pkg.New(resolvedPath)
absResolvedPath, _, err := pathutil.ResolveAbsAndRelPaths(resolvedPath)
if err != nil {
return err
}
p, err := pkg.New(filesys.FileSystemOrOnDisk{}, absResolvedPath)
if err != nil {
return errors.E(op, err)
}
Expand Down

0 comments on commit 0fa4a0a

Please sign in to comment.