Skip to content

Commit

Permalink
Use ubuntu cloud image with OVF (#140)
Browse files Browse the repository at this point in the history
* Use ubuntu cloud image with OVF

Also build docker image with Terraform instead of transfering it over.
Added ssh options to prevent host file checking.

* fixup! Use ubuntu cloud image with OVF
  • Loading branch information
krousey authored and k8s-ci-robot committed May 7, 2018
1 parent 7e593cd commit 5d5cdec
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 166 deletions.
5 changes: 2 additions & 3 deletions cloud/terraform/cmd/terraform-machine-controller/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ RUN CGO_ENABLED=0 GOOS=linux go install -a -ldflags '-extldflags "-static"' sigs

# Final container
FROM alpine:3.7
RUN apk --no-cache add --update ca-certificates bash openssh
RUN echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config
RUN echo "UserKnownHostsFile /dev/null" >> /etc/ssh/ssh_config
RUN apk --no-cache add --update ca-certificates bash openssh terraform
RUN echo 'plugin_cache_dir = "$HOME/.terraform.d/plugin-cache"' >> ~/.terraformrc
COPY --from=builder /go/bin/terraform-machine-controller .
2 changes: 1 addition & 1 deletion cloud/terraform/cmd/terraform-machine-controller/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
PREFIX = gcr.io/k8s-cluster-api
DEV_PREFIX ?= gcr.io/$(shell gcloud config get-value project)
NAME = terraform-machine-controller
TAG = 0.0.1
TAG = 0.0.2

image:
docker build -t "$(PREFIX)/$(NAME):$(TAG)" -f ./Dockerfile ../../../..
Expand Down
34 changes: 13 additions & 21 deletions cloud/terraform/machineactuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,17 @@ func (tf *TerraformClient) Create(cluster *clusterv1.Cluster, machine *clusterv1
args = append(args, fmt.Sprintf("vm_name=%s", machine.ObjectMeta.Name))
args = append(args, fmt.Sprintf("-var-file=%s", tfVarsPath))

out, cmdErr := runTerraformCmd(false, tfConfigDir, args...)
_, cmdErr := runTerraformCmd(false, tfConfigDir, args...)
if cmdErr != nil {
return errors.New(fmt.Sprintf("Could not run terraform: ", cmdErr))
return errors.New(fmt.Sprintf("Could not run terraform: %s", cmdErr))
}

// Get the IP address
kubeadmJoinIpRe := regexp.MustCompile("kubeadm join .* ([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}:[0-9]{1,5})")
parts := kubeadmJoinIpRe.FindStringSubmatch(out.String()) // [full match, ip addr]
if len(parts) < 2 {
return errors.New(fmt.Sprintf("Could not get master IP address. You will need to manually modify the cluster object's status with the endpoint if the master was created successfully."))
out, cmdErr := runTerraformCmd(false, tfConfigDir, "output", "ip_address")
if cmdErr != nil {
return fmt.Errorf("could not obtain 'ip_address' output variable: %s", cmdErr)
}
ipPortParts := strings.Split(parts[1], ":")
masterEndpointIp := ipPortParts[0]
masterEndpointIp := strings.TrimSpace(out.String())
glog.Infof("Master created with ip address %s", masterEndpointIp)

// If we have a machineClient, then annotate the machine so that we
Expand Down Expand Up @@ -396,8 +394,10 @@ func (tf *TerraformClient) GetKubeConfig(master *clusterv1.Machine) (string, err
cmd := exec.Command(
// TODO: this is taking my private key and username for now.
"ssh", "-i", "~/.ssh/vsphere_tmp",
"-o", "StrictHostKeyChecking no",
"-o", "UserKnownHostsFile /dev/null",
fmt.Sprintf("ubuntu@%s", ip),
"echo STARTFILE; cat /etc/kubernetes/admin.conf")
"echo STARTFILE; sudo cat /etc/kubernetes/admin.conf")
cmd.Stdout = &out
cmd.Stderr = os.Stderr
cmd.Run()
Expand Down Expand Up @@ -432,29 +432,21 @@ func (tf *TerraformClient) SetupRemoteMaster(master *clusterv1.Machine) error {
}
cmd := exec.Command(
"scp", "-i", "~/.ssh/vsphere_tmp",
"-o", "StrictHostKeyChecking no",
"-o", "UserKnownHostsFile /dev/null",
"-r",
path.Join(homedir, ".terraform.d"),
fmt.Sprintf("ubuntu@%s:~/", ip))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()

// TODO: Bake this into the controller image instead of this hacky thing.
glog.Infof("Copying the terraform binary to master.")
cmd = exec.Command(
// TODO: this is taking my private key and username for now.
"scp", "-i", "~/.ssh/vsphere_tmp",
// TODO: this should be a flag?
"-r", "/Users/karangoel/.gvm/pkgsets/go1.9.2/global/src/sigs.k8s.io/cluster-api/cloud/terraform/bin/",
fmt.Sprintf("ubuntu@%s:~/.terraform.d/", ip))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()

glog.Infof("Setting up terraform on remote master.")
cmd = exec.Command(
// TODO: this is taking my private key and username for now.
"ssh", "-i", "~/.ssh/vsphere_tmp",
"-o", "StrictHostKeyChecking no",
"-o", "UserKnownHostsFile /dev/null",
fmt.Sprintf("ubuntu@%s", ip),
fmt.Sprintf("source ~/.profile; cd ~/.terraform.d/kluster/machines/%s; ~/.terraform.d/terraform init; cp -r ~/.terraform.d/kluster/machines/%s/.terraform/plugins/* ~/.terraform.d/plugins/", machineName, machineName))
cmd.Stdout = os.Stdout
Expand Down
4 changes: 2 additions & 2 deletions cloud/terraform/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ deb [arch=amd64] https://apt.dockerproject.org/repo ubuntu-xenial main
EOF
apt-get update
apt-get install -y docker-engine=1.11.2-0~xenial
apt-get install -y docker.io
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
Expand Down Expand Up @@ -313,7 +313,7 @@ kubeadm init --apiserver-bind-port ${PORT} --token ${TOKEN} --kubernetes-version
# install weavenet
sysctl net.bridge.bridge-nf-call-iptables=1
export kubever=$(kubectl version --kubeconfig /etc/kubernetes/admin.conf | base64 | tr -d '\n')
kubectl apply --kubeconfig /etc/kubernetes/admin.conf -f "https://cloud.weave.works/k8s/net?k8s-version=$kubever"
kubectl apply --kubeconfig /etc/kubernetes/admin.conf -f "https://cloud.weave.works/k8s/net?env.CHECKPOINT_DISABLE=1&env.IPALLOC_RANGE=${POD_CIDR}&disable-npc=true&k8s-version=$kubever"
for tries in $(seq 1 60); do
kubectl --kubeconfig /etc/kubernetes/kubelet.conf annotate --overwrite node $(hostname) machine=${MACHINE} && break
Expand Down
Loading

0 comments on commit 5d5cdec

Please sign in to comment.