123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- package remote
- import (
- "fmt"
- "path/filepath"
- "strings"
- "k8s.io/klog"
- )
- const (
- cniVersion = "v0.8.5"
- cniArch = "amd64"
- cniDirectory = "cni/bin"
- cniConfDirectory = "cni/net.d"
- cniURL = "https://storage.googleapis.com/k8s-artifacts-cni/release/" + cniVersion + "/" + "cni-plugins-linux-" + cniArch + "-" + cniVersion + ".tgz"
- )
- const cniConfig = `{
- "name": "mynet",
- "type": "bridge",
- "bridge": "mynet0",
- "isDefaultGateway": true,
- "forceAddress": false,
- "ipMasq": true,
- "hairpinMode": true,
- "ipam": {
- "type": "host-local",
- "subnet": "10.10.0.0/16"
- }
- }
- `
- func setupCNI(host, workspace string) error {
- klog.V(2).Infof("Install CNI on %q", host)
- cniPath := filepath.Join(workspace, cniDirectory)
- cmd := getSSHCommand(" ; ",
- fmt.Sprintf("mkdir -p %s", cniPath),
- fmt.Sprintf("curl -s -L %s | tar -xz -C %s", cniURL, cniPath),
- )
- if output, err := SSH(host, "sh", "-c", cmd); err != nil {
- return fmt.Errorf("failed to install cni plugin on %q: %v output: %q", host, err, output)
- }
-
-
-
- klog.V(2).Infof("Adding CNI configuration on %q", host)
- cniConfigPath := filepath.Join(workspace, cniConfDirectory)
- cmd = getSSHCommand(" ; ",
- fmt.Sprintf("mkdir -p %s", cniConfigPath),
- fmt.Sprintf("echo %s > %s", quote(cniConfig), filepath.Join(cniConfigPath, "mynet.conf")),
- )
- if output, err := SSH(host, "sh", "-c", cmd); err != nil {
- return fmt.Errorf("failed to write cni configuration on %q: %v output: %q", host, err, output)
- }
- return nil
- }
- func configureFirewall(host string) error {
- klog.V(2).Infof("Configure iptables firewall rules on %q", host)
-
- output, err := SSH(host, "iptables", "-L", "INPUT")
- if err != nil {
- return fmt.Errorf("failed to get iptables INPUT on %q: %v output: %q", host, err, output)
- }
- if strings.Contains(output, "Chain INPUT (policy DROP)") {
- cmd := getSSHCommand("&&",
- "(iptables -C INPUT -w -p TCP -j ACCEPT || iptables -A INPUT -w -p TCP -j ACCEPT)",
- "(iptables -C INPUT -w -p UDP -j ACCEPT || iptables -A INPUT -w -p UDP -j ACCEPT)",
- "(iptables -C INPUT -w -p ICMP -j ACCEPT || iptables -A INPUT -w -p ICMP -j ACCEPT)")
- output, err := SSH(host, "sh", "-c", cmd)
- if err != nil {
- return fmt.Errorf("failed to configured firewall on %q: %v output: %v", host, err, output)
- }
- }
- output, err = SSH(host, "iptables", "-L", "FORWARD")
- if err != nil {
- return fmt.Errorf("failed to get iptables FORWARD on %q: %v output: %q", host, err, output)
- }
- if strings.Contains(output, "Chain FORWARD (policy DROP)") {
- cmd := getSSHCommand("&&",
- "(iptables -C FORWARD -w -p TCP -j ACCEPT || iptables -A FORWARD -w -p TCP -j ACCEPT)",
- "(iptables -C FORWARD -w -p UDP -j ACCEPT || iptables -A FORWARD -w -p UDP -j ACCEPT)",
- "(iptables -C FORWARD -w -p ICMP -j ACCEPT || iptables -A FORWARD -w -p ICMP -j ACCEPT)")
- output, err = SSH(host, "sh", "-c", cmd)
- if err != nil {
- return fmt.Errorf("failed to configured firewall on %q: %v output: %v", host, err, output)
- }
- }
- return nil
- }
- func cleanupNodeProcesses(host string) {
- klog.V(2).Infof("Killing any existing node processes on %q", host)
- cmd := getSSHCommand(" ; ",
- "pkill kubelet",
- "pkill kube-apiserver",
- "pkill etcd",
- "pkill e2e_node.test",
- )
-
-
-
- SSH(host, "sh", "-c", cmd)
- }
- func quote(s string) string {
- return fmt.Sprintf("'\"'\"'%s'\"'\"'", s)
- }
|