mirror of
https://github.com/GoogleContainerTools/kaniko
synced 2026-10-17 17:26:43 +02:00
executor: add --label flag
Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
This commit is contained in:
+23
-3
@@ -21,6 +21,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-containerregistry/pkg/v1/partial"
|
||||
@@ -82,7 +83,7 @@ func newStageBuilder(opts *config.KanikoOptions, stage config.KanikoStage, cross
|
||||
return nil, err
|
||||
}
|
||||
|
||||
imageConfig, err := initializeConfig(sourceImage)
|
||||
imageConfig, err := initializeConfig(sourceImage, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -134,7 +135,7 @@ func newStageBuilder(opts *config.KanikoOptions, stage config.KanikoStage, cross
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func initializeConfig(img partial.WithConfigFile) (*v1.ConfigFile, error) {
|
||||
func initializeConfig(img partial.WithConfigFile, opts *config.KanikoOptions) (*v1.ConfigFile, error) {
|
||||
imageConfig, err := img.ConfigFile()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -143,6 +144,25 @@ func initializeConfig(img partial.WithConfigFile) (*v1.ConfigFile, error) {
|
||||
if imageConfig.Config.Env == nil {
|
||||
imageConfig.Config.Env = constants.ScratchEnvVars
|
||||
}
|
||||
|
||||
if opts == nil {
|
||||
return imageConfig, nil
|
||||
}
|
||||
|
||||
if l := len(opts.Labels); l > 0 {
|
||||
if imageConfig.Config.Labels == nil {
|
||||
imageConfig.Config.Labels = make(map[string]string)
|
||||
}
|
||||
for _, label := range opts.Labels {
|
||||
parts := strings.SplitN(label, "=", 2)
|
||||
if len(parts) != 2 {
|
||||
return nil, fmt.Errorf("labels must be of the form key=value, got %s", label)
|
||||
}
|
||||
|
||||
imageConfig.Config.Labels[parts[0]] = parts[1]
|
||||
}
|
||||
}
|
||||
|
||||
return imageConfig, nil
|
||||
}
|
||||
|
||||
@@ -484,7 +504,7 @@ func CalculateDependencies(opts *config.KanikoOptions) (map[int][]string, error)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
cfg, err := initializeConfig(image)
|
||||
cfg, err := initializeConfig(image, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -462,7 +462,7 @@ func TestInitializeConfig(t *testing.T) {
|
||||
t.Errorf("error seen when running test %s", err)
|
||||
t.Fail()
|
||||
}
|
||||
actual, _ := initializeConfig(img)
|
||||
actual, _ := initializeConfig(img, nil)
|
||||
testutil.CheckDeepEqual(t, tt.expected, actual.Config)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user