Use kops create -f for creating clusters via manifest

This commit is contained in:
Peter Rifel 2021-01-12 19:19:58 -06:00
parent 196e678205
commit cef43d2002
No known key found for this signature in database
GPG Key ID: BC6469E5B16DB2B6
5 changed files with 26 additions and 24 deletions

View File

@ -152,9 +152,9 @@ func stateStore(cloudProvider string) string {
if ss == "" {
switch cloudProvider {
case "aws":
ss = "s3://k8s-kops-prow/"
ss = "s3://k8s-kops-prow"
case "gce":
ss = "gs://k8s-kops-gce/"
ss = "gs://k8s-kops-gce"
}
}
return ss

View File

@ -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, " "))
@ -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,

View File

@ -63,7 +63,11 @@ 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,
@ -71,5 +75,6 @@ func (d *deployer) templateValues(zones []string, publicIP string) map[string]in
"publicIP": publicIP,
"stateStore": d.StateStore,
"zones": zones,
}
"sshPublicKey": string(publicKey),
}, nil
}

View File

@ -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
}

View File

@ -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: