diff --git a/pkg/skaffold/initializer/build/builders.go b/pkg/skaffold/initializer/build/builders.go index 9a7e53e4c28..b7e40eb39f1 100644 --- a/pkg/skaffold/initializer/build/builders.go +++ b/pkg/skaffold/initializer/build/builders.go @@ -63,11 +63,21 @@ type GeneratedBuilderImagePair struct { } type Initializer interface { + // ProcessImages is the entrypoint call, and handles the pairing of all builders + // contained in the initializer with the provided images from the deploy initializer ProcessImages([]string) error + // BuildConfig returns the processed build config to be written to the skaffold.yaml BuildConfig() latest.BuildConfig + // BuilderImagePairs returns all of the processed builder/image pairs. for use in testing. BuilderImagePairs() []BuilderImagePair + // PrintAnalysis writes the project analysis to the provided out stream PrintAnalysis(io.Writer) error - UnresolvedPairs() []GeneratedBuilderImagePair + // GeneratedPairs returns all builder/image pairs with images generated by skaffold. + // Each of these pairs contains a path at which a k8s manifest should be generated. + GeneratedPairs() []GeneratedBuilderImagePair + // Resolve should be called by the init controller once all generated pairs have + // been handled, to signal to the build initializer that all + // builder/image pairs have been resolved. Resolve() } @@ -90,7 +100,7 @@ func (e *emptyBuildInitializer) PrintAnalysis(io.Writer) error { return nil } -func (e *emptyBuildInitializer) UnresolvedPairs() []GeneratedBuilderImagePair { +func (e *emptyBuildInitializer) GeneratedPairs() []GeneratedBuilderImagePair { return nil } diff --git a/pkg/skaffold/initializer/build/builders_test.go b/pkg/skaffold/initializer/build/builders_test.go index e0f537cf7a5..984bf2c65a9 100644 --- a/pkg/skaffold/initializer/build/builders_test.go +++ b/pkg/skaffold/initializer/build/builders_test.go @@ -139,7 +139,7 @@ func TestResolveBuilderImages(t *testing.T) { } err := initializer.resolveBuilderImages() t.CheckErrorAndDeepEqual(test.shouldErr, err, test.expectedPairs, initializer.BuilderImagePairs()) - t.CheckDeepEqual(test.expectedGeneratedPairs, initializer.UnresolvedPairs()) + t.CheckDeepEqual(test.expectedGeneratedPairs, initializer.GeneratedPairs()) }) } } diff --git a/pkg/skaffold/initializer/build/cli.go b/pkg/skaffold/initializer/build/cli.go index 0a83e73dc27..098abacd2e8 100644 --- a/pkg/skaffold/initializer/build/cli.go +++ b/pkg/skaffold/initializer/build/cli.go @@ -62,7 +62,7 @@ func (c *cliBuildInitializer) PrintAnalysis(out io.Writer) error { return printAnalysis(out, c.enableNewFormat, c.skipBuild, c.builderImagePairs, c.builders, nil) } -func (c *cliBuildInitializer) UnresolvedPairs() []GeneratedBuilderImagePair { +func (c *cliBuildInitializer) GeneratedPairs() []GeneratedBuilderImagePair { return nil } diff --git a/pkg/skaffold/initializer/build/init.go b/pkg/skaffold/initializer/build/init.go index 6aea8585e4f..5dc559e2382 100644 --- a/pkg/skaffold/initializer/build/init.go +++ b/pkg/skaffold/initializer/build/init.go @@ -63,7 +63,7 @@ func (d *defaultBuildInitializer) PrintAnalysis(out io.Writer) error { return printAnalysis(out, d.enableNewFormat, d.skipBuild, d.builderImagePairs, d.builders, d.unresolvedImages) } -func (d *defaultBuildInitializer) UnresolvedPairs() []GeneratedBuilderImagePair { +func (d *defaultBuildInitializer) GeneratedPairs() []GeneratedBuilderImagePair { return d.generatedBuilderImagePairs } diff --git a/pkg/skaffold/initializer/config_test.go b/pkg/skaffold/initializer/config_test.go index 9f8245770c5..bd614e760c0 100644 --- a/pkg/skaffold/initializer/config_test.go +++ b/pkg/skaffold/initializer/config_test.go @@ -71,7 +71,7 @@ func (s stubBuildInitializer) BuildConfig() latest.BuildConfig { } } -func (s stubBuildInitializer) UnresolvedPairs() []build.GeneratedBuilderImagePair { +func (s stubBuildInitializer) GeneratedPairs() []build.GeneratedBuilderImagePair { panic("do not call me") } diff --git a/pkg/skaffold/initializer/init.go b/pkg/skaffold/initializer/init.go index 2e5da979498..493b7b57c10 100644 --- a/pkg/skaffold/initializer/init.go +++ b/pkg/skaffold/initializer/init.go @@ -46,7 +46,7 @@ func DoInit(ctx context.Context, out io.Writer, c config.Config) error { a := analyze.NewAnalyzer(c) - if err := a.Analyze(rootDir); err != nil { + if err = a.Analyze(rootDir); err != nil { return err } @@ -63,14 +63,14 @@ func DoInit(ctx context.Context, out io.Writer, c config.Config) error { var generatedManifests map[string][]byte if c.EnableManifestGeneration { - generatedManifests, err = deployInitializer.GenerateManifests(buildInitializer.UnresolvedPairs()) + generatedManifests, err = deployInitializer.GenerateManifests(buildInitializer.GeneratedPairs()) if err != nil { return err } buildInitializer.Resolve() } - if err := deployInitializer.Validate(); err != nil { + if err = deployInitializer.Validate(); err != nil { return err } @@ -90,12 +90,13 @@ func DoInit(ctx context.Context, out io.Writer, c config.Config) error { } for path, manifest := range generatedManifests { - if err := ioutil.WriteFile(path, manifest, 0644); err != nil { + if err = ioutil.WriteFile(path, manifest, 0644); err != nil { return errors.Wrap(err, "writing k8s manifest to file") } + fmt.Fprintf(out, "Generated manifest %s was written\n", path) } - if err := ioutil.WriteFile(c.Opts.ConfigurationFile, pipeline, 0644); err != nil { + if err = ioutil.WriteFile(c.Opts.ConfigurationFile, pipeline, 0644); err != nil { return errors.Wrap(err, "writing config to file") }