Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade carvel-imgpkg #147

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ require (
github.com/go-logr/logr v1.2.3
github.com/google/go-cmp v0.5.8
github.com/google/go-containerregistry v0.9.0
github.com/k14s/imgpkg v0.17.0
github.com/spf13/cobra v1.4.0
github.com/stern/stern v1.21.0
github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942
github.com/stretchr/testify v1.7.1
github.com/vmware-labs/reconciler-runtime v0.6.0
github.com/vmware-tanzu/carvel-imgpkg v0.25.0
github.com/vmware-tanzu/difflib v0.0.0-20201117154628-0c031775bf57
github.com/vmware-tanzu/tanzu-framework v0.22.0
golang.org/x/crypto v0.0.0-20220214200702-86341886e292
Expand Down Expand Up @@ -51,17 +51,20 @@ require (
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/VividCortex/ewma v1.1.1 // indirect
github.com/adrg/xdg v0.2.1 // indirect
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220209173558-ad29539cd2e9 // indirect
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/aunum/log v0.0.0-20200821225356-38d2e2c8b489 // indirect
github.com/aws/aws-sdk-go v1.40.56 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/briandowns/spinner v1.18.0 // indirect
github.com/census-instrumentation/opencensus-proto v0.3.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cheggaaa/pb v1.0.29 // indirect
github.com/cheggaaa/pb/v3 v3.0.8 // indirect
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4 // indirect
github.com/cncf/xds/go v0.0.0-20211130200136-a8f946100490 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.11.4 // indirect
Expand Down Expand Up @@ -114,9 +117,11 @@ require (
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b // indirect
github.com/k14s/imgpkg v0.17.0 // indirect
github.com/k14s/kbld v0.32.0 // indirect
github.com/k14s/semver/v4 v4.0.1-0.20210701191048-266d47ac6115 // indirect
github.com/k14s/starlark-go v0.0.0-20200720175618-3a5c849cc368 // indirect
Expand Down Expand Up @@ -163,8 +168,8 @@ require (
github.com/subosito/gotenv v1.2.0 // indirect
github.com/valyala/fastjson v1.6.3 // indirect
github.com/vbatts/tar-split v0.11.2 // indirect
github.com/vdemeester/k8s-pkg-credentialprovider v1.22.4 // indirect
github.com/vito/go-interact v1.0.1 // indirect
github.com/vmware-tanzu/carvel-imgpkg v0.25.0 // indirect
github.com/vmware-tanzu/carvel-kapp-controller v0.25.0 // indirect
github.com/vmware-tanzu/carvel-vendir v0.24.0 // indirect
github.com/vmware-tanzu/carvel-ytt v0.40.0 // indirect
Expand Down Expand Up @@ -194,11 +199,13 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
k8s.io/apiserver v0.24.0 // indirect
k8s.io/cloud-provider v0.22.4 // indirect
k8s.io/cluster-bootstrap v0.23.4 // indirect
k8s.io/component-base v0.24.0 // indirect
k8s.io/klog/v2 v2.60.1 // indirect
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
k8s.io/kubectl v0.23.4 // indirect
k8s.io/legacy-cloud-providers v0.22.4 // indirect
sigs.k8s.io/cluster-api v1.1.3 // indirect
sigs.k8s.io/cluster-api-provider-aws v1.1.0 // indirect
sigs.k8s.io/cluster-api-provider-azure v1.0.1 // indirect
Expand Down
34 changes: 32 additions & 2 deletions go.sum

Large diffs are not rendered by default.

30 changes: 22 additions & 8 deletions pkg/commands/workload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import (
"context"
"fmt"
"io"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
"time"

"github.com/google/go-cmp/cmp"
ggcrregistry "github.com/google/go-containerregistry/pkg/registry"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/google/go-containerregistry/pkg/v1/types"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
Expand All @@ -47,7 +48,6 @@ import (
"github.com/vmware-tanzu/apps-cli-plugin/pkg/cli-runtime/validation"
"github.com/vmware-tanzu/apps-cli-plugin/pkg/commands"
"github.com/vmware-tanzu/apps-cli-plugin/pkg/flags"
"github.com/vmware-tanzu/apps-cli-plugin/pkg/source"
)

func TestWorkloadCommand(t *testing.T) {
Expand Down Expand Up @@ -1595,10 +1595,25 @@ func TestWorkloadOptionsApplyOptionsToWorkload(t *testing.T) {
}

func TestWorkloadOptionsPublishLocalSource(t *testing.T) {
registry, err := ggcrregistry.TLS("localhost")
utilruntime.Must(err)
defer registry.Close()
u, err := url.Parse(registry.URL)
createServer := func(handler func(w http.ResponseWriter, r *http.Request)) *httptest.Server {
response := []byte("response")
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
odinnordico marked this conversation as resolved.
Show resolved Hide resolved
if r.URL.Path == "/v2/" {
w.WriteHeader(http.StatusOK)
return
}
w.Header().Set("Content-Type", string(types.DockerManifestSchema2))
handler(w, r)
w.Write(response)
}))
}
reg := createServer(func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet {
w.Header().Set("Docker-Content-Digest", "sha")
}
})
defer reg.Close()
u, err := url.Parse(reg.URL)
utilruntime.Must(err)
registryHost := u.Host

Expand Down Expand Up @@ -1674,7 +1689,6 @@ Published source

cmd := &cobra.Command{}
ctx := cli.WithCommand(context.Background(), cmd)
ctx = source.StashGgcrRemoteOptions(ctx, remote.WithTransport(registry.Client().Transport))
odinnordico marked this conversation as resolved.
Show resolved Hide resolved

opts := &commands.WorkloadOptions{}
opts.LoadDefaults(c)
Expand Down
35 changes: 26 additions & 9 deletions pkg/source/imgpkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,32 @@ package source
import (
"context"
"fmt"

odinnordico marked this conversation as resolved.
Show resolved Hide resolved
"os"
"path"
"time"

"github.com/cppforlife/go-cli-ui/ui"
regname "github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/k14s/imgpkg/pkg/imgpkg/plainimage"
"github.com/k14s/imgpkg/pkg/imgpkg/registry"
"github.com/vmware-tanzu/carvel-imgpkg/pkg/imgpkg/plainimage"
"github.com/vmware-tanzu/carvel-imgpkg/pkg/imgpkg/registry"
)

func ImgpkgPush(ctx context.Context, dir string, excludedFiles []string, image string) (string, error) {
options := RetrieveGgcrRemoteOptions(ctx)
// TODO support more registry options
reg, err := registry.NewRegistry(registry.Opts{VerifyCerts: true}, options...)
envFunction := func() []string {
envVars := os.Environ()
_, present := os.LookupEnv("IMGPKG_ENABLE_IAAS_AUTH")
if !present {
envVars = append(envVars, "IMGPKG_ENABLE_IAAS_AUTH=false")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question Are you sure you want to change the imgpkg defaults? Many people expect the credential helpers to work by default. Minimally, this change should be called out on the PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@odinnordico : I removed this env var section and built it locally. CLI commands for local path flow works. I am able to verify the images on the registry.

}
return envVars
}

options.EnvironFunc = envFunction

// TODO: support more registry options using apps plugin configuration
reg, err := registry.NewSimpleRegistry(options)
if err != nil {
return "", fmt.Errorf("unable to create a registry with provided options: %v", err)
}
Expand All @@ -54,14 +67,18 @@ func ImgpkgPush(ctx context.Context, dir string, excludedFiles []string, image s

type ggcrRemoteOptionsStashKey struct{}

func StashGgcrRemoteOptions(ctx context.Context, options ...remote.Option) context.Context {
func StashGgcrRemoteOptions(ctx context.Context, options registry.Opts) context.Context {
odinnordico marked this conversation as resolved.
Show resolved Hide resolved
return context.WithValue(ctx, ggcrRemoteOptionsStashKey{}, options)
}

func RetrieveGgcrRemoteOptions(ctx context.Context) []remote.Option {
options, ok := ctx.Value(ggcrRemoteOptionsStashKey{}).([]remote.Option)
func RetrieveGgcrRemoteOptions(ctx context.Context) registry.Opts {
options, ok := ctx.Value(ggcrRemoteOptionsStashKey{}).(registry.Opts)
if !ok {
return []remote.Option{}
return registry.Opts{
VerifyCerts: true,
RetryCount: 8,
ResponseHeaderTimeout: 300 * time.Second,
}
odinnordico marked this conversation as resolved.
Show resolved Hide resolved
}
return options
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading