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

enhance: add link, host, and custom labeling #201

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
39 changes: 39 additions & 0 deletions cmd/vela-kaniko/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,21 @@
Name: "label.url",
Usage: "direct url of the repository",
},
&cli.StringFlag{
EnvVars: []string{"VELA_BUILD_LINK"},
Name: "label.build_link",
Usage: "direct Vela link to the build",
},
&cli.StringFlag{
EnvVars: []string{"VELA_BUILD_HOST"},
Name: "label.host",
Usage: "host that the image is built on",
},
&cli.StringFlag{
EnvVars: []string{"VELA_BUILD_CUSTOM_LABELS", "PARAMETER_CUSTOM_LABELS"},
Name: "label.custom",
Usage: "custom labels to add to the image in the form LABEL_NAME=ENV_KEY",
},
&cli.StringSliceFlag{
EnvVars: []string{"VELA_REPO_TOPICS"},
Name: "label.topics",
Expand Down Expand Up @@ -381,6 +396,27 @@
}
}

// target type for custom labels
var customLabels []string

labelsStr := c.String("label.custom")
if len(labelsStr) > 0 {
customLabelsMap := make(map[string]string)

// attempt to unmarshal to map
err := json.Unmarshal([]byte(labelsStr), &customLabelsMap)
if err != nil {
// fall back on splitting the string
customLabels = strings.Split(labelsStr, ",")

Check failure on line 410 in cmd/vela-kaniko/main.go

View workflow job for this annotation

GitHub Actions / diff-review

ineffectual assignment to customLabels (ineffassign)

Check failure on line 410 in cmd/vela-kaniko/main.go

View workflow job for this annotation

GitHub Actions / diff-review

ineffectual assignment to customLabels (ineffassign)

Check failure on line 410 in cmd/vela-kaniko/main.go

View workflow job for this annotation

GitHub Actions / full-review

ineffectual assignment to customLabels (ineffassign)

Check failure on line 410 in cmd/vela-kaniko/main.go

View workflow job for this annotation

GitHub Actions / full-review

ineffectual assignment to customLabels (ineffassign)

Check failure on line 410 in cmd/vela-kaniko/main.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] cmd/vela-kaniko/main.go#L410

ineffectual assignment to customLabels (ineffassign)
Raw output
cmd/vela-kaniko/main.go:410:4: ineffectual assignment to customLabels (ineffassign)
			customLabels = strings.Split(labelsStr, ",")
			^
ecrupper marked this conversation as resolved.
Show resolved Hide resolved
} else {
// iterate through the custom labels map
for key, value := range customLabelsMap {
// add the custom label to the custom labels
customLabels = append(customLabels, fmt.Sprintf("%s=%s", key, value))

Check failure on line 415 in cmd/vela-kaniko/main.go

View workflow job for this annotation

GitHub Actions / diff-review

SA4010: this result of append is never used, except maybe in other appends (staticcheck)

Check failure on line 415 in cmd/vela-kaniko/main.go

View workflow job for this annotation

GitHub Actions / diff-review

SA4010: this result of append is never used, except maybe in other appends (staticcheck)

Check failure on line 415 in cmd/vela-kaniko/main.go

View workflow job for this annotation

GitHub Actions / full-review

SA4010: this result of append is never used, except maybe in other appends (staticcheck)

Check failure on line 415 in cmd/vela-kaniko/main.go

View workflow job for this annotation

GitHub Actions / full-review

SA4010: this result of append is never used, except maybe in other appends (staticcheck)

Check failure on line 415 in cmd/vela-kaniko/main.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] cmd/vela-kaniko/main.go#L415

SA4010: this result of append is never used, except maybe in other appends (staticcheck)
Raw output
cmd/vela-kaniko/main.go:415:20: SA4010: this result of append is never used, except maybe in other appends (staticcheck)
				customLabels = append(customLabels, fmt.Sprintf("%s=%s", key, value))
				               ^
ecrupper marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

// create the plugin
p := &Plugin{
// build configuration
Expand Down Expand Up @@ -436,6 +472,9 @@
Number: c.Int("label.number"),
Topics: c.StringSlice("label.topics"),
URL: c.String("label.url"),
BuildURL: c.String("label.build_link"),
Host: c.String("label.host"),
CustomSet: c.StringSlice("label.custom"),
},
Labels: c.StringSlice("repo.labels"),
},
Expand Down
18 changes: 9 additions & 9 deletions cmd/vela-kaniko/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,6 @@ func (p *Plugin) Command() *exec.Cmd {
flags = append(flags, fmt.Sprintf("--destination=%s:%s", p.Repo.Name, tag))
}

// add predefined labels to user provided labels
p.Repo.Labels = append(p.Repo.Labels, p.Repo.AddLabels()...)

// iterate through all repo labels
for _, label := range p.Repo.Labels {
// add flag for tag from provided repo tag
flags = append(flags, "--label", label)
}

// add flag for dockerfile from provided image dockerfile
flags = append(flags, fmt.Sprintf("--dockerfile=%s", p.Image.Dockerfile))

Expand Down Expand Up @@ -188,6 +179,15 @@ func (p *Plugin) Command() *exec.Cmd {
// add flag for logging verbosity
flags = append(flags, fmt.Sprintf("--verbosity=%s", logrus.GetLevel()))

// add predefined labels to user provided labels
p.Repo.Labels = append(p.Repo.Labels, p.Repo.AddLabels()...)

// iterate through all repo labels
for _, label := range p.Repo.Labels {
// add flag for tag from provided repo tag
flags = append(flags, fmt.Sprintf("--label=%s", label))
}

return exec.Command(kanikoBin, flags...)
}

Expand Down
Loading
Loading