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

add support for generate name #80

Merged
merged 2 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 18 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,17 @@ func splitYamlDocs(data string) []string {
}

func deploy(c *cli.Context, r *ObjectResource) error {
logDebug.Printf("about to deploy resource %s/%s (from file:%q)", r.Kind, r.Name, r.FileName)
args := []string{"apply", "-f", "-"}

name := r.Name
command := "apply"

if r.GenerateName != "" {
name = r.GenerateName
command = "create"
}

logDebug.Printf("about to deploy resource %s/%s (from file:%q)", r.Kind, name, r.FileName)
args := []string{command, "-f", "-"}
cmd, err := newKubeCmd(c, args)
if err != nil {
return err
Expand Down Expand Up @@ -279,6 +288,13 @@ func deploy(c *cli.Context, r *ObjectResource) error {
return err
}
logInfo.Print(outbuf.String())

if r.GenerateName != "" {
//This gets the generated resource name from the output
resourceName := strings.TrimSuffix(outbuf.String(), " created\n")
r.Name = strings.Split(resourceName, "/")[1]
}

if isWatchableResouce(r) {
return watchResource(c, r)
}
Expand Down
3 changes: 3 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type ObjectMeta struct {
// Not all objects are required to be scoped to a namespace - the value of this field for
// those objects will be empty.
Namespace string `yaml:"namespace,omitempty"`

// GenerateName causes kubernetes to generate a random resource name for you on create, it takes the given string and suffixes a random string to it
GenerateName string `yaml:"generateName,omitempty"`
}

// DeploymentStatus is the most recently observed status of the Deployment / Statefulset / DaemonSets.
Expand Down