From 1620509f4c03c0a80d5f0a68ad99623c3e08cf23 Mon Sep 17 00:00:00 2001 From: Alexander Jung Date: Thu, 21 Nov 2024 21:28:39 +0100 Subject: [PATCH] feat(pkg): Recognize the `--label` flag when packaging a kernel Signed-off-by: Alexander Jung --- internal/cli/kraft/pkg/packager_cli_kernel.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/cli/kraft/pkg/packager_cli_kernel.go b/internal/cli/kraft/pkg/packager_cli_kernel.go index b24d04ec3..49b372b49 100644 --- a/internal/cli/kraft/pkg/packager_cli_kernel.go +++ b/internal/cli/kraft/pkg/packager_cli_kernel.go @@ -76,6 +76,18 @@ func (p *packagerCliKernel) Pack(ctx context.Context, opts *PkgOptions, args ... opts.Env = append(opts.Env, envs...) } + labels := make(map[string]string) + if len(opts.Labels) > 0 { + for _, label := range opts.Labels { + kv := strings.SplitN(label, "=", 2) + if len(kv) != 2 { + return nil, fmt.Errorf("invalid label format: %s", label) + } + + labels[kv[0]] = kv[1] + } + } + var result []pack.Package norender := log.LoggerTypeFromString(config.G[config.KraftKit](ctx).Log.Type) != log.FANCY @@ -96,6 +108,7 @@ func (p *packagerCliKernel) Pack(ctx context.Context, opts *PkgOptions, args ... packmanager.PackKConfig(!opts.NoKConfig), packmanager.PackName(opts.Name), packmanager.PackOutput(opts.Output), + packmanager.PackLabels(labels), ) envs := opts.aggregateEnvs()