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

Handling configurable machine setup/installation #104

Merged
merged 3 commits into from
Apr 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions cloud/google/cmd/gce-machine-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import (
)

var (
kubeadmToken = pflag.String("token", "", "Kubeadm token to use to join new machines")
kubeadmToken = pflag.String("token", "", "Kubeadm token to use to join new machines")
machineSetupConfigsPath = pflag.String("machinesetup", "", "path to machine setup configs file")
)

func init() {
Expand All @@ -54,7 +55,7 @@ func main() {
glog.Fatalf("Could not create client for talking to the apiserver: %v", err)
}

actuator, err := google.NewMachineActuator(*kubeadmToken, client.ClusterV1alpha1().Machines(corev1.NamespaceDefault))
actuator, err := google.NewMachineActuator(*kubeadmToken, client.ClusterV1alpha1().Machines(corev1.NamespaceDefault), *machineSetupConfigsPath)
if err != nil {
glog.Fatalf("Could not create Google machine actuator: %v", err)
}
Expand Down
32 changes: 13 additions & 19 deletions cloud/google/cmd/generate-image/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ package main
import (
"fmt"

"io/ioutil"
"os"

"github.com/golang/glog"
"github.com/spf13/cobra"
"sigs.k8s.io/cluster-api/cloud/google"
)

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

var opts options
Expand All @@ -36,37 +36,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)
}
},
}

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
6 changes: 6 additions & 0 deletions cloud/google/config/configtemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ spec:
mountPath: /etc/credentials
- name: sshkeys
mountPath: /etc/sshkeys
- name: machine-setup
mountPath: /etc/machinesetup
env:
- name: GOOGLE_APPLICATION_CREDENTIALS
value: /etc/credentials/service-account.json
Expand All @@ -147,6 +149,7 @@ spec:
args:
- --kubeconfig=/etc/kubernetes/admin.conf
- --token={{ .Token }}
- --machinesetup=/etc/machinesetup/machine_setup_configs.yaml
resources:
requests:
cpu: 100m
Expand All @@ -171,6 +174,9 @@ spec:
- name: credentials
secret:
secretName: machine-controller-credential
- name: machine-setup
configMap:
name: machine-setup
---
apiVersion: apps/v1beta1
kind: StatefulSet
Expand Down
4 changes: 3 additions & 1 deletion cloud/google/gceproviderconfig/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ type GCEProviderConfig struct {
Project string `json:"project"`
Zone string `json:"zone"`
MachineType string `json:"machineType"`
Image string `json:"image"`

// The name of the OS to be installed on the machine.
OS string `json:"os"`
}
4 changes: 3 additions & 1 deletion cloud/google/gceproviderconfig/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ type GCEProviderConfig struct {
Project string `json:"project"`
Zone string `json:"zone"`
MachineType string `json:"machineType"`
Image string `json:"image"`

// The name of the OS to be installed on the machine.
OS string `json:"os"`
}
Loading