diff --git a/pkg/skaffold/build/local/local_test.go b/pkg/skaffold/build/local/local_test.go index c3c017bcce0..1853553fef3 100644 --- a/pkg/skaffold/build/local/local_test.go +++ b/pkg/skaffold/build/local/local_test.go @@ -34,12 +34,12 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/warnings" "github.com/GoogleContainerTools/skaffold/testutil" + testEvent "github.com/GoogleContainerTools/skaffold/testutil/event" ) type testAuthHelper struct{} @@ -229,13 +229,13 @@ func TestLocalRun(t *testing.T) { t.Override(&docker.EvalBuildArgs, func(_ config.RunMode, _ string, _ string, args map[string]*string, _ map[string]*string) (map[string]*string, error) { return args, nil }) - event.InitializeState([]latest.Pipeline{{ + testEvent.InitializeState([]latest.Pipeline{{ Deploy: latest.DeployConfig{}, Build: latest.BuildConfig{ BuildType: latest.BuildType{ LocalBuild: &latest.LocalBuild{}, }, - }}}, "", true, true, true) + }}}) builder, err := NewBuilder(&mockConfig{}, &latest.LocalBuild{ diff --git a/pkg/skaffold/build/scheduler_test.go b/pkg/skaffold/build/scheduler_test.go index f93e637ab73..fe0e5152e57 100644 --- a/pkg/skaffold/build/scheduler_test.go +++ b/pkg/skaffold/build/scheduler_test.go @@ -30,9 +30,9 @@ import ( "github.com/google/go-cmp/cmp" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/tag" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" + testEvent "github.com/GoogleContainerTools/skaffold/testutil/event" ) func TestGetBuild(t *testing.T) { @@ -393,7 +393,7 @@ func initializeEvents() { }, }, }} - event.InitializeState(pipes, "temp", true, true, true) + testEvent.InitializeState(pipes) } func errorsComparer(a, b error) bool { diff --git a/pkg/skaffold/deploy/status/status_check_test.go b/pkg/skaffold/deploy/status/status_check_test.go index 4a176cb99b3..081db5f4b23 100644 --- a/pkg/skaffold/deploy/status/status_check_test.go +++ b/pkg/skaffold/deploy/status/status_check_test.go @@ -36,12 +36,12 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy/kubectl" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy/label" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy/resource" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/proto/v1" "github.com/GoogleContainerTools/skaffold/testutil" + testEvent "github.com/GoogleContainerTools/skaffold/testutil/event" ) func TestGetDeployments(t *testing.T) { @@ -293,7 +293,7 @@ func TestGetDeployStatus(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - event.InitializeState([]latest.Pipeline{{}}, "test", true, true, true) + testEvent.InitializeState([]latest.Pipeline{{}}) errCode, err := getSkaffoldDeployStatus(test.counter, test.deployments) t.CheckError(test.shouldErr, err) if test.shouldErr { @@ -370,7 +370,7 @@ func TestPrintSummaryStatus(t *testing.T) { out := new(bytes.Buffer) rc := newCounter(10) rc.pending = test.pending - event.InitializeState([]latest.Pipeline{{}}, "test", true, true, true) + testEvent.InitializeState([]latest.Pipeline{{}}) r := withStatus(resource.NewDeployment(test.deployment, test.namespace, 0), test.ae) // report status once and set it changed to false. r.ReportSinceLastUpdated(false) @@ -460,7 +460,7 @@ func TestPrintStatus(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { out := new(bytes.Buffer) - event.InitializeState([]latest.Pipeline{{}}, "test", true, true, true) + testEvent.InitializeState([]latest.Pipeline{{}}) checker := statusChecker{labeller: labeller} actual := checker.printStatus(test.rs, out) t.CheckDeepEqual(test.expectedOut, out.String()) @@ -591,7 +591,7 @@ func TestPollDeployment(t *testing.T) { testutil.Run(t, test.description, func(t *testutil.T) { t.Override(&util.DefaultExecCommand, test.command) t.Override(&defaultPollPeriodInMilliseconds, 100) - event.InitializeState([]latest.Pipeline{{}}, "test", true, true, true) + testEvent.InitializeState([]latest.Pipeline{{}}) mockVal := mockValidator{runs: test.runs} dep := test.dep.WithValidator(mockVal) diff --git a/pkg/skaffold/event/config.go b/pkg/skaffold/event/config.go new file mode 100644 index 00000000000..8adb50ec7a8 --- /dev/null +++ b/pkg/skaffold/event/config.go @@ -0,0 +1,29 @@ +/* +Copyright 2021 The Skaffold Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package event + +import ( + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" +) + +type Config interface { + GetKubeContext() string + AutoBuild() bool + AutoDeploy() bool + AutoSync() bool + GetPipelines() []latest.Pipeline +} diff --git a/pkg/skaffold/event/event.go b/pkg/skaffold/event/event.go index 60ccec9bbce..94b2b32c48f 100644 --- a/pkg/skaffold/event/event.go +++ b/pkg/skaffold/event/event.go @@ -30,7 +30,6 @@ import ( sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/instrumentation" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/version" "github.com/GoogleContainerTools/skaffold/proto/v1" @@ -157,15 +156,15 @@ func (ev *eventHandler) forEachEvent(callback func(*proto.LogEntry) error) error return <-listener.errors } -func emptyState(pipelines []latest.Pipeline, kubeContext string, autoBuild, autoDeploy, autoSync bool) proto.State { +func emptyState(cfg Config) proto.State { builds := map[string]string{} - for _, p := range pipelines { + for _, p := range cfg.GetPipelines() { for _, a := range p.Build.Artifacts { builds[a.ImageName] = NotStarted } } - metadata := initializeMetadata(pipelines, kubeContext) - return emptyStateWithArtifacts(builds, metadata, autoBuild, autoDeploy, autoSync) + metadata := initializeMetadata(cfg.GetPipelines(), cfg.GetKubeContext()) + return emptyStateWithArtifacts(builds, metadata, cfg.AutoBuild(), cfg.AutoDeploy(), cfg.AutoSync()) } func emptyStateWithArtifacts(builds map[string]string, metadata *proto.Metadata, autoBuild, autoDeploy, autoSync bool) proto.State { @@ -191,8 +190,8 @@ func emptyStateWithArtifacts(builds map[string]string, metadata *proto.Metadata, } // InitializeState instantiates the global state of the skaffold runner, as well as the event log. -func InitializeState(c []latest.Pipeline, kc string, autoBuild, autoDeploy, autoSync bool) { - handler.setState(emptyState(c, kc, autoBuild, autoDeploy, autoSync)) +func InitializeState(cfg Config) { + handler.setState(emptyState(cfg)) } // DeployInProgress notifies that a deployment has been started. diff --git a/pkg/skaffold/event/event_test.go b/pkg/skaffold/event/event_test.go index 41597647de0..09b098a2be5 100644 --- a/pkg/skaffold/event/event_test.go +++ b/pkg/skaffold/event/event_test.go @@ -67,7 +67,7 @@ func TestGetLogEvents(t *testing.T) { func TestGetState(t *testing.T) { ev := newHandler() - ev.state = emptyState([]latest.Pipeline{{}}, "test", true, true, true) + ev.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) ev.stateLock.Lock() ev.state.BuildState.Artifacts["img"] = Complete @@ -82,7 +82,7 @@ func TestDeployInProgress(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState([]latest.Pipeline{{}}, "test", true, true, true) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().DeployState.Status == NotStarted }) DeployInProgress() @@ -93,7 +93,7 @@ func TestDeployFailed(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState([]latest.Pipeline{{}}, "test", true, true, true) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().DeployState.Status == NotStarted }) DeployFailed(errors.New("BUG")) @@ -107,7 +107,7 @@ func TestDeployComplete(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState([]latest.Pipeline{{}}, "test", true, true, true) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().DeployState.Status == NotStarted }) DeployComplete() @@ -121,11 +121,11 @@ func TestBuildInProgress(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState([]latest.Pipeline{{Build: latest.BuildConfig{ + handler.state = emptyState(mockCfg([]latest.Pipeline{{Build: latest.BuildConfig{ Artifacts: []*latest.Artifact{{ ImageName: "img", }}, - }}}, "test", true, true, true) + }}}, "test")) wait(t, func() bool { return handler.getState().BuildState.Artifacts["img"] == NotStarted }) BuildInProgress("img") @@ -136,11 +136,11 @@ func TestBuildFailed(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState([]latest.Pipeline{{Build: latest.BuildConfig{ + handler.state = emptyState(mockCfg([]latest.Pipeline{{Build: latest.BuildConfig{ Artifacts: []*latest.Artifact{{ ImageName: "img", }}, - }}}, "test", true, true, true) + }}}, "test")) wait(t, func() bool { return handler.getState().BuildState.Artifacts["img"] == NotStarted }) BuildFailed("img", errors.New("BUG")) @@ -154,11 +154,11 @@ func TestBuildComplete(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState([]latest.Pipeline{{Build: latest.BuildConfig{ + handler.state = emptyState(mockCfg([]latest.Pipeline{{Build: latest.BuildConfig{ Artifacts: []*latest.Artifact{{ ImageName: "img", }}, - }}}, "test", true, true, true) + }}}, "test")) wait(t, func() bool { return handler.getState().BuildState.Artifacts["img"] == NotStarted }) BuildComplete("img") @@ -169,7 +169,7 @@ func TestPortForwarded(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState([]latest.Pipeline{{}}, "test", true, true, true) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().ForwardedPorts[8080] == nil }) PortForwarded(8080, schemautil.FromInt(8888), "pod", "container", "ns", "portname", "resourceType", "resourceName", "127.0.0.1") @@ -186,7 +186,7 @@ func TestStatusCheckEventStarted(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState([]latest.Pipeline{{}}, "test", true, true, true) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted }) StatusCheckEventStarted() @@ -197,7 +197,7 @@ func TestStatusCheckEventInProgress(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState([]latest.Pipeline{{}}, "test", true, true, true) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted }) StatusCheckEventInProgress("[2/5 deployment(s) are still pending]") @@ -208,7 +208,7 @@ func TestStatusCheckEventSucceeded(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState([]latest.Pipeline{{}}, "test", true, true, true) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted }) statusCheckEventSucceeded() @@ -219,7 +219,7 @@ func TestStatusCheckEventFailed(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState([]latest.Pipeline{{}}, "test", true, true, true) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted }) StatusCheckEventEnded(proto.StatusCode_STATUSCHECK_FAILED_SCHEDULING, errors.New("one or more deployments failed")) @@ -233,7 +233,7 @@ func TestResourceStatusCheckEventUpdated(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState([]latest.Pipeline{{}}, "test", true, true, true) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted }) ResourceStatusCheckEventUpdated("ns:pod/foo", proto.ActionableErr{ @@ -247,7 +247,7 @@ func TestResourceStatusCheckEventSucceeded(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState([]latest.Pipeline{{}}, "test", true, true, true) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted }) resourceStatusCheckEventSucceeded("ns:pod/foo") @@ -258,7 +258,7 @@ func TestResourceStatusCheckEventFailed(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState([]latest.Pipeline{{}}, "test", true, true, true) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted }) resourceStatusCheckEventFailed("ns:pod/foo", proto.ActionableErr{ @@ -272,7 +272,7 @@ func TestFileSyncInProgress(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState([]latest.Pipeline{{}}, "test", true, true, true) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().FileSyncState.Status == NotStarted }) FileSyncInProgress(5, "image") @@ -283,7 +283,7 @@ func TestFileSyncFailed(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState([]latest.Pipeline{{}}, "test", true, true, true) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().FileSyncState.Status == NotStarted }) FileSyncFailed(5, "image", errors.New("BUG")) @@ -294,7 +294,7 @@ func TestFileSyncSucceeded(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState([]latest.Pipeline{{}}, "test", true, true, true) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) wait(t, func() bool { return handler.getState().FileSyncState.Status == NotStarted }) FileSyncSucceeded(5, "image") @@ -305,7 +305,7 @@ func TestDebuggingContainer(t *testing.T) { defer func() { handler = newHandler() }() handler = newHandler() - handler.state = emptyState([]latest.Pipeline{{}}, "test", true, true, true) + handler.state = emptyState(mockCfg([]latest.Pipeline{{}}, "test")) found := func() bool { for _, dc := range handler.getState().DebuggingContainers { @@ -598,3 +598,21 @@ func TestSaveEventsToFile(t *testing.T) { testutil.CheckDeepEqual(t, 1, buildCompleteEvent) testutil.CheckDeepEqual(t, 1, devLoopCompleteEvent) } + +type config struct { + pipes []latest.Pipeline + kubectx string +} + +func (c config) GetKubeContext() string { return c.kubectx } +func (c config) AutoBuild() bool { return true } +func (c config) AutoDeploy() bool { return true } +func (c config) AutoSync() bool { return true } +func (c config) GetPipelines() []latest.Pipeline { return c.pipes } + +func mockCfg(pipes []latest.Pipeline, kubectx string) config { + return config{ + pipes: pipes, + kubectx: kubectx, + } +} diff --git a/pkg/skaffold/event/util_test.go b/pkg/skaffold/event/util_test.go index eb3ac5be8a8..303124d078f 100644 --- a/pkg/skaffold/event/util_test.go +++ b/pkg/skaffold/event/util_test.go @@ -135,7 +135,7 @@ func TestEmptyState(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { handler = &eventHandler{ - state: emptyState([]latest.Pipeline{test.cfg}, test.cluster, true, true, true), + state: emptyState(mockCfg([]latest.Pipeline{test.cfg}, test.cluster)), } metadata := handler.state.Metadata builders := metadata.Build.Builders diff --git a/pkg/skaffold/kubernetes/portforward/entry_manager_test.go b/pkg/skaffold/kubernetes/portforward/entry_manager_test.go index 9e1a08211a4..be78191bb15 100644 --- a/pkg/skaffold/kubernetes/portforward/entry_manager_test.go +++ b/pkg/skaffold/kubernetes/portforward/entry_manager_test.go @@ -22,13 +22,13 @@ import ( "testing" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" + testEvent "github.com/GoogleContainerTools/skaffold/testutil/event" ) func TestStop(t *testing.T) { - event.InitializeState([]latest.Pipeline{{}}, "test", true, true, true) + testEvent.InitializeState([]latest.Pipeline{{}}) pfe1 := newPortForwardEntry(0, latest.PortForwardResource{ Type: constants.Pod, diff --git a/pkg/skaffold/kubernetes/portforward/pod_forwarder_test.go b/pkg/skaffold/kubernetes/portforward/pod_forwarder_test.go index 3a29e3a9d91..91e184831c2 100644 --- a/pkg/skaffold/kubernetes/portforward/pod_forwarder_test.go +++ b/pkg/skaffold/kubernetes/portforward/pod_forwarder_test.go @@ -28,11 +28,11 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/watch" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" schemautil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/testutil" + testEvent "github.com/GoogleContainerTools/skaffold/testutil/event" ) func TestAutomaticPortForwardPod(t *testing.T) { @@ -401,7 +401,7 @@ func TestAutomaticPortForwardPod(t *testing.T) { } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - event.InitializeState([]latest.Pipeline{{}}, "test", true, true, true) + testEvent.InitializeState([]latest.Pipeline{{}}) taken := map[int]struct{}{} t.Override(&retrieveAvailablePort, mockRetrieveAvailablePort("127.0.0.1", taken, test.availablePorts)) t.Override(&topLevelOwnerKey, func(context.Context, metav1.Object, string) string { return "owner" }) @@ -474,7 +474,7 @@ func TestStartPodForwarder(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - event.InitializeState([]latest.Pipeline{{}}, "", true, true, true) + testEvent.InitializeState([]latest.Pipeline{{}}) t.Override(&topLevelOwnerKey, func(context.Context, metav1.Object, string) string { return "owner" }) t.Override(&newPodWatcher, func(kubernetes.PodSelector, []string) kubernetes.PodWatcher { return &fakePodWatcher{ diff --git a/pkg/skaffold/kubernetes/portforward/resource_forwarder_test.go b/pkg/skaffold/kubernetes/portforward/resource_forwarder_test.go index d11e55c1e24..8f1bccc99bf 100644 --- a/pkg/skaffold/kubernetes/portforward/resource_forwarder_test.go +++ b/pkg/skaffold/kubernetes/portforward/resource_forwarder_test.go @@ -34,12 +34,12 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy/label" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event" kubernetesclient "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/client" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" schemautil "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/GoogleContainerTools/skaffold/testutil" + testEvent "github.com/GoogleContainerTools/skaffold/testutil/event" ) type testForwarder struct { @@ -121,7 +121,7 @@ func TestStart(t *testing.T) { } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - event.InitializeState([]latest.Pipeline{{}}, "", true, true, true) + testEvent.InitializeState([]latest.Pipeline{{}}) t.Override(&retrieveAvailablePort, mockRetrieveAvailablePort("127.0.0.1", map[int]struct{}{}, test.availablePorts)) t.Override(&retrieveServices, func(context.Context, string, []string) ([]*latest.PortForwardResource, error) { return test.resources, nil @@ -263,7 +263,7 @@ func TestUserDefinedResources(t *testing.T) { for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - event.InitializeState([]latest.Pipeline{{}}, "", true, true, true) + testEvent.InitializeState([]latest.Pipeline{{}}) t.Override(&retrieveAvailablePort, mockRetrieveAvailablePort("127.0.0.1", map[int]struct{}{}, []int{8080, 9000})) t.Override(&retrieveServices, func(context.Context, string, []string) ([]*latest.PortForwardResource, error) { return []*latest.PortForwardResource{svc}, nil diff --git a/pkg/skaffold/runner/new.go b/pkg/skaffold/runner/new.go index 0b049d804bf..c9913fc13ce 100644 --- a/pkg/skaffold/runner/new.go +++ b/pkg/skaffold/runner/new.go @@ -48,7 +48,7 @@ import ( // NewForConfig returns a new SkaffoldRunner for a SkaffoldConfig func NewForConfig(runCtx *runcontext.RunContext) (*SkaffoldRunner, error) { - event.InitializeState(runCtx.GetPipelines(), runCtx.GetKubeContext(), runCtx.AutoBuild(), runCtx.AutoDeploy(), runCtx.AutoSync()) + event.InitializeState(runCtx) event.LogMetaEvent() kubectlCLI := pkgkubectl.NewCLI(runCtx, "") diff --git a/testutil/event/config.go b/testutil/event/config.go new file mode 100644 index 00000000000..1c313baa3e3 --- /dev/null +++ b/testutil/event/config.go @@ -0,0 +1,39 @@ +/* +Copyright 2021 The Skaffold Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package event + +import ( + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" +) + +func InitializeState(pipes []latest.Pipeline) { + cfg := config{ + pipes: pipes, + } + event.InitializeState(cfg) +} + +type config struct { + pipes []latest.Pipeline +} + +func (c config) AutoBuild() bool { return true } +func (c config) AutoDeploy() bool { return true } +func (c config) AutoSync() bool { return true } +func (c config) GetPipelines() []latest.Pipeline { return c.pipes } +func (c config) GetKubeContext() string { return "temp" }