diff --git a/.run/provs-server.run.xml b/.run/provs-server.run.xml new file mode 100644 index 0000000..3d94520 --- /dev/null +++ b/.run/provs-server.run.xml @@ -0,0 +1,11 @@ + + + + \ No newline at end of file diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/K3s.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/K3s.kt index 2b153e2..e11f1f4 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/K3s.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/K3s.kt @@ -2,8 +2,17 @@ package org.domaindrivenarchitecture.provs.server.infrastructure import org.domaindrivenarchitecture.provs.framework.core.Prov import org.domaindrivenarchitecture.provs.framework.core.ProvResult -import org.domaindrivenarchitecture.provs.framework.core.echoCommandForText -import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstall +import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createDirs +import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createFileFromResourceTemplate +import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.fileExists + +// TODO: jem - 2022.01.24 - these are global vars without scope / ns ! +val k3sConfigFile = "/etc/rancher/k3s/config.yaml" +val k3sResourcePath = "org/domaindrivenarchitecture/provs/infrastructure/k3s/" + +fun Prov.testConfigExists(): Boolean { + return fileExists(k3sConfigFile) +} /** * Installs a k3s server. @@ -11,30 +20,52 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInsta * If tlsHost is specified, then tls (if configured) also applies to the specified host. */ fun Prov.provisionK3sInfra(docker: Boolean = false, tlsHost: String? = null, options: String? = null) = task { - val tlsSanOption = tlsHost?.let { "--tls-san ${it}" } ?: "" + if (!testConfigExists()) { + createDirs("/etc/rancher/k3s/", sudo = true) + createFileFromResourceTemplate( + k3sConfigFile, + "config.yaml.template", + k3sResourcePath, + mapOf("loopback_ipv4" to "192.168.5.1", "loopback_ipv6" to "fc00::5:1", + "node_ipv4" to "159.69.176.151", "node_ipv6" to "2a01:4f8:c010:2f72::1"), + "644", + sudo = true + ) + // TODO: verify the download ! + //cmd("curl -sfL https://get.k3s.io | sh -") - val k3sAllOptions = if (tlsHost == null && options == null) - "" - else - "INSTALL_K3S_EXEC=\"$tlsSanOption ${options ?: ""}\"" + /* - aptInstall("curl") - if (!chk("k3s -version")) { - if (docker) { - // might not work if docker already installed - sh(""" + org/domaindrivenarchitecture/provs/infrastructure/k3s/config.yaml.template.template + + val tlsSanOption = tlsHost?.let { "--tls-san ${it}" } ?: "" + + val k3sAllOptions = if (tlsHost == null && options == null) + "" + else + "INSTALL_K3S_EXEC=\"$tlsSanOption ${options ?: ""}\"" + + aptInstall("curl") + if (!chk("k3s -version")) { + if (docker) { + // might not work if docker already installed + sh( + """ curl https://releases.rancher.com/install-docker/19.03.sh | sh curl -sfL https://get.k3s.io | $k3sAllOptions sh -s - --docker - """.trimIndent()) - } else { - cmd("curl -sfL https://get.k3s.io | $k3sAllOptions sh -") + """.trimIndent() + ) + } else { + cmd("curl -sfL https://get.k3s.io | $k3sAllOptions sh -") + } } + */ } else { ProvResult(true) } } - +/* @Suppress("unused") fun Prov.uninstallK3sServer() = task { cmd("sudo /usr/local/bin/k3s-uninstall.sh") @@ -44,3 +75,4 @@ fun Prov.uninstallK3sServer() = task { fun Prov.applyK3sConfig(configAsYaml: String) = task { cmd(echoCommandForText(configAsYaml) + " | sudo k3s kubectl apply -f -") } +*/ \ No newline at end of file diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/network.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/network.kt index 6cdb57b..5aac5cc 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/network.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/network.kt @@ -18,7 +18,7 @@ fun Prov.provisionNetwork() = task { loopbackFile, "99-loopback.yaml.template", resourcePath, - mapOf("ip" to "192.168.5.1/32"), + mapOf("loopback_ipv4" to "192.168.5.1/32", "loopback_ipv6" to "fc00::5:1/128"), "644", sudo = true ) diff --git a/src/main/resources/org/domaindrivenarchitecture/provs/infrastructure/k3s/config.yaml.template b/src/main/resources/org/domaindrivenarchitecture/provs/infrastructure/k3s/config.yaml.template new file mode 100644 index 0000000..1d1fe98 --- /dev/null +++ b/src/main/resources/org/domaindrivenarchitecture/provs/infrastructure/k3s/config.yaml.template @@ -0,0 +1,14 @@ +etcd-disable-snapshots: true +default-local-storage-path: /var +flannel-backend: none +disable-network-policy: true +cluster-cidr: + - 10.42.0.0/16 + - fd42::/48 +service-cidr: + - 10.43.0.0/16 + - fd43::/112 +node-ip: + - ${node_ipv4} + - ${node_ipv6} +bind-address: ${loopback_ipv4} \ No newline at end of file diff --git a/src/main/resources/org/domaindrivenarchitecture/provs/infrastructure/network/99-loopback.yaml.template b/src/main/resources/org/domaindrivenarchitecture/provs/infrastructure/network/99-loopback.yaml.template index 31314d9..a1359a9 100644 --- a/src/main/resources/org/domaindrivenarchitecture/provs/infrastructure/network/99-loopback.yaml.template +++ b/src/main/resources/org/domaindrivenarchitecture/provs/infrastructure/network/99-loopback.yaml.template @@ -6,4 +6,5 @@ network: match: name: lo addresses: - - $ip + - ${loopback_ipv4} + - ${loopback_ipv6}