Skip to content
This repository was archived by the owner on Mar 24, 2023. It is now read-only.

Commit d07bcf7

Browse files
committed
Don't leak watch files
1 parent ef1cda7 commit d07bcf7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+510
-189
lines changed

Gopkg.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ ignored = [
7878
name = "github.com/ghodss/yaml"
7979
version = "1.0.0"
8080

81+
[[constraint]]
82+
name = "github.com/golang/mock"
83+
version = "v1.2.0"
84+
8185
# Overrides for Kustomize & Helm
8286
[[constraint]]
8387
name = "k8s.io/helm"

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ _mockgen:
185185
-destination pkg/test-mocks/apptype/determine_type_mock.go \
186186
-package apptype \
187187
github.com/replicatedhq/ship/pkg/specs/apptype \
188-
Inspector & \
188+
Inspector,LocalAppCopy & \
189189
mockgen \
190190
-destination pkg/test-mocks/replicatedapp/resolve_replicated_app.go \
191191
-package replicatedapp \

cmd/hack-docs/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"fmt"
55

6-
"github.com/mcuadros/go-jsonschema-generator"
6+
jsonschema "github.com/mcuadros/go-jsonschema-generator"
77
"github.com/replicatedhq/ship/pkg/api"
88
)
99

hack/get_build_deps.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ go get -u golang.org/x/tools/cmd/goimports
55
go get -u golang.org/x/lint/golint
66
go get github.com/golang/mock/gomock
77
go install github.com/golang/mock/mockgen
8-
go get github.com/elazarl/go-bindata-assetfs/...
9-
go get -u github.com/jteeuwen/go-bindata/...
8+
go get github.com/elazarl/go-bindata-assetfs/go-bindata-assetfs
9+
go get -u github.com/jteeuwen/go-bindata/go-bindata
1010
go get -u github.com/gordonklaus/ineffassign

pkg/api/asset_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"testing"
55

66
"github.com/stretchr/testify/require"
7-
"gopkg.in/yaml.v2"
7+
yaml "gopkg.in/yaml.v2"
88
)
99

1010
func TestDeserialize(t *testing.T) {

pkg/api/lifecycle_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"testing"
55

66
"github.com/stretchr/testify/require"
7-
"gopkg.in/yaml.v2"
7+
yaml "gopkg.in/yaml.v2"
88
)
99

1010
func TestDeserializeLifecycle(t *testing.T) {

pkg/cli/root.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"os"
66
"strings"
77

8-
"github.com/hashicorp/go-multierror"
8+
multierror "github.com/hashicorp/go-multierror"
99
"github.com/replicatedhq/ship/pkg/constants"
1010
"github.com/replicatedhq/ship/pkg/version"
1111
"github.com/spf13/cobra"

pkg/e2e/vendor_client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
"github.com/go-kit/kit/log"
1212
"github.com/go-kit/kit/log/level"
13-
"github.com/hashicorp/go-multierror"
13+
multierror "github.com/hashicorp/go-multierror"
1414
"github.com/pkg/errors"
1515
)
1616

pkg/filetree/loader_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
state2 "github.com/replicatedhq/ship/pkg/test-mocks/state"
1212
"github.com/replicatedhq/ship/pkg/testing/tmpfs"
1313
"github.com/stretchr/testify/require"
14-
"gopkg.in/yaml.v2"
14+
yaml "gopkg.in/yaml.v2"
1515
)
1616

1717
type TestCase struct {

pkg/lifecycle/daemon/routes_navcycle_getcycle_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/replicatedhq/ship/pkg/lifecycle/daemon/daemontypes"
1414
"github.com/replicatedhq/ship/pkg/testing/logger"
1515
"github.com/stretchr/testify/require"
16-
"gopkg.in/yaml.v2"
16+
yaml "gopkg.in/yaml.v2"
1717
)
1818

1919
type lifecycleTestcase struct {

pkg/lifecycle/daemon/ui.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/http"
77
"strings"
88

9-
"github.com/elazarl/go-bindata-assetfs"
9+
assetfs "github.com/elazarl/go-bindata-assetfs"
1010
"github.com/go-kit/kit/log"
1111
"github.com/go-kit/kit/log/level"
1212
)

pkg/lifecycle/kustomize/kustomizer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/replicatedhq/ship/pkg/lifecycle/daemon/daemontypes"
1919
"github.com/replicatedhq/ship/pkg/state"
2020
"github.com/spf13/afero"
21-
"gopkg.in/yaml.v2"
21+
yaml "gopkg.in/yaml.v2"
2222
"sigs.k8s.io/kustomize/pkg/patch"
2323
ktypes "sigs.k8s.io/kustomize/pkg/types"
2424
)

pkg/lifecycle/kustomize/post_kustomize_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/replicatedhq/ship/pkg/testing/logger"
77
"github.com/replicatedhq/ship/pkg/util"
88
"github.com/stretchr/testify/require"
9-
"gopkg.in/yaml.v2"
9+
yaml "gopkg.in/yaml.v2"
1010
)
1111

1212
type kustomizeTestFile struct {

pkg/lifecycle/render/amazoneks/render.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"text/template"
99

1010
"github.com/go-kit/kit/log"
11-
"github.com/hashicorp/go-multierror"
11+
multierror "github.com/hashicorp/go-multierror"
1212
"github.com/pkg/errors"
1313
"github.com/replicatedhq/libyaml"
1414
"github.com/replicatedhq/ship/pkg/api"

pkg/lifecycle/render/config/resolve/api_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/spf13/viper"
1919
"github.com/stretchr/testify/assert"
2020
"github.com/stretchr/testify/require"
21-
"gopkg.in/yaml.v2"
21+
yaml "gopkg.in/yaml.v2"
2222
)
2323

2424
type apiTestcase struct {

pkg/lifecycle/render/googlegke/render.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"github.com/Masterminds/sprig"
1010
"github.com/go-kit/kit/log"
11-
"github.com/hashicorp/go-multierror"
11+
multierror "github.com/hashicorp/go-multierror"
1212
"github.com/pkg/errors"
1313
"github.com/replicatedhq/libyaml"
1414
"github.com/replicatedhq/ship/pkg/api"

pkg/lifecycle/render/helm/template_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"path/filepath"
77
"testing"
88

9+
"github.com/emosbaugh/yaml"
910
"github.com/golang/mock/gomock"
1011
"github.com/replicatedhq/libyaml"
1112
"github.com/replicatedhq/ship/pkg/api"
@@ -21,7 +22,6 @@ import (
2122
"github.com/spf13/afero"
2223
"github.com/spf13/viper"
2324
"github.com/stretchr/testify/require"
24-
"gopkg.in/yaml.v2"
2525
"k8s.io/helm/pkg/chartutil"
2626
)
2727

pkg/lifecycle/render/render_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"github.com/spf13/viper"
2727
"github.com/stretchr/testify/assert"
2828
"github.com/stretchr/testify/require"
29-
"gopkg.in/yaml.v2"
29+
yaml "gopkg.in/yaml.v2"
3030
)
3131

3232
type testcase struct {

pkg/logger/logger.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/go-kit/kit/log"
1010
"github.com/go-kit/kit/log/level"
1111
"github.com/go-stack/stack"
12-
"github.com/hashicorp/go-multierror"
12+
multierror "github.com/hashicorp/go-multierror"
1313
"github.com/replicatedhq/ship/pkg/constants"
1414
"github.com/spf13/afero"
1515
"github.com/spf13/viper"

pkg/ship/dig.go

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func buildInjector(v *viper.Viper) (*dig.Container, error) {
6969
templates.NewBuilderBuilder,
7070
specs.NewIDPatcher,
7171
apptype.NewInspector,
72+
apptype.NewLocalAppCopy,
7273
util.NewAssetUploader,
7374
patch.NewShipPatcher,
7475

pkg/specs/apptype/determine_type.go

+52-17
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,19 @@ import (
2222
"github.com/spf13/viper"
2323
)
2424

25+
type LocalAppCopy interface {
26+
GetType() string
27+
GetLocalPath() string
28+
Remove(FS afero.Afero) error
29+
}
30+
2531
type Inspector interface {
2632
// DetermineApplicationType loads and application from upstream,
2733
// returning the app type and the local path where its been downloaded (when applicable),
2834
DetermineApplicationType(
2935
ctx context.Context,
3036
upstream string,
31-
) (appType string, localPath string, err error)
37+
) (app LocalAppCopy, err error)
3238
}
3339

3440
func NewInspector(
@@ -59,18 +65,18 @@ type FileFetcher interface {
5965
GetFiles(ctx context.Context, upstream, savePath string) (string, error)
6066
}
6167

62-
func (r *inspector) DetermineApplicationType(ctx context.Context, upstream string) (appType string, localPath string, err error) {
68+
func (r *inspector) DetermineApplicationType(ctx context.Context, upstream string) (app LocalAppCopy, err error) {
6369
// hack hack hack
6470
isReplicatedApp := strings.HasPrefix(upstream, "replicated.app") ||
6571
strings.HasPrefix(upstream, "staging.replicated.app") ||
6672
strings.HasPrefix(upstream, "local.replicated.app")
6773
if isReplicatedApp {
68-
return "replicated.app", "", nil
74+
return &localAppCopy{AppType: "replicated.app"}, nil
6975
}
7076

7177
parts := strings.SplitN(upstream, "?", 2)
7278
if _, err := os.Stat(parts[0]); err == nil && gogetter.IsShipYaml(parts[0]) {
73-
return "runbook.replicated.app", parts[0], nil
79+
return &localAppCopy{AppType: "runbook.replicated.app", LocalPath: parts[0]}, nil
7480
}
7581

7682
r.ui.Info(fmt.Sprintf("Attempting to retrieve upstream %s ...", upstream))
@@ -90,19 +96,15 @@ func (r *inspector) DetermineApplicationType(ctx context.Context, upstream strin
9096
return r.determineTypeFromContents(ctx, upstream, &fetcher)
9197
}
9298

93-
return "", "", errors.New(fmt.Sprintf("upstream %s is not a replicated app, a github repo, or compatible with go-getter", upstream))
99+
return nil, errors.New(fmt.Sprintf("upstream %s is not a replicated app, a github repo, or compatible with go-getter", upstream))
94100
}
95101

96-
func (r *inspector) determineTypeFromContents(ctx context.Context, upstream string, fetcher FileFetcher) (
97-
applicationType string,
98-
checkoutPath string,
99-
err error,
100-
) {
102+
func (r *inspector) determineTypeFromContents(ctx context.Context, upstream string, fetcher FileFetcher) (app LocalAppCopy, err error) {
101103
debug := level.Debug(r.logger)
102104

103105
repoSavePath, err := r.fs.TempDir(constants.ShipPathInternalTmp, "repo")
104106
if err != nil {
105-
return "", "", errors.Wrap(err, "create tmp dir")
107+
return nil, errors.Wrap(err, "create tmp dir")
106108
}
107109

108110
finalPath, err := fetcher.GetFiles(ctx, upstream, repoSavePath)
@@ -129,10 +131,10 @@ func (r *inspector) determineTypeFromContents(ctx context.Context, upstream stri
129131
}
130132

131133
if !hasSucceeded {
132-
return "", "", retryError
134+
return nil, retryError
133135
}
134136
} else {
135-
return "", "", err
137+
return nil, err
136138
}
137139
}
138140

@@ -141,10 +143,10 @@ func (r *inspector) determineTypeFromContents(ctx context.Context, upstream stri
141143
for _, filename := range []string{"ship.yaml", "ship.yml"} {
142144
isReplicatedApp, err = r.fs.Exists(path.Join(finalPath, filename))
143145
if err != nil {
144-
return "", "", errors.Wrapf(err, "check for %s", filename)
146+
return nil, errors.Wrapf(err, "check for %s", filename)
145147
}
146148
if isReplicatedApp {
147-
return "inline.replicated.app", finalPath, nil
149+
return &localAppCopy{AppType: "inline.replicated.app", LocalPath: finalPath, rootTempDir: repoSavePath}, nil
148150
}
149151
}
150152

@@ -156,8 +158,41 @@ func (r *inspector) determineTypeFromContents(ctx context.Context, upstream stri
156158
debug.Log("event", "isChart.check", "isChart", isChart)
157159

158160
if isChart {
159-
return "helm", finalPath, nil
161+
return &localAppCopy{AppType: "helm", LocalPath: finalPath, rootTempDir: repoSavePath}, nil
160162
}
161163

162-
return "k8s", finalPath, nil
164+
return &localAppCopy{AppType: "k8s", LocalPath: finalPath, rootTempDir: repoSavePath}, nil
165+
}
166+
167+
func NewLocalAppCopy(
168+
appType string,
169+
localPath string,
170+
rootTempDir string,
171+
) LocalAppCopy {
172+
return &localAppCopy{
173+
AppType: appType,
174+
LocalPath: localPath,
175+
rootTempDir: rootTempDir,
176+
}
177+
}
178+
179+
type localAppCopy struct {
180+
AppType string
181+
LocalPath string
182+
rootTempDir string
183+
}
184+
185+
func (c *localAppCopy) GetType() string {
186+
return c.AppType
187+
}
188+
189+
func (c *localAppCopy) GetLocalPath() string {
190+
return c.LocalPath
191+
}
192+
193+
func (c *localAppCopy) Remove(fs afero.Afero) error {
194+
if c.rootTempDir == "" {
195+
return nil
196+
}
197+
return fs.RemoveAll(c.rootTempDir)
163198
}

pkg/specs/chart.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/replicatedhq/ship/pkg/api"
1616
"github.com/replicatedhq/ship/pkg/constants"
1717
"github.com/replicatedhq/ship/pkg/util"
18-
"gopkg.in/yaml.v2"
18+
yaml "gopkg.in/yaml.v2"
1919
)
2020

2121
func (r *Resolver) DefaultHelmUnforkRelease(upstreamAsset api.Asset, forkedAsset api.Asset) api.Spec {

pkg/specs/gogetter/go_getter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"github.com/go-kit/kit/log"
1111
"github.com/go-kit/kit/log/level"
12-
"github.com/hashicorp/go-getter"
12+
getter "github.com/hashicorp/go-getter"
1313
"github.com/pkg/errors"
1414
"github.com/replicatedhq/ship/pkg/constants"
1515
"github.com/replicatedhq/ship/pkg/util"

0 commit comments

Comments
 (0)