Skip to content

Commit

Permalink
Use kops create -f for creating clusters via manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
rifelpet committed Jan 13, 2021
1 parent 196e678 commit 6b7309d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ import (
"sigs.k8s.io/kubetest2/pkg/exec"
)

// replace performs a `kops replace` followed by `kops update cluster --yes`
// create performs a `kops create -f` followed by `kops update cluster --yes`
func (d *deployer) replace() error {
args := []string{
d.KopsBinaryPath, "replace",
d.KopsBinaryPath, "create",
"--filename", d.manifestPath,
"--force",
"--name", d.ClusterName,
}
klog.Info(strings.Join(args, " "))
Expand All @@ -42,22 +41,6 @@ func (d *deployer) replace() error {
return err
}

args = []string{
d.KopsBinaryPath, "create", "secret", "sshpublickey",
"admin",
"-i", d.SSHPublicKeyPath,
"--name", d.ClusterName,
}
klog.Info(strings.Join(args, " "))
cmd = exec.Command(args[0], args[1:]...)
cmd.SetEnv(d.env()...)

exec.InheritOutput(cmd)
err = cmd.Run()
if err != nil {
return err
}

args = []string{
d.KopsBinaryPath, "update", "cluster", "--yes",
"--name", d.ClusterName,
Expand Down
9 changes: 7 additions & 2 deletions tests/e2e/kubetest2-kops/deployer/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,18 @@ func (d *deployer) renderTemplate(values map[string]interface{}) error {
return nil
}

func (d *deployer) templateValues(zones []string, publicIP string) map[string]interface{} {
func (d *deployer) templateValues(zones []string, publicIP string) (map[string]interface{}, error) {
publicKey, err := ioutil.ReadFile(d.SSHPublicKeyPath)
if err != nil {
return nil, err
}
return map[string]interface{}{
"cloudProvider": d.CloudProvider,
"clusterName": d.ClusterName,
"kubernetesVersion": d.KubernetesVersion,
"publicIP": publicIP,
"stateStore": d.StateStore,
"zones": zones,
}
"sshPublicKey": string(publicKey),
}, nil
}
5 changes: 4 additions & 1 deletion tests/e2e/kubetest2-kops/deployer/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ func (d *deployer) Up() error {
}

if d.TemplatePath != "" {
values := d.templateValues(zones, adminAccess)
values, err := d.templateValues(zones, adminAccess)
if err != nil {
return err
}
if err := d.renderTemplate(values); err != nil {
return err
}
Expand Down
11 changes: 11 additions & 0 deletions tests/e2e/templates/simple.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ spec:

---

apiVersion: kops.k8s.io/v1alpha2
kind: SSHCredential
metadata:
name: admin
labels:
kops.k8s.io/cluster: {{.clusterName}}
spec:
publicKey: {{.sshPublicKey}}

---

apiVersion: kops.k8s.io/v1alpha2
kind: InstanceGroup
metadata:
Expand Down

0 comments on commit 6b7309d

Please sign in to comment.