e2e.go / kops: Add --kops-kubernetes-version

This adds a flag to override the version we're deploying with kops for
e2es. (The kops experience is disconnected from the actual source tree
we're running tests from, which is similar to GKE.)
This commit is contained in:
Zach Loafman 2016-10-04 13:51:02 -07:00
parent d26b4ca285
commit ca58119af7
2 changed files with 30 additions and 21 deletions

View File

@ -52,12 +52,13 @@ var (
verbose = flag.Bool("v", false, "If true, print all command output.") verbose = flag.Bool("v", false, "If true, print all command output.")
// kops specific flags. // kops specific flags.
kopsPath = flag.String("kops", "", "(kops only) Path to the kops binary. Must be set for kops.") kopsPath = flag.String("kops", "", "(kops only) Path to the kops binary. Must be set for kops.")
kopsCluster = flag.String("kops-cluster", "", "(kops only) Cluster name. Must be set for kops.") kopsCluster = flag.String("kops-cluster", "", "(kops only) Cluster name. Must be set for kops.")
kopsState = flag.String("kops-state", os.Getenv("KOPS_STATE_STORE"), "(kops only) s3:// path to kops state store. Must be set. (This flag defaults to $KOPS_STATE_STORE, and overrides it if set.)") kopsState = flag.String("kops-state", os.Getenv("KOPS_STATE_STORE"), "(kops only) s3:// path to kops state store. Must be set. (This flag defaults to $KOPS_STATE_STORE, and overrides it if set.)")
kopsSSHKey = flag.String("kops-ssh-key", os.Getenv("AWS_SSH_KEY"), "(kops only) Path to ssh key-pair for each node. (Defaults to $AWS_SSH_KEY or '~/.ssh/kube_aws_rsa'.)") kopsSSHKey = flag.String("kops-ssh-key", os.Getenv("AWS_SSH_KEY"), "(kops only) Path to ssh key-pair for each node. (Defaults to $AWS_SSH_KEY or '~/.ssh/kube_aws_rsa'.)")
kopsZones = flag.String("kops-zones", "us-west-2a", "(kops AWS only) AWS zones for kops deployment, comma delimited.") kopsKubeVersion = flag.String("kops-kubernetes-version", "", "(kops only) If set, the version of Kubernetes to deploy (can be a URL to a GCS path where the release is stored) (Defaults to kops default, latest stable release.).")
kopsNodes = flag.Int("kops-nodes", 2, "(kops only) Number of nodes to create.") kopsZones = flag.String("kops-zones", "us-west-2a", "(kops AWS only) AWS zones for kops deployment, comma delimited.")
kopsNodes = flag.Int("kops-nodes", 2, "(kops only) Number of nodes to create.")
// Deprecated flags. // Deprecated flags.
deprecatedPush = flag.Bool("push", false, "Deprecated. Does nothing.") deprecatedPush = flag.Bool("push", false, "Deprecated. Does nothing.")
@ -392,12 +393,13 @@ func (b bash) Down() error {
} }
type kops struct { type kops struct {
path string path string
sshKey string kubeVersion string
zones []string sshKey string
nodes int zones []string
cluster string nodes int
kubecfg string cluster string
kubecfg string
} }
func NewKops() (*kops, error) { func NewKops() (*kops, error) {
@ -453,22 +455,28 @@ func NewKops() (*kops, error) {
return nil, err return nil, err
} }
return &kops{ return &kops{
path: *kopsPath, path: *kopsPath,
sshKey: sshKey + ".pub", // kops only needs the public key, e2es need the private key. kubeVersion: *kopsKubeVersion,
zones: zones, sshKey: sshKey + ".pub", // kops only needs the public key, e2es need the private key.
nodes: *kopsNodes, zones: zones,
cluster: *kopsCluster, nodes: *kopsNodes,
kubecfg: kubecfg, cluster: *kopsCluster,
kubecfg: kubecfg,
}, nil }, nil
} }
func (k kops) Up() error { func (k kops) Up() error {
if err := finishRunning("kops config", exec.Command( createArgs := []string{
k.path, "create", "cluster", "create", "cluster",
"--name", k.cluster, "--name", k.cluster,
"--ssh-public-key", k.sshKey, "--ssh-public-key", k.sshKey,
"--node-count", strconv.Itoa(k.nodes), "--node-count", strconv.Itoa(k.nodes),
"--zones", strings.Join(k.zones, ","))); err != nil { "--zones", strings.Join(k.zones, ","),
}
if k.kubeVersion != "" {
createArgs = append(createArgs, "--kubernetes-version", k.kubeVersion)
}
if err := finishRunning("kops config", exec.Command(k.path, createArgs...)); err != nil {
return fmt.Errorf("kops configuration failed: %v", err) return fmt.Errorf("kops configuration failed: %v", err)
} }
if err := finishRunning("kops update", exec.Command(k.path, "update", "cluster", k.cluster, "--yes")); err != nil { if err := finishRunning("kops update", exec.Command(k.path, "update", "cluster", k.cluster, "--yes")); err != nil {

View File

@ -275,6 +275,7 @@ k8s-build-output
keep-gogoproto keep-gogoproto
km-path km-path
kops-cluster kops-cluster
kops-kubernetes-version
kops-nodes kops-nodes
kops-ssh-key kops-ssh-key
kops-state kops-state