Skip to content

Commit

Permalink
Removes assumption of Docker on Kubernetes hosts (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eagerod authored Feb 22, 2025
1 parent 8aa074c commit 20b03f9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 48 deletions.
30 changes: 4 additions & 26 deletions pkg/hope/node_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import (
"github.com/Eagerod/hope/pkg/ssh"
)

// Sets up any configuration on Kubernetes nodes that are common between
// control-plane nodes, and worker nodes.
// TODO: Consider writing these files using file provisioners in Packer
// instead?
func setupCommonNodeRequirements(log *logrus.Entry, node *Node) error {
if !node.IsKubernetesNode() {
return fmt.Errorf("Node has role %s, should not prepare as Kubernetes node", node.Role)
Expand All @@ -30,30 +34,6 @@ func setupCommonNodeRequirements(log *logrus.Entry, node *Node) error {

connectionString := node.ConnectionString()

// TODO: Create a function in ssh pkg that allows for running
// multi-statement commands on the target without needing to manually
// construct the string.
// TODO: Consider writing these files using file provisioners in Packer
// instead?
commands := []string{
"mkdir -p /etc/sysconfig",
"echo \"\" > /etc/sysconfig/docker-storage",
"echo \"\" > /etc/sysconfig/docker-storage-setup",
fmt.Sprintf("echo \"%s\" > /etc/docker/daemon.json", strings.ReplaceAll(DockerDaemonJson, "\"", "\\\"")),
fmt.Sprintf("echo \"%s\" > /etc/sysctl.d/k8s.conf", K8SConf),
fmt.Sprintf("echo \"%s\" > /proc/sys/net/ipv4/ip_forward", IpForward),
}
commandString := fmt.Sprintf("'%s'", strings.Join(commands, " && "))

if err := ssh.ExecSSH(connectionString, "sudo", "sh", "-c", commandString); err != nil {
return err
}

// Various other setups.
if err := ssh.ExecSSH(connectionString, "sudo", "sed", "-i", "'/--exec-opt native.cgroupdriver/d'", "/usr/lib/systemd/system/docker.service"); err != nil {
return err
}

// Different versions of kubeabm will install their kubeadm.conf under
// different paths; take the first one found from known paths.
possibleKubeadmConfigPaths := []string{
Expand Down Expand Up @@ -92,9 +72,7 @@ func setupCommonNodeRequirements(log *logrus.Entry, node *Node) error {
daemonsScript := fmt.Sprintf("\"%s\"", strings.Join(
[]string{
"systemctl daemon-reload",
"systemctl enable docker",
"systemctl enable kubelet",
"systemctl restart docker",
"systemctl restart kubelet",
},
" && ",
Expand Down
22 changes: 0 additions & 22 deletions pkg/hope/resources.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
package hope

var DockerDaemonJson = `{
"exec-opts": [
"native.cgroupdriver=systemd"
],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"storage-opts": [
"overlay2.override_kernel_check=true"
]
}
`

var K8SConf = `net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
`

var IpForward = `1
`

var NginxConfig = `user nginx;
worker_processes 1;
Expand Down

0 comments on commit 20b03f9

Please sign in to comment.