Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init --analyze should return unique image names #3141

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions pkg/skaffold/initializer/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ type builderImagePair struct {
ImageName string
}

type set map[string]interface{}

func (s set) add(value string) {
s[value] = value
}

func (s set) values() (values []string) {
for val := range s {
values = append(values, val)
}
sort.Strings(values)
return values
}

// DoInit executes the `skaffold init` flow.
func DoInit(ctx context.Context, out io.Writer, c Config) error {
rootDir := "."
Expand Down Expand Up @@ -219,7 +233,7 @@ func DoInit(ctx context.Context, out io.Writer, c Config) error {
// separately returns the builder configs and images that didn't have any matches.
func autoSelectBuilders(builderConfigs []InitBuilder, images []string) ([]builderImagePair, []InitBuilder, []string) {
var pairs []builderImagePair
var unresolvedImages []string
var unresolvedImages = make(set)
for _, image := range images {
matchingConfigIndex := -1
for i, config := range builderConfigs {
Expand All @@ -241,10 +255,10 @@ func autoSelectBuilders(builderConfigs []InitBuilder, images []string) ([]builde
builderConfigs = append(builderConfigs[:matchingConfigIndex], builderConfigs[matchingConfigIndex+1:]...)
} else {
// No definite pair found, add to images list
unresolvedImages = append(unresolvedImages, image)
unresolvedImages.add(image)
}
}
return pairs, builderConfigs, unresolvedImages
return pairs, builderConfigs, unresolvedImages.values()
}

// detectBuilders checks if a path is a builder config, and if it is, returns the InitBuilders representing the
Expand Down
8 changes: 8 additions & 0 deletions pkg/skaffold/initializer/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,14 @@ func TestAutoSelectBuilders(t *testing.T) {
},
expectedFilteredImages: []string{"image1", "image2"},
},
{
description: "show unique image names",
builderConfigs: nil,
images: []string{"image1", "image1"},
expectedPairs: nil,
expectedBuildersLeft: nil,
expectedFilteredImages: []string{"image1"},
},
}

for _, test := range tests {
Expand Down