Skip to content

Commit

Permalink
oci-support feature branch (kptdev#2666)
Browse files Browse the repository at this point in the history
Rebased on main and squashed

Co-authored-by: Louis DeJardin <[email protected]>

OCI: Fix Porch Build
  • Loading branch information
loudej authored and martinmaly committed Feb 18, 2022
1 parent d4e3995 commit 67629c7
Show file tree
Hide file tree
Showing 36 changed files with 3,127 additions and 475 deletions.
5 changes: 4 additions & 1 deletion commands/pkgcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"github.com/GoogleContainerTools/kpt/internal/cmddiff"
"github.com/GoogleContainerTools/kpt/internal/cmdget"
"github.com/GoogleContainerTools/kpt/internal/cmdinit"
"github.com/GoogleContainerTools/kpt/internal/cmdpull"
"github.com/GoogleContainerTools/kpt/internal/cmdpush"
"github.com/GoogleContainerTools/kpt/internal/cmdupdate"
"github.com/GoogleContainerTools/kpt/internal/docs/generated/pkgdocs"
"github.com/GoogleContainerTools/kpt/thirdparty/cmdconfig/commands/cmdtree"
Expand Down Expand Up @@ -47,7 +49,8 @@ func GetPkgCommand(ctx context.Context, name string) *cobra.Command {
pkg.AddCommand(
cmdget.NewCommand(ctx, name), cmdinit.NewCommand(ctx, name),
cmdupdate.NewCommand(ctx, name), cmddiff.NewCommand(ctx, name),
cmdtree.NewCommand(ctx, name),
cmdtree.NewCommand(ctx, name), cmdpull.NewCommand(ctx, name),
cmdpush.NewCommand(ctx, name),
)
return pkg
}
16 changes: 14 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ module github.com/GoogleContainerTools/kpt
go 1.17

require (
github.com/Masterminds/semver v1.5.0
github.com/cpuguy83/go-md2man/v2 v2.0.1
github.com/go-errors/errors v1.4.2
github.com/google/go-cmp v0.5.7
github.com/google/go-containerregistry v0.6.0
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/igorsobreira/titlecase v0.0.0-20140109233139-4156b5b858ac
github.com/otiai10/copy v1.7.0
github.com/otiai10/copy v1.6.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 v1.1.0
golang.org/x/mod v0.5.1
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gotest.tools v2.2.0+incompatible
k8s.io/api v0.23.3
k8s.io/apiextensions-apiserver v0.23.3
Expand Down Expand Up @@ -45,7 +46,12 @@ require (
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.10.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/cli v20.10.12+incompatible // indirect
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v20.10.12+incompatible // indirect
github.com/docker/docker-credential-helpers v0.6.4 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
Expand All @@ -66,6 +72,7 @@ require (
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
Expand All @@ -76,17 +83,22 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/onsi/gomega v1.17.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2-0.20211117181255-693428a734f5 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday v1.5.2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spyzhov/ajson v0.4.2 // indirect
github.com/vbatts/tar-split v0.11.2 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
Expand Down
414 changes: 407 additions & 7 deletions go.sum

Large diffs are not rendered by default.

22 changes: 16 additions & 6 deletions internal/cmdget/cmdget.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/GoogleContainerTools/kpt/internal/util/get"
"github.com/GoogleContainerTools/kpt/internal/util/parse"
"github.com/GoogleContainerTools/kpt/internal/util/pathutil"
"github.com/GoogleContainerTools/kpt/internal/util/remote"
kptfilev1 "github.com/GoogleContainerTools/kpt/pkg/api/kptfile/v1"
"github.com/spf13/cobra"
"sigs.k8s.io/kustomize/kyaml/filesys"
Expand All @@ -40,7 +41,7 @@ func NewRunner(ctx context.Context, parent string) *Runner {
ctx: ctx,
}
c := &cobra.Command{
Use: "get REPO_URI[.git]/PKG_PATH[@VERSION] [LOCAL_DEST_DIRECTORY]",
Use: "get {REPO_URI[.git]/PKG_PATH[@VERSION]|IMAGE:TAG} [LOCAL_DEST_DIRECTORY]",
Args: cobra.MinimumNArgs(1),
Short: docs.GetShort,
Long: docs.GetShort + "\n" + docs.GetLong,
Expand Down Expand Up @@ -86,20 +87,29 @@ func (r *Runner) preRunE(_ *cobra.Command, args []string) error {
args[1] = resolvedPath
}
}
t, err := parse.GitParseArgs(r.ctx, args)
destination, err := parse.ParseArgs(r.ctx, args, parse.Options{
SetGit: func(git *kptfilev1.Git) error {
r.Get.Git = git
r.Get.Upstream = remote.NewGitUpstream(git)
return nil
},
SetOci: func(oci *kptfilev1.Oci) error {
r.Get.Upstream = remote.NewOciUpstream(oci)
return nil
},
})
if err != nil {
return errors.E(op, err)
return err
}

r.Get.Git = &t.Git
absDestPath, _, err := pathutil.ResolveAbsAndRelPaths(t.Destination)
absDestPath, _, err := pathutil.ResolveAbsAndRelPaths(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)
return errors.E(op, types.UniquePath(destination), err)
}
r.Get.Destination = string(p.UniquePath)

Expand Down
1 change: 1 addition & 0 deletions internal/cmdget/cmdget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ func TestCmd_Execute_flagAndArgParsing(t *testing.T) {
validations: func(repo, dir string, r *cmdget.Runner, err error) {
assert.Error(t, err)
assert.Contains(t, err.Error(), "specify '.git'")
assert.Contains(t, err.Error(), "specify 'oci://'")
},
},
"valid strategy provided": {
Expand Down
109 changes: 109 additions & 0 deletions internal/cmdpull/cmdpull.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Copyright 2021 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.

package cmdpull

import (
"context"
"os"

docs "github.com/GoogleContainerTools/kpt/internal/docs/generated/pkgdocs"
"github.com/GoogleContainerTools/kpt/internal/errors"
"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/cmdutil"
"github.com/GoogleContainerTools/kpt/internal/util/parse"
"github.com/GoogleContainerTools/kpt/internal/util/pull"
"github.com/GoogleContainerTools/kpt/internal/util/remote"
kptfilev1 "github.com/GoogleContainerTools/kpt/pkg/api/kptfile/v1"
"github.com/spf13/cobra"
"sigs.k8s.io/kustomize/kyaml/filesys"
)

// NewRunner returns a command runner
func NewRunner(ctx context.Context, parent string) *Runner {
r := &Runner{
ctx: ctx,
}
c := &cobra.Command{
Use: "pull {REPO_URI[.git]/PKG_PATH[@VERSION]|IMAGE:TAG} [LOCAL_DEST_DIRECTORY]",
Args: cobra.MinimumNArgs(1),
Short: docs.PullShort,
Long: docs.PullShort + "\n" + docs.PullLong,
Example: docs.PullExamples,
RunE: r.runE,
PreRunE: r.preRunE,
}
cmdutil.FixDocs("kpt", parent, c)
r.Command = c
return r
}

func NewCommand(ctx context.Context, parent string) *cobra.Command {
return NewRunner(ctx, parent).Command
}

// Runner contains the run function
type Runner struct {
ctx context.Context
Pull pull.Command
Command *cobra.Command
}

func (r *Runner) preRunE(_ *cobra.Command, args []string) error {
const op errors.Op = "cmdpull.preRunE"
if len(args) == 1 {
args = append(args, pkg.CurDir)
} else {
_, err := os.Lstat(args[1])
if err == nil || os.IsExist(err) {
resolvedPath, err := argutil.ResolveSymlink(r.ctx, args[1])
if err != nil {
return errors.E(op, err)
}
args[1] = resolvedPath
}
}
destination, err := parse.ParseArgs(r.ctx, args, parse.Options{
SetGit: func(git *kptfilev1.Git) error {
r.Pull.Origin = remote.NewGitOrigin(git)
return nil
},
SetOci: func(oci *kptfilev1.Oci) error {
r.Pull.Origin = remote.NewOciOrigin(oci)
return nil
},
})
if err != nil {
return err
}

p, err := pkg.New(filesys.FileSystemOrOnDisk{}, destination)
if err != nil {
return errors.E(op, types.UniquePath(destination), err)
}
r.Pull.Destination = string(p.UniquePath)

return nil
}

func (r *Runner) runE(c *cobra.Command, _ []string) error {
const op errors.Op = "cmdpull.runE"
if err := r.Pull.Run(r.ctx); err != nil {
return errors.E(op, types.UniquePath(r.Pull.Destination), err)
}

return nil
}
Loading

0 comments on commit 67629c7

Please sign in to comment.