Merge pull request #2052 from reactiveops/fix_gh_1953

Feedback for kops create -f when operation succeeds
This commit is contained in:
Justin Santa Barbara 2017-03-27 22:54:56 -04:00 committed by GitHub
commit e50f6c661a
1 changed files with 25 additions and 4 deletions

View File

@ -84,6 +84,10 @@ func RunCreate(f *util.Factory, out io.Writer, c *CreateOptions) error {
codec := codecs.UniversalDecoder(kopsapi.SchemeGroupVersion) codec := codecs.UniversalDecoder(kopsapi.SchemeGroupVersion)
var clusterName = ""
//var cSpec = false
var sb bytes.Buffer
fmt.Fprintf(&sb, "\n")
for _, f := range c.Filenames { for _, f := range c.Filenames {
contents, err := vfs.Context.ReadFile(f) contents, err := vfs.Context.ReadFile(f)
if err != nil { if err != nil {
@ -91,7 +95,6 @@ func RunCreate(f *util.Factory, out io.Writer, c *CreateOptions) error {
} }
sections := bytes.Split(contents, []byte("\n---\n")) sections := bytes.Split(contents, []byte("\n---\n"))
for _, section := range sections { for _, section := range sections {
defaults := &schema.GroupVersionKind{ defaults := &schema.GroupVersionKind{
Group: v1alpha1.SchemeGroupVersion.Group, Group: v1alpha1.SchemeGroupVersion.Group,
@ -111,6 +114,7 @@ func RunCreate(f *util.Factory, out io.Writer, c *CreateOptions) error {
} }
return fmt.Errorf("error creating federation: %v", err) return fmt.Errorf("error creating federation: %v", err)
} }
fmt.Fprintf(&sb, "Created federation/%q\n", v.ObjectMeta.Name)
case *kopsapi.Cluster: case *kopsapi.Cluster:
// Adding a PerformAssignments() call here as the user might be trying to use // Adding a PerformAssignments() call here as the user might be trying to use
@ -125,10 +129,13 @@ func RunCreate(f *util.Factory, out io.Writer, c *CreateOptions) error {
return fmt.Errorf("cluster %q already exists", v.ObjectMeta.Name) return fmt.Errorf("cluster %q already exists", v.ObjectMeta.Name)
} }
return fmt.Errorf("error creating cluster: %v", err) return fmt.Errorf("error creating cluster: %v", err)
} else {
fmt.Fprintf(&sb, "Created cluster/%s\n", v.ObjectMeta.Name)
//cSpec = true
} }
case *kopsapi.InstanceGroup: case *kopsapi.InstanceGroup:
clusterName := v.ObjectMeta.Labels[kopsapi.LabelClusterName] clusterName = v.ObjectMeta.Labels[kopsapi.LabelClusterName]
if clusterName == "" { if clusterName == "" {
return fmt.Errorf("must specify %q label with cluster name to create instanceGroup", kopsapi.LabelClusterName) return fmt.Errorf("must specify %q label with cluster name to create instanceGroup", kopsapi.LabelClusterName)
} }
@ -138,15 +145,29 @@ func RunCreate(f *util.Factory, out io.Writer, c *CreateOptions) error {
return fmt.Errorf("instanceGroup %q already exists", v.ObjectMeta.Name) return fmt.Errorf("instanceGroup %q already exists", v.ObjectMeta.Name)
} }
return fmt.Errorf("error creating instanceGroup: %v", err) return fmt.Errorf("error creating instanceGroup: %v", err)
} else {
fmt.Fprintf(&sb, "Created instancegroup/%s\n", v.ObjectMeta.Name)
} }
default: default:
glog.V(2).Infof("Type of object was %T", v) glog.V(2).Infof("Type of object was %T", v)
return fmt.Errorf("Unhandled kind %q in %q", gvk, f) return fmt.Errorf("Unhandled kind %q in %s", gvk, f)
} }
} }
} }
{
// If there is a value in this sb, this should mean that we have something to deploy
// so let's advise the user how to engage the cloud provider and deploy
if sb.String() != "" {
fmt.Fprintf(&sb, "\n")
fmt.Fprintf(&sb, "To deploy these resources, run: kops update cluster %s --yes\n", clusterName)
fmt.Fprintf(&sb, "\n")
}
_, err := out.Write(sb.Bytes())
if err != nil {
return fmt.Errorf("error writing to output: %v", err)
}
}
return nil return nil
} }