Skip to content

Commit c72ef95

Browse files
authored
Merge pull request #1421 from justinsb/harmonious_create
Use update cluster from create cluster
2 parents 0d6ff79 + f70029c commit c72ef95

File tree

2 files changed

+43
-48
lines changed

2 files changed

+43
-48
lines changed

Diff for: cmd/kops/create_cluster.go

+17-30
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"k8s.io/kops/upup/pkg/fi"
3333
"k8s.io/kops/upup/pkg/fi/cloudup"
3434
"k8s.io/kops/upup/pkg/fi/utils"
35-
"k8s.io/kops/upup/pkg/kutil"
3635
"sort"
3736
)
3837

@@ -586,11 +585,6 @@ func RunCreateCluster(f *util.Factory, out io.Writer, c *CreateClusterOptions) e
586585
return err
587586
}
588587

589-
secretStore, err := registry.SecretStore(cluster)
590-
if err != nil {
591-
return err
592-
}
593-
594588
err = registry.WriteConfigDeprecated(configBase.Join(registry.PathClusterCompleted), fullCluster)
595589
if err != nil {
596590
return fmt.Errorf("error writing completed cluster spec: %v", err)
@@ -605,19 +599,26 @@ func RunCreateCluster(f *util.Factory, out io.Writer, c *CreateClusterOptions) e
605599

606600
if targetName != "" {
607601
if isDryrun {
608-
fmt.Print("Previewing changes that will be made:\n\n")
602+
fmt.Fprintf(out, "Previewing changes that will be made:\n\n")
609603
}
610604

611-
applyCmd := &cloudup.ApplyClusterCmd{
612-
Cluster: fullCluster,
613-
Models: strings.Split(c.Models, ","),
614-
Clientset: clientset,
615-
TargetName: targetName,
616-
OutDir: c.OutDir,
617-
DryRun: isDryrun,
618-
}
605+
// TODO: Maybe just embed UpdateClusterOptions in CreateClusterOptions?
606+
updateClusterOptions := &UpdateClusterOptions{}
607+
updateClusterOptions.InitDefaults()
608+
609+
updateClusterOptions.Yes = c.Yes
610+
updateClusterOptions.Target = c.Target
611+
updateClusterOptions.Models = c.Models
612+
updateClusterOptions.OutDir = c.OutDir
613+
614+
// SSHPublicKey has already been mapped
615+
updateClusterOptions.SSHPublicKey = ""
619616

620-
err = applyCmd.Run()
617+
// No equivalent options:
618+
// updateClusterOptions.MaxTaskDuration = c.MaxTaskDuration
619+
// updateClusterOptions.CreateKubecfg = c.CreateKubecfg
620+
621+
err := RunUpdateCluster(f, clusterName, out, updateClusterOptions)
621622
if err != nil {
622623
return err
623624
}
@@ -644,20 +645,6 @@ func RunCreateCluster(f *util.Factory, out io.Writer, c *CreateClusterOptions) e
644645
if err != nil {
645646
return fmt.Errorf("error writing to output: %v", err)
646647
}
647-
} else {
648-
glog.Infof("Exporting kubecfg for cluster")
649-
650-
x := &kutil.CreateKubecfg{
651-
ContextName: cluster.ObjectMeta.Name,
652-
KeyStore: keyStore,
653-
SecretStore: secretStore,
654-
KubeMasterIP: cluster.Spec.MasterPublicName,
655-
}
656-
657-
err = x.WriteKubecfg()
658-
if err != nil {
659-
return err
660-
}
661648
}
662649
}
663650

Diff for: cmd/kops/update_cluster.go

+26-18
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
"bytes"
2021
"fmt"
2122
"github.com/golang/glog"
2223
"github.com/spf13/cobra"
@@ -163,9 +164,9 @@ func RunUpdateCluster(f *util.Factory, clusterName string, out io.Writer, c *Upd
163164
if isDryrun {
164165
target := applyCmd.Target.(*fi.DryRunTarget)
165166
if target.HasChanges() {
166-
fmt.Printf("Must specify --yes to apply changes\n")
167+
fmt.Fprintf(out, "Must specify --yes to apply changes\n")
167168
} else {
168-
fmt.Printf("No changes need to be applied\n")
169+
fmt.Fprintf(out, "No changes need to be applied\n")
169170
}
170171
return nil
171172
}
@@ -202,29 +203,36 @@ func RunUpdateCluster(f *util.Factory, clusterName string, out io.Writer, c *Upd
202203
}
203204

204205
if !hasKubecfg {
206+
sb := new(bytes.Buffer)
207+
205208
// Assume initial creation
206209
if c.Target == cloudup.TargetTerraform {
207-
fmt.Printf("\n")
208-
fmt.Printf("Terraform output has been placed into %s\n", c.OutDir)
209-
fmt.Printf("Run these commands to apply the configuration:\n")
210-
fmt.Printf(" cd %s\n", c.OutDir)
211-
fmt.Printf(" terraform plan\n")
212-
fmt.Printf(" terraform apply\n")
213-
fmt.Printf("\n")
210+
fmt.Fprintf(sb, "\n")
211+
fmt.Fprintf(sb, "Terraform output has been placed into %s\n", c.OutDir)
212+
fmt.Fprintf(sb, "Run these commands to apply the configuration:\n")
213+
fmt.Fprintf(sb, " cd %s\n", c.OutDir)
214+
fmt.Fprintf(sb, " terraform plan\n")
215+
fmt.Fprintf(sb, " terraform apply\n")
216+
fmt.Fprintf(sb, "\n")
214217
} else {
215-
fmt.Printf("\n")
216-
fmt.Printf("Cluster is starting. It should be ready in a few minutes.\n")
217-
fmt.Printf("\n")
218+
fmt.Fprintf(sb, "\n")
219+
fmt.Fprintf(sb, "Cluster is starting. It should be ready in a few minutes.\n")
220+
fmt.Fprintf(sb, "\n")
218221
}
219-
fmt.Printf("Suggestions:\n")
220-
fmt.Printf(" * list nodes: kubectl get nodes --show-labels\n")
222+
fmt.Fprintf(sb, "Suggestions:\n")
223+
fmt.Fprintf(sb, " * list nodes: kubectl get nodes --show-labels\n")
221224
if cluster.Spec.Topology.Masters == kops.TopologyPublic {
222-
fmt.Printf(" * ssh to the master: ssh -i ~/.ssh/id_rsa admin@%s\n", cluster.Spec.MasterPublicName)
225+
fmt.Fprintf(sb, " * ssh to the master: ssh -i ~/.ssh/id_rsa admin@%s\n", cluster.Spec.MasterPublicName)
223226
} else {
224-
fmt.Printf(" * ssh to the bastion: ssh -i ~/.ssh/id_rsa admin@%s\n", cluster.Spec.MasterPublicName)
227+
fmt.Fprintf(sb, " * ssh to the bastion: ssh -i ~/.ssh/id_rsa admin@%s\n", cluster.Spec.MasterPublicName)
228+
}
229+
fmt.Fprintf(sb, " * read about installing addons: https://github.com/kubernetes/kops/blob/master/docs/addons.md\n")
230+
fmt.Fprintf(sb, "\n")
231+
232+
_, err := out.Write(sb.Bytes())
233+
if err != nil {
234+
return fmt.Errorf("error writing to output: %v", err)
225235
}
226-
fmt.Printf(" * read about installing addons: https://github.com/kubernetes/kops/blob/master/docs/addons.md\n")
227-
fmt.Printf("\n")
228236
}
229237
}
230238

0 commit comments

Comments
 (0)