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

Fix redundant Jib image flags generated by init #3191

Merged
merged 3 commits into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 4 additions & 14 deletions pkg/skaffold/jib/jib_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,11 @@ func (j Jib) CreateArtifact(manifestImage string) *latest.Artifact {
a.Workspace = workspace
}

if j.BuilderName == PluginName(JibMaven) {
jibMaven := &latest.JibArtifact{Type: string(JibMaven)}
if j.Project != "" {
jibMaven.Project = j.Project
}
jibMaven.Flags = []string{"-Dimage=" + manifestImage}
a.ArtifactType = latest.ArtifactType{JibArtifact: jibMaven}
} else if j.BuilderName == PluginName(JibGradle) {
jibGradle := &latest.JibArtifact{Type: string(JibGradle)}
if j.Project != "" {
jibGradle.Project = j.Project
}
jibGradle.Flags = []string{"-Dimage=" + manifestImage}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been --image too, I think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-Dimage= will work as well, and I know --image doesn't work when put before, say, jibDockerBuild, so I prefer it to --image. It's safer.

a.ArtifactType = latest.ArtifactType{JibArtifact: jibGradle}
jib := &latest.JibArtifact{}
if j.Project != "" {
jib.Project = j.Project
}
a.ArtifactType = latest.ArtifactType{JibArtifact: jib}

return a
}
Expand Down
28 changes: 11 additions & 17 deletions pkg/skaffold/jib/jib_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,23 +187,19 @@ func TestCreateArtifact(t *testing.T) {
config: Jib{BuilderName: "Jib Gradle Plugin", FilePath: filepath.Join("path", "to", "build.gradle"), Image: "image", Project: "project"},
manifestImage: "different-image",
expectedArtifact: latest.Artifact{
ImageName: "different-image",
Workspace: filepath.Join("path", "to"),
ArtifactType: latest.ArtifactType{
JibArtifact: &latest.JibArtifact{Project: "project", Flags: []string{"-Dimage=different-image"}, Type: string(JibGradle)},
},
ImageName: "different-image",
Workspace: filepath.Join("path", "to"),
ArtifactType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{Project: "project"}},
},
},
{
description: "jib gradle without image and project",
config: Jib{BuilderName: "Jib Gradle Plugin", FilePath: filepath.Join("path", "to", "build.gradle")},
manifestImage: "different-image",
expectedArtifact: latest.Artifact{
ImageName: "different-image",
Workspace: filepath.Join("path", "to"),
ArtifactType: latest.ArtifactType{
JibArtifact: &latest.JibArtifact{Flags: []string{"-Dimage=different-image"}, Type: string(JibGradle)},
},
ImageName: "different-image",
Workspace: filepath.Join("path", "to"),
ArtifactType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{}},
},
},
{
Expand All @@ -213,19 +209,17 @@ func TestCreateArtifact(t *testing.T) {
expectedArtifact: latest.Artifact{
ImageName: "different-image",
Workspace: filepath.Join("path", "to"),
ArtifactType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{Project: "project", Flags: []string{"-Dimage=different-image"}, Type: string(JibMaven)}},
ArtifactType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{Project: "project"}},
},
},
{
description: "jib maven without image and project",
config: Jib{BuilderName: "Jib Maven Plugin", FilePath: filepath.Join("path", "to", "pom.xml")},
manifestImage: "different-image",
expectedArtifact: latest.Artifact{
ImageName: "different-image",
Workspace: filepath.Join("path", "to"),
ArtifactType: latest.ArtifactType{
JibArtifact: &latest.JibArtifact{Flags: []string{"-Dimage=different-image"}, Type: string(JibMaven)},
},
ImageName: "different-image",
Workspace: filepath.Join("path", "to"),
ArtifactType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{}},
},
},
{
Expand All @@ -234,7 +228,7 @@ func TestCreateArtifact(t *testing.T) {
manifestImage: "different-image",
expectedArtifact: latest.Artifact{
ImageName: "different-image",
ArtifactType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{Flags: []string{"-Dimage=different-image"}, Type: string(JibGradle)}},
ArtifactType: latest.ArtifactType{JibArtifact: &latest.JibArtifact{}},
},
},
}
Expand Down