Skip to content

Commit

Permalink
Upgrade go-provider (#53)
Browse files Browse the repository at this point in the history
This upgrades pulumi-go-provider to latest. Code was automatically
migrated using a slightly modified patch described
[here](pulumi/pulumi-go-provider#227 (comment)).

---------

Co-authored-by: Ian Wahbe <[email protected]>
  • Loading branch information
blampe and iwahbe authored May 13, 2024
1 parent 9b789f3 commit ff71c25
Show file tree
Hide file tree
Showing 20 changed files with 208 additions and 704 deletions.
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ require (
github.com/muesli/reflow v0.3.0
github.com/otiai10/copy v1.14.0
github.com/pulumi/providertest v0.0.12
github.com/pulumi/pulumi-go-provider v0.16.0
github.com/pulumi/pulumi-go-provider/integration v0.10.1-0.20240314105842-9fbffb634faf
github.com/pulumi/pulumi-go-provider v0.16.1-0.20240426163030-72606b1e6fb7
github.com/pulumi/pulumi-java/pkg v0.10.0
github.com/pulumi/pulumi/pkg/v3 v3.113.3
github.com/pulumi/pulumi/sdk/go/pulumi-language-go/v3 v3.0.0-20240415162817-44c8de53d5d2
Expand Down Expand Up @@ -455,7 +454,7 @@ require (
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect
golang.org/x/exp/typeparams v0.0.0-20240314144324-c7f7c6466f7f // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
Expand Down
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2316,10 +2316,8 @@ github.com/pulumi/esc v0.6.2 h1:+z+l8cuwIauLSwXQS0uoI3rqB+YG4SzsZYtHfNoXBvw=
github.com/pulumi/esc v0.6.2/go.mod h1:jNnYNjzsOgVTjCp0LL24NsCk8ZJxq4IoLQdCT0X7l8k=
github.com/pulumi/providertest v0.0.12 h1:UjcFQHHs4AGJyJqxhvC2q8yVQ7Li+UyCyP95HZcK03U=
github.com/pulumi/providertest v0.0.12/go.mod h1:REAoaN+hGOtdWJGirfWYqcSjCejlbGfzyVTUuemJTuE=
github.com/pulumi/pulumi-go-provider v0.16.0 h1:vLAiECprIoLdTPd0UFs9Vv/HgSw7l/SBAurRBm3vpSU=
github.com/pulumi/pulumi-go-provider v0.16.0/go.mod h1:2yjjeyMSmsb/o/BRJeWk+kcXrJWF5U2EulJKnN7qVLs=
github.com/pulumi/pulumi-go-provider/integration v0.10.1-0.20240314105842-9fbffb634faf h1:7fDWArOUFH+qQ9EywoC4K2ElXP76Ks/CtVJkEBmv2pk=
github.com/pulumi/pulumi-go-provider/integration v0.10.1-0.20240314105842-9fbffb634faf/go.mod h1:sf87soow+4JkV361vHI0W04hpJmWiWajzJytFMNonCE=
github.com/pulumi/pulumi-go-provider v0.16.1-0.20240426163030-72606b1e6fb7 h1:zHoiZbyFIeEfdoaqwA9Lp3jzdDgtdCPKM2aWhaA4EGg=
github.com/pulumi/pulumi-go-provider v0.16.1-0.20240426163030-72606b1e6fb7/go.mod h1:sJUl1EjF3BQXAkrOeRhS3kZq17lz2o2QnTQd+c1FepU=
github.com/pulumi/pulumi-java/pkg v0.10.0 h1:D1i5MiiNrxYr2uJ1szcj1aQwF9DYv7TTsPmajB9dKSw=
github.com/pulumi/pulumi-java/pkg v0.10.0/go.mod h1:xu6UgYtQm+xXOo1/DZNa2CWVPytu+RMkZVTtI7w7ffY=
github.com/pulumi/pulumi-yaml v1.6.0 h1:mb/QkebWXTa1fR+P3ZkCCHGXOYC6iTN8X8By9eNz8xM=
Expand Down Expand Up @@ -3003,8 +3001,8 @@ golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down
12 changes: 6 additions & 6 deletions provider/internal/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package internal
import (
"bufio"
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
Expand All @@ -40,7 +41,6 @@ import (
"github.com/sirupsen/logrus"

provider "github.com/pulumi/pulumi-go-provider"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
)
Expand Down Expand Up @@ -157,7 +157,7 @@ func (c *cli) rc() *regclient.RegClient {

// tail is meant to be called as a goroutine and will pipe output from the CLI
// back to the Pulumi engine. Requires a corresponding call to close.
func (c *cli) tail(ctx provider.Context) {
func (c *cli) tail(ctx context.Context) {
c.done = make(chan struct{}, 1)
defer func() {
c.done <- struct{}{}
Expand All @@ -171,18 +171,18 @@ func (c *cli) tail(ctx provider.Context) {
s := bufio.NewScanner(c.r)
for s.Scan() {
text := s.Text()
ctx.LogStatus(diag.Info, text)
provider.GetLogger(ctx).InfoStatus(text)
_, _ = b.WriteString(text + "\n")
}
ctx.LogStatus(diag.Info, "") // clear confusing "DONE" statements.
provider.GetLogger(ctx).InfoStatus("") // clear confusing "DONE" statements.

if c.dumplogs {
// Persist the full Docker output on error for easier debugging.
if b.Len() > 0 {
ctx.Log(diag.Info, b.String())
provider.GetLogger(ctx).Info(b.String())
}
if c.err.Len() > 0 {
ctx.Log(diag.Error, c.err.String())
provider.GetLogger(ctx).Error(c.err.String())
}
}
}
Expand Down
28 changes: 13 additions & 15 deletions provider/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,19 @@ import (
"github.com/regclient/regclient/types/ref"

provider "github.com/pulumi/pulumi-go-provider"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
)

// Client handles all our Docker API calls.
type Client interface {
Build(ctx provider.Context, b Build) (*client.SolveResponse, error)
Build(ctx context.Context, b Build) (*client.SolveResponse, error)
BuildKitEnabled() (bool, error)
Inspect(ctx context.Context, id string) ([]descriptor.Descriptor, error)
Delete(ctx context.Context, id string) error

ManifestCreate(ctx provider.Context, push bool, target string, refs ...string) error
ManifestInspect(ctx provider.Context, target string) (string, error)
ManifestDelete(ctx provider.Context, target string) error
ManifestCreate(ctx context.Context, push bool, target string, refs ...string) error
ManifestInspect(ctx context.Context, target string) (string, error)
ManifestDelete(ctx context.Context, target string) error
}

// Build encapsulates all of the user-provider build parameters and options.
Expand Down Expand Up @@ -98,13 +97,12 @@ func newDockerCLI(config *Config) (*command.DockerCli, error) {
// "default", if no targets were specified) to SolveResponses, which capture
// the build's digest and tags (if any).
func (c *cli) Build(
pctx provider.Context,
ctx context.Context,
build Build,
) (*client.SolveResponse, error) {
ctx := context.Context(pctx)
opts := build.BuildOptions()

go c.tail(pctx)
go c.tail(ctx)
defer contract.IgnoreClose(c)

if build.ShouldExec() {
Expand Down Expand Up @@ -134,7 +132,7 @@ func (c *cli) Build(
for _, d := range w.Detail {
fmt.Fprintf(b, "\n%s", d)
}
pctx.Log(diag.Warning, b.String())
provider.GetLogger(ctx).Warning(b.String())
}
}()

Expand Down Expand Up @@ -247,7 +245,7 @@ func (c *cli) BuildKitEnabled() (bool, error) {
return c.Cli.BuildKitEnabled()
}

func (c *cli) ManifestCreate(ctx provider.Context, push bool, target string, refs ...string) error {
func (c *cli) ManifestCreate(ctx context.Context, push bool, target string, refs ...string) error {
go c.tail(ctx)
defer contract.IgnoreClose(c)

Expand All @@ -271,11 +269,11 @@ func (c *cli) ManifestCreate(ctx provider.Context, push bool, target string, ref
cmd.SetErr(c.Err())
cmd.SetOut(c.Out())

ctx.Log(diag.Debug, fmt.Sprint("creating manifest with args", args))
provider.GetLogger(ctx).Debug(fmt.Sprint("creating manifest with args", args))
return cmd.ExecuteContext(ctx)
}

func (c *cli) ManifestInspect(ctx provider.Context, target string) (string, error) {
func (c *cli) ManifestInspect(ctx context.Context, target string) (string, error) {
rc := c.rc()

ref, err := ref.New(target)
Expand All @@ -291,17 +289,17 @@ func (c *cli) ManifestInspect(ctx provider.Context, target string) (string, erro
return string(m.GetDescriptor().Digest), nil
}

func (c *cli) ManifestDelete(ctx provider.Context, target string) error {
func (c *cli) ManifestDelete(ctx context.Context, target string) error {
rc := c.rc()

ref, err := ref.New(target)
if err != nil {
return err
}

err = rc.ManifestDelete(context.Context(ctx), ref)
err = rc.ManifestDelete(ctx, ref)
if errors.Is(err, errs.ErrHTTPStatus) {
ctx.Log(diag.Warning, "this registry does not support deletions")
provider.GetLogger(ctx).Warning("this registry does not support deletions")
return nil
}
if err != nil {
Expand Down
76 changes: 25 additions & 51 deletions provider/internal/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ package internal
import (
"bytes"
"context"
"io"
"log/slog"
"os"
"path/filepath"
"testing"

"github.com/docker/docker/api/types/registry"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"

"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
)

func TestAuth(t *testing.T) {
Expand Down Expand Up @@ -79,21 +78,9 @@ func TestCustomHost(t *testing.T) {

func TestBuild(t *testing.T) {
t.Parallel()
// Workaround for https://github.com/pulumi/pulumi-go-provider/issues/159
ctrl, ctx := gomock.WithContext(context.Background(), t)
pctx := NewMockProviderContext(ctrl)
pctx.EXPECT().Log(gomock.Any(), gomock.Any()).AnyTimes()
pctx.EXPECT().LogStatus(gomock.Any(), gomock.Any()).AnyTimes()
pctx.EXPECT().Done().Return(ctx.Done()).AnyTimes()
pctx.EXPECT().
Value(gomock.Any()).
DoAndReturn(func(key any) any { return ctx.Value(key) }).
AnyTimes()
pctx.EXPECT().Err().Return(ctx.Err()).AnyTimes()
pctx.EXPECT().Deadline().Return(ctx.Deadline()).AnyTimes()

tmpdir := t.TempDir()
max := Max
Max := Max

exampleContext := &BuildContext{Context: Context{Location: "../../examples/app"}}

Expand Down Expand Up @@ -135,7 +122,7 @@ func TestBuild(t *testing.T) {
Tags: []string{"cached"},
CacheTo: []CacheTo{{Local: &CacheToLocal{
Dest: filepath.Join(tmpdir, "cache"),
CacheWithMode: CacheWithMode{Mode: &max},
CacheWithMode: CacheWithMode{Mode: &Max},
}}},
CacheFrom: []CacheFrom{{Local: &CacheFromLocal{
Src: filepath.Join(tmpdir, "cache"),
Expand Down Expand Up @@ -300,12 +287,13 @@ func TestBuild(t *testing.T) {
if tt.skip {
t.Skip()
}
ctx := context.Background()
cli := testcli(t, true, tt.auths...)

build, err := tt.args.toBuild(pctx, false)
build, err := tt.args.toBuild(ctx, false)
require.NoError(t, err)

_, err = cli.Build(pctx, build)
_, err = cli.Build(ctx, build)
assert.NoError(t, err, cli.err.String())
})
}
Expand Down Expand Up @@ -366,14 +354,22 @@ func TestNormalizeReference(t *testing.T) {
}
}

//nolint:paralleltest // Overrides default logger.
func TestBuildError(t *testing.T) {
t.Parallel()

if os.Getenv("CI") != "" {
t.Skip("flaky on CI for some reason")
}

ctrl, ctx := gomock.WithContext(context.Background(), t)
l := slog.Default()
defer slog.SetDefault(l)

// Override go-provider's default logger to capture and tee to stdout.
logger := &bytes.Buffer{}
slog.SetDefault(
slog.New(
slog.NewTextHandler(io.MultiWriter(logger, os.Stdout), nil),
),
)

exampleContext := &BuildContext{Context: Context{Location: "../../examples/app"}}

Expand All @@ -383,28 +379,14 @@ func TestBuildError(t *testing.T) {
Inline: "FROM alpine\nRUN echo hello\nRUN badcmd",
},
}
logged := bytes.Buffer{}

pctx := NewMockProviderContext(ctrl)
pctx.EXPECT().Done().Return(ctx.Done()).AnyTimes()
pctx.EXPECT().
Value(gomock.Any()).
DoAndReturn(func(key any) any { return ctx.Value(key) }).
AnyTimes()
pctx.EXPECT().Err().Return(ctx.Err()).AnyTimes()
pctx.EXPECT().Deadline().Return(ctx.Deadline()).AnyTimes()

pctx.EXPECT().LogStatus(gomock.Any(), gomock.Any()).AnyTimes()
pctx.EXPECT().Log(gomock.Any(), gomock.Any()).DoAndReturn(func(_ diag.Severity, msg string) {
logged.WriteString(msg)
}).AnyTimes()

ctx := context.Background()
cli := testcli(t, true)

build, err := args.toBuild(pctx, false)
build, err := args.toBuild(ctx, false)
require.NoError(t, err)

_, err = cli.Build(pctx, build)
_, err = cli.Build(ctx, build)
assert.Error(t, err)

want := []string{
Expand All @@ -413,7 +395,7 @@ func TestBuildError(t *testing.T) {
}

for _, want := range want {
assert.Contains(t, logged.String(), want)
assert.Contains(t, logger.String(), want)
}
assert.ErrorContains(t, err,
`process "/bin/sh -c badcmd" did not complete successfully: exit code: 127`,
Expand All @@ -422,7 +404,6 @@ func TestBuildError(t *testing.T) {

func TestBuildExecError(t *testing.T) {
t.Parallel()
ctrl, _ := gomock.WithContext(context.Background(), t)

exampleContext := &BuildContext{Context: Context{Location: "../../examples/app"}}

Expand All @@ -434,20 +415,13 @@ func TestBuildExecError(t *testing.T) {
Exec: true,
}

pctx := NewMockProviderContext(ctrl)
pctx.EXPECT().Log(
diag.Warning,
"No exports were specified so the build will only remain in the local build cache. "+
"Use `push` to upload the image to a registry, or silence this warning with a `cacheonly` export.",
)
pctx.EXPECT().LogStatus(gomock.Any(), gomock.Any()).AnyTimes()

ctx := context.Background()
cli := testcli(t, true)

build, err := args.toBuild(pctx, false)
build, err := args.toBuild(ctx, false)
require.NoError(t, err)

_, err = cli.Build(pctx, build)
_, err = cli.Build(ctx, build)
assert.Error(t, err)

want := []string{
Expand Down
Loading

0 comments on commit ff71c25

Please sign in to comment.