Skip to content

Commit

Permalink
feat: --annotation cli arg for pack command
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebond committed Nov 1, 2024
1 parent c332eeb commit 7a58125
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
flagOutput = "output"
flagInsecureRegistry = "insecure-registry"
flagDocsTarFile = "docs-tar-file"
flagAnnotations = "annotation"
)

func init() {
Expand All @@ -35,6 +36,7 @@ func init() {
cmd.PersistentFlags().String(flagOutput, "", "Output archive file. Don't push to OCI but just dump into a file")
cmd.PersistentFlags().Bool(flagInsecureRegistry, false, "Use HTTP instead of HTTPS to access the OCI registry")
cmd.PersistentFlags().String(flagDocsTarFile, "", "Optional tar.gz file containing a documentation bundle")
cmd.PersistentFlags().StringSlice(flagAnnotations, nil, "Annotations to add to the OCI image manifest")
}

var packCmd = &cobra.Command{
Expand Down Expand Up @@ -70,6 +72,11 @@ var packCmd = &cobra.Command{
return err
}

c.Annotations, err = flags.GetStringSlice(flagAnnotations)
if err != nil {
return err
}

return c.Run(cmd.Context(), vm, args[0], args[1])
},
}
10 changes: 10 additions & 0 deletions pkg/kubecfg/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type PackCmd struct {
OutputFile string
InsecureRegistry bool // use HTTP if true
DocsTarFile string
Annotations []string
}

func (c PackCmd) Run(ctx context.Context, vm *jsonnet.VM, ociPackage string, rootFile string) (err error) {
Expand Down Expand Up @@ -196,6 +197,15 @@ func (c PackCmd) pushOCIBundle(ctx context.Context, ref string, rootFile string,
"org.opencontainers.image.source": "kubecfg pack",
},
}
if c.Annotations != nil {
for _, a := range c.Annotations {
parts := strings.SplitN(a, "=", 2)
if len(parts) != 2 {
return fmt.Errorf("invalid annotation: %q", a)
}
manifest.Annotations[parts[0]] = parts[1]
}
}
manifestBlob, err := json.Marshal(manifest)
if err != nil {
return err
Expand Down

0 comments on commit 7a58125

Please sign in to comment.