Skip to content

Commit

Permalink
Merge pull request #80 from uswitch/support_generate_name
Browse files Browse the repository at this point in the history
add support for generate name
  • Loading branch information
gambol99 committed Jun 15, 2018
2 parents bbf1be6 + c9256bb commit be80707
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
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

0 comments on commit be80707

Please sign in to comment.