Skip to content

Commit

Permalink
Remove call to preloaded script in generate-image
Browse files Browse the repository at this point in the history
  • Loading branch information
kcoronado committed Apr 3, 2018
1 parent 6bc01dd commit 242d193
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions cluster-api/cloud/google/cmd/generate-image/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ import (

"github.com/golang/glog"
"github.com/spf13/cobra"
"k8s.io/kube-deploy/cluster-api/cloud/google"
"io/ioutil"
"os"
)

type options struct {
version string
role string
dockerImages []string
script string
}

var opts options
Expand All @@ -36,38 +35,31 @@ var generateCmd = &cobra.Command{
Use: "generate_image",
Short: "Outputs a script to generate a preloaded image",
Run: func(cmd *cobra.Command, args []string) {
if opts.script == "" {
glog.Error("Please provide a startup script.")
cmd.Help()
os.Exit(1)
}

if err := runGenerate(opts); err != nil {
glog.Exit(err)
}
},
}

// TODO(kcoronado): take a script file as a parameter instead of generating the preloaded script from the template.
func init() {
generateCmd.Flags().StringVar(&opts.version, "version", "1.7.3", "The version of kubernetes to install")
generateCmd.Flags().StringVar(&opts.role, "role", "master", "The role of the machine (master or node)")
generateCmd.Flags().StringArrayVar(&opts.dockerImages, "extra-docker-images", []string{}, "extra docker images to preload")
generateCmd.Flags().StringVar(&opts.script, "script", "", "The path to the machine's startup script")
}

func runGenerate(o options) error {
var script string
var err error
switch o.role {
case "master":
script, err = google.PreloadMasterScript(o.version, o.dockerImages)
case "node":
script, err = google.PreloadMasterScript(o.version, o.dockerImages)
default:
return fmt.Errorf("unrecognized role: %q", o.role)
}

bytes, err := ioutil.ReadFile(o.script)
if err != nil {
return err
}

// just print the script for now
// TODO actually start a VM, let it run the script, stop the VM, then create the image
fmt.Println(script)
fmt.Println(string(bytes))
return nil
}

Expand Down

0 comments on commit 242d193

Please sign in to comment.