Skip to content

Commit 85c5c6e

Browse files
committed
only runCtx and Config changes
1 parent 3fe8b25 commit 85c5c6e

File tree

24 files changed

+264
-474
lines changed

24 files changed

+264
-474
lines changed

cmd/skaffold/app/cmd/build_test.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
2929
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
3030
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
31+
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext"
3132
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
3233
"github.com/GoogleContainerTools/skaffold/testutil"
3334
)
@@ -49,8 +50,8 @@ func (r *mockRunner) Stop() error {
4950
}
5051

5152
func TestTagFlag(t *testing.T) {
52-
mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest.SkaffoldConfig, error) {
53-
return &mockRunner{}, []*latest.SkaffoldConfig{{}}, nil
53+
mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, *runcontext.RunContext, []*latest.SkaffoldConfig, error) {
54+
return &mockRunner{}, &runcontext.RunContext{}, []*latest.SkaffoldConfig{{}}, nil
5455
}
5556

5657
testutil.Run(t, "override tag with argument", func(t *testutil.T) {
@@ -68,8 +69,8 @@ func TestTagFlag(t *testing.T) {
6869
}
6970

7071
func TestQuietFlag(t *testing.T) {
71-
mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest.SkaffoldConfig, error) {
72-
return &mockRunner{}, []*latest.SkaffoldConfig{{}}, nil
72+
mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, *runcontext.RunContext, []*latest.SkaffoldConfig, error) {
73+
return &mockRunner{}, nil, []*latest.SkaffoldConfig{{}}, nil
7374
}
7475

7576
tests := []struct {
@@ -114,8 +115,8 @@ func TestQuietFlag(t *testing.T) {
114115
}
115116

116117
func TestFileOutputFlag(t *testing.T) {
117-
mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest.SkaffoldConfig, error) {
118-
return &mockRunner{}, []*latest.SkaffoldConfig{{}}, nil
118+
mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, *runcontext.RunContext, []*latest.SkaffoldConfig, error) {
119+
return &mockRunner{}, nil, []*latest.SkaffoldConfig{{}}, nil
119120
}
120121

121122
tests := []struct {
@@ -177,16 +178,16 @@ func TestFileOutputFlag(t *testing.T) {
177178
}
178179

179180
func TestRunBuild(t *testing.T) {
180-
errRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest.SkaffoldConfig, error) {
181-
return nil, nil, errors.New("some error")
181+
errRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, *runcontext.RunContext, []*latest.SkaffoldConfig, error) {
182+
return nil, nil, nil, errors.New("some error")
182183
}
183-
mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest.SkaffoldConfig, error) {
184-
return &mockRunner{}, []*latest.SkaffoldConfig{{}}, nil
184+
mockCreateRunner := func(io.Writer, config.SkaffoldOptions) (runner.Runner, *runcontext.RunContext, []*latest.SkaffoldConfig, error) {
185+
return &mockRunner{}, nil, []*latest.SkaffoldConfig{{}}, nil
185186
}
186187

187188
tests := []struct {
188189
description string
189-
mock func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest.SkaffoldConfig, error)
190+
mock func(io.Writer, config.SkaffoldOptions) (runner.Runner, *runcontext.RunContext, []*latest.SkaffoldConfig, error)
190191
shouldErr bool
191192
}{
192193
{

cmd/skaffold/app/cmd/cmd.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"os"
2424
"strings"
2525

26-
sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors"
2726
"github.com/sirupsen/logrus"
2827
"github.com/spf13/cobra"
2928
"github.com/spf13/pflag"
@@ -32,6 +31,7 @@ import (
3231
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
3332
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
3433
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
34+
sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors"
3535
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/instrumentation"
3636
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/server"
3737
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/survey"
@@ -268,8 +268,10 @@ func setUpLogs(stdErr io.Writer, level string, timestamp bool) error {
268268

269269
func alwaysSucceedWhenCancelled(ctx context.Context, cfg sErrors.Config, err error) error {
270270
// if the context was cancelled act as if all is well
271-
if err == nil || ctx.Err() == context.Canceled {
271+
if err != nil && ctx.Err() == context.Canceled {
272272
return nil
273+
} else if err == nil || err == context.Canceled {
274+
return err
273275
}
274276
return sErrors.ShowAIError(cfg, err)
275277
}

cmd/skaffold/app/cmd/debug_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
2525
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
26+
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext"
2627
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
2728
"github.com/GoogleContainerTools/skaffold/testutil"
2829
)
@@ -48,8 +49,8 @@ func TestNewCmdDebug(t *testing.T) {
4849
func TestDebugIndependentFromDev(t *testing.T) {
4950
mockRunner := &mockDevRunner{}
5051
testutil.Run(t, "DevDebug", func(t *testutil.T) {
51-
t.Override(&createRunner, func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest.SkaffoldConfig, error) {
52-
return mockRunner, []*latest.SkaffoldConfig{{}}, nil
52+
t.Override(&createRunner, func(io.Writer, config.SkaffoldOptions) (runner.Runner, *runcontext.RunContext, []*latest.SkaffoldConfig, error) {
53+
return mockRunner, nil, []*latest.SkaffoldConfig{{}}, nil
5354
})
5455
t.Override(&opts, config.SkaffoldOptions{})
5556
t.Override(&doDev, func(context.Context, io.Writer) error {

cmd/skaffold/app/cmd/dev_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
2626
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
27+
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext"
2728
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
2829
"github.com/GoogleContainerTools/skaffold/testutil"
2930
)
@@ -95,8 +96,8 @@ func TestDoDev(t *testing.T) {
9596
hasDeployed: test.hasDeployed,
9697
errDev: context.Canceled,
9798
}
98-
t.Override(&createRunner, func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest.SkaffoldConfig, error) {
99-
return mockRunner, []*latest.SkaffoldConfig{{}}, nil
99+
t.Override(&createRunner, func(io.Writer, config.SkaffoldOptions) (runner.Runner, *runcontext.RunContext, []*latest.SkaffoldConfig, error) {
100+
return mockRunner, &runcontext.RunContext{}, []*latest.SkaffoldConfig{{}}, nil
100101
})
101102
t.Override(&opts, config.SkaffoldOptions{
102103
Cleanup: true,
@@ -145,8 +146,8 @@ func TestDevConfigChange(t *testing.T) {
145146
testutil.Run(t, "test config change", func(t *testutil.T) {
146147
mockRunner := &mockConfigChangeRunner{}
147148

148-
t.Override(&createRunner, func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest.SkaffoldConfig, error) {
149-
return mockRunner, []*latest.SkaffoldConfig{{}}, nil
149+
t.Override(&createRunner, func(io.Writer, config.SkaffoldOptions) (runner.Runner, *runcontext.RunContext, []*latest.SkaffoldConfig, error) {
150+
return mockRunner, nil, []*latest.SkaffoldConfig{{}}, nil
150151
})
151152
t.Override(&opts, config.SkaffoldOptions{
152153
Cleanup: true,

cmd/skaffold/app/cmd/run_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
2626
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
2727
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
28+
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext"
2829
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
2930
"github.com/GoogleContainerTools/skaffold/testutil"
3031
)
@@ -69,8 +70,8 @@ func (r *mockRunRunner) DeployAndLog(context.Context, io.Writer, []build.Artifac
6970
func TestBuildImageFlag(t *testing.T) {
7071
testutil.Run(t, "", func(t *testutil.T) {
7172
mockRunner := &mockRunRunner{}
72-
t.Override(&createRunner, func(io.Writer, config.SkaffoldOptions) (runner.Runner, []*latest.SkaffoldConfig, error) {
73-
return mockRunner, []*latest.SkaffoldConfig{{
73+
t.Override(&createRunner, func(io.Writer, config.SkaffoldOptions) (runner.Runner, *runcontext.RunContext, []*latest.SkaffoldConfig, error) {
74+
return mockRunner, nil, []*latest.SkaffoldConfig{{
7475
Pipeline: latest.Pipeline{
7576
Build: latest.BuildConfig{
7677
Artifacts: []*latest.Artifact{

cmd/skaffold/app/cmd/runner_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func TestCreateNewRunner(t *testing.T) {
9999
Write("skaffold.yaml", fmt.Sprintf("apiVersion: %s\nkind: Config\n%s", latest.Version, test.config)).
100100
Chdir()
101101

102-
_, _, err := createNewRunner(ioutil.Discard, test.options)
102+
_, _, _, err := createNewRunner(ioutil.Discard, test.options)
103103

104104
t.CheckError(test.shouldErr, err)
105105
if test.expectedError != "" {

docs/content/en/api/skaffold.swagger.json

+14-28
Large diffs are not rendered by default.

docs/content/en/docs/references/api/grpc.md

-1
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,6 @@ For Cancelled Error code, use range 800 to 850.<br>
964964
| DEPLOY_MANIFEST_WRITE_ERR | 1020 | Error writing hydrated kubernetes manifests. |
965965
| DEPLOY_PARSE_MANIFEST_IMAGES_ERR | 1021 | Error getting images from a kubernetes manifest. |
966966
| DEPLOY_HELM_CREATE_NS_NOT_AVAILABLE | 1022 | Helm config `createNamespace` not available |
967-
| DEPLOY_CLUSTER_INTERNAL_SYSTEM_ERR | 1023 | Deploy error due to internal system error on k8 clusterm |
968967
| TEST_USER_CONFIG_ERR | 1101 | Error expanding paths |
969968
| TEST_CST_USER_ERR | 1102 | Error running container-structure-test |
970969
| TEST_IMG_PULL_ERR | 1103 | Unable to docker pull image |

pkg/skaffold/deploy/error/errors.go

-56
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,17 @@ package error
1818

1919
import (
2020
"fmt"
21-
"regexp"
2221
"strings"
2322

24-
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/cluster"
25-
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
2623
sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors"
2724
"github.com/GoogleContainerTools/skaffold/proto/v1"
2825
)
2926

30-
// re is a shortcut around regexp.MustCompile
31-
func re(s string) *regexp.Regexp {
32-
return regexp.MustCompile(s)
33-
}
34-
3527
const (
3628
executableNotFound = "executable file not found"
3729
notFound = "%s not found"
3830
)
3931

40-
var (
41-
internalServerError = re(".*Internal Server Error")
42-
43-
// for testing
44-
isMinikube = cluster.GetClient().IsMinikube
45-
)
46-
4732
// DebugHelperRetrieveErr is thrown when debug helpers could not be retrieved.
4833
// This error occurs in skaffold debug command when transforming the manifest before deploying.
4934
func DebugHelperRetrieveErr(err error) error {
@@ -72,44 +57,3 @@ func MissingToolErr(toolName string, err error) string {
7257
}
7358
return err.Error()
7459
}
75-
76-
func isClusterInternalSystemError(err error) bool {
77-
return internalServerError.MatchString(err.Error())
78-
}
79-
80-
func internalSystemError(cfg sErrors.Config, err error) error {
81-
return sErrors.NewProblem(
82-
func(err error) string {
83-
return fmt.Sprintf("Deploy Failed. %v", err)
84-
},
85-
proto.StatusCode_DEPLOY_CLUSTER_INTERNAL_SYSTEM_ERR,
86-
cfg,
87-
func(cfg sErrors.Config) []*proto.Suggestion {
88-
kubectx := cfg.GetKubeContext()
89-
action := fmt.Sprintf("Something went wrong with your cluster %q", kubectx)
90-
if isMinikube(kubectx) {
91-
action = fmt.Sprintf("Run minikube status -p %s to check if minikube is running", kubectx)
92-
}
93-
return []*proto.Suggestion{{
94-
SuggestionCode: proto.SuggestionCode_OPEN_ISSUE,
95-
// TODO: show tip to run minikube logs command and attach logs.
96-
Action: fmt.Sprintf("%s. Try again.\nIf this keeps happening please open an issue %s", action, constants.GithubIssueLink),
97-
}}
98-
},
99-
err,
100-
)
101-
}
102-
103-
func UserError(cfg sErrors.Config, err error, sc proto.StatusCode) error {
104-
if sErrors.IsSkaffoldErr(err) {
105-
return err
106-
}
107-
if isClusterInternalSystemError(err) {
108-
return internalSystemError(cfg, err)
109-
}
110-
return sErrors.NewError(err,
111-
proto.ActionableErr{
112-
Message: err.Error(),
113-
ErrCode: sc,
114-
})
115-
}

pkg/skaffold/deploy/error/errors_test.go

-76
This file was deleted.

0 commit comments

Comments
 (0)