Skip to content

Commit

Permalink
add logging when rewriting
Browse files Browse the repository at this point in the history
Signed-off-by: Ludvig Liljenberg <lliljenberg@microsoft.com>
  • Loading branch information
ludfjig committed Sep 20, 2023
1 parent e258191 commit d24a4bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions pkg/porter/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"io"
"strings"

"get.porter.sh/porter/pkg/cache"
Expand Down Expand Up @@ -198,7 +199,7 @@ func (p *Porter) resolveBundleReference(ctx context.Context, opts *BundleReferen
pullOpts := *opts // make a copy just to do the pull
pullOpts.Reference = ref.String()

err := ensureVPrefix(&pullOpts)
err := ensureVPrefix(&pullOpts, p.Out)
if err != nil {
return err
}
Expand Down Expand Up @@ -309,7 +310,7 @@ func (p *Porter) BuildActionArgs(ctx context.Context, installation storage.Insta
// Version tag should always be prefixed with a "v", see https://github.com/getporter/porter/issues/2886.
// This is safe because "porter publish" adds a "v", see
// https://github.com/getporter/porter/blob/17bd7816ef6bde856793f6122e32274aa9d01d1b/pkg/storage/installation.go#L350
func ensureVPrefix(opts *BundleReferenceOptions) error {
func ensureVPrefix(opts *BundleReferenceOptions, out io.Writer) error {
var ociRef *cnab.OCIReference
if opts._ref != nil {
ociRef = opts._ref
Expand All @@ -332,6 +333,7 @@ func ensureVPrefix(opts *BundleReferenceOptions) error {
}

// always update the .Reference string, but don't add the _ref field unless it was already there (non-nil)
fmt.Fprintf(out, "WARNING: using reference %q instead of %q because missing v-prefix on tag\n", vRef.String(), ociRef.String())
opts.Reference = vRef.String()
if opts._ref != nil {
opts._ref = &vRef
Expand Down
9 changes: 5 additions & 4 deletions pkg/porter/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package porter
import (
"context"
"fmt"
"os"
"strings"
"testing"

Expand Down Expand Up @@ -585,7 +586,7 @@ func Test_ensureVPrefix(t *testing.T) {
assert.False(t, tt.args.opts._ref.Tag()[0] == 'v')
}

err := ensureVPrefix(tt.args.opts)
err := ensureVPrefix(tt.args.opts, os.Stdout)

// after
tt.wantErr(t, err, fmt.Sprintf("ensureVPrefix(%v)", tt.args.opts))
Expand Down Expand Up @@ -653,7 +654,7 @@ func Test_ensureVPrefix_idempotent(t *testing.T) {
assert.True(t, tt.args.opts._ref.Tag()[1] != 'v')
}

err := ensureVPrefix(tt.args.opts)
err := ensureVPrefix(tt.args.opts, os.Stdout)

// after
tt.wantErr(t, err, fmt.Sprintf("ensureVPrefix(%v)", tt.args.opts))
Expand Down Expand Up @@ -686,7 +687,7 @@ func Test_ensureVPrefix_latest(t *testing.T) {
bundleRef: nil,
}

err := ensureVPrefix(&opts)
err := ensureVPrefix(&opts, os.Stdout)
assert.NoError(t, err)

// should be unchanged
Expand All @@ -711,7 +712,7 @@ func Test_ensureVPrefix_missing_tag(t *testing.T) {
bundleRef: nil,
}

err := ensureVPrefix(&opts)
err := ensureVPrefix(&opts, os.Stdout)
assert.NoError(t, err)

// should be unchanged
Expand Down

0 comments on commit d24a4bf

Please sign in to comment.