Skip to content

Commit 3bf1852

Browse files
feat(publish): add publish command stub
1 parent 72b0fd1 commit 3bf1852

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

kustomize/commands/commands.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"sigs.k8s.io/kustomize/kustomize/v5/commands/edit"
2020
"sigs.k8s.io/kustomize/kustomize/v5/commands/localize"
2121
"sigs.k8s.io/kustomize/kustomize/v5/commands/openapi"
22+
"sigs.k8s.io/kustomize/kustomize/v5/commands/publish"
2223
"sigs.k8s.io/kustomize/kustomize/v5/commands/version"
2324
"sigs.k8s.io/kustomize/kyaml/filesys"
2425
)
@@ -55,6 +56,7 @@ See https://sigs.k8s.io/kustomize
5556
version.NewCmdVersion(stdOut),
5657
openapi.NewCmdOpenAPI(stdOut),
5758
localize.NewCmdLocalize(fSys),
59+
publish.NewCmdPublish(fSys, pvd.GetFieldValidator(), pvd.GetResourceFactory()),
5860
)
5961
configcobra.AddCommands(c, konfig.ProgramName)
6062

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright 2019 The Kubernetes Authors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package publish
5+
6+
import (
7+
"errors"
8+
9+
"github.com/spf13/cobra"
10+
"sigs.k8s.io/kustomize/api/ifc"
11+
"sigs.k8s.io/kustomize/api/resource"
12+
"sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile"
13+
"sigs.k8s.io/kustomize/kyaml/filesys"
14+
)
15+
16+
type publishOptions struct {
17+
registry string
18+
noVerify bool
19+
}
20+
21+
// NewCmdEdit returns an instance of 'edit' subcommand.
22+
func NewCmdPublish(
23+
fSys filesys.FileSystem, v ifc.Validator, rf *resource.Factory,
24+
) *cobra.Command {
25+
var o publishOptions
26+
27+
cmd := &cobra.Command{
28+
Use: "publish",
29+
Short: "Publishes a kustomization resource to an OCI registry",
30+
Long: "",
31+
Example: `
32+
publish <registry>
33+
`,
34+
RunE: func(cmd *cobra.Command, args []string) error {
35+
err := o.Validate(args)
36+
if err != nil {
37+
return err
38+
}
39+
return o.RunPublish(fSys)
40+
},
41+
42+
Args: cobra.MinimumNArgs(1),
43+
}
44+
cmd.Flags().BoolVar(&o.noVerify, "no-verify", false,
45+
"skip validation for resources",
46+
)
47+
return cmd
48+
}
49+
50+
// Validate validates addResource command.
51+
func (o *publishOptions) Validate(args []string) error {
52+
if len(args) == 0 {
53+
return errors.New("must specify a registry")
54+
}
55+
o.registry = args[0]
56+
return nil
57+
}
58+
59+
// RunAddResource runs addResource command (do real work).
60+
func (o *publishOptions) RunPublish(fSys filesys.FileSystem) error {
61+
mf, err := kustfile.NewKustomizationFile(fSys)
62+
if err != nil {
63+
return err
64+
}
65+
m, err := mf.Read()
66+
if err != nil {
67+
return err
68+
}
69+
70+
for _, r := range m.Resources {
71+
println(r)
72+
}
73+
74+
return nil
75+
}

0 commit comments

Comments
 (0)