Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nkubala committed Feb 24, 2020
1 parent 25b9ddd commit 8d4812f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
14 changes: 12 additions & 2 deletions pkg/skaffold/initializer/build/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/initializer/build/builders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/initializer/build/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/initializer/build/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/initializer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
11 changes: 6 additions & 5 deletions pkg/skaffold/initializer/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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")
}

Expand Down

0 comments on commit 8d4812f

Please sign in to comment.