mirror of
https://github.com/kairos-io/provider-k3s.git
synced 2025-09-20 09:05:48 +00:00
Merge pull request #75 from kairos-io/sync-release-4.1
Sync release 4.1
This commit is contained in:
@@ -36,8 +36,7 @@ BUILD_GOLANG:
|
|||||||
COPY . ./
|
COPY . ./
|
||||||
ARG BIN
|
ARG BIN
|
||||||
ARG SRC
|
ARG SRC
|
||||||
|
RUN go-build-static.sh -a -o ${BIN} ./${SRC}
|
||||||
RUN go-build.sh -a -o ${BIN} ./${SRC}
|
|
||||||
SAVE ARTIFACT ${BIN} ${BIN} AS LOCAL build/${BIN}
|
SAVE ARTIFACT ${BIN} ${BIN} AS LOCAL build/${BIN}
|
||||||
|
|
||||||
VERSION:
|
VERSION:
|
||||||
|
@@ -9,7 +9,6 @@ type K3sAgentConfig struct {
|
|||||||
KubeletArgs []string `json:"kubelet-arg,omitempty" yaml:"kubelet-arg,omitempty"`
|
KubeletArgs []string `json:"kubelet-arg,omitempty" yaml:"kubelet-arg,omitempty"`
|
||||||
KubeProxyArgs []string `json:"kube-proxy-arg,omitempty" yaml:"kube-proxy-arg,omitempty"`
|
KubeProxyArgs []string `json:"kube-proxy-arg,omitempty" yaml:"kube-proxy-arg,omitempty"`
|
||||||
NodeName string `json:"node-name,omitempty" yaml:"node-name,omitempty"`
|
NodeName string `json:"node-name,omitempty" yaml:"node-name,omitempty"`
|
||||||
NoFlannel bool `json:"no-flannel,omitempty" yaml:"no-flannel,omitempty"`
|
|
||||||
Debug bool `json:"debug,omitempty" yaml:"debug,omitempty"`
|
Debug bool `json:"debug,omitempty" yaml:"debug,omitempty"`
|
||||||
WithNodeId string `json:"with-node-id,omitempty" yaml:"with-node-id,omitempty"`
|
WithNodeId string `json:"with-node-id,omitempty" yaml:"with-node-id,omitempty"`
|
||||||
NodeIP string `json:"node-ip,omitempty" yaml:"node-ip,omitempty"`
|
NodeIP string `json:"node-ip,omitempty" yaml:"node-ip,omitempty"`
|
||||||
|
44
main.go
44
main.go
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -23,7 +24,7 @@ const (
|
|||||||
|
|
||||||
serverSystemName = "k3s"
|
serverSystemName = "k3s"
|
||||||
agentSystemName = "k3s-agent"
|
agentSystemName = "k3s-agent"
|
||||||
K8S_NO_PROXY = ".svc,.svc.cluster,.svc.cluster.local"
|
K8sNoProxy = ".svc,.svc.cluster,.svc.cluster.local"
|
||||||
BootBefore = "boot.before"
|
BootBefore = "boot.before"
|
||||||
LocalImagesPath = "/opt/content/images"
|
LocalImagesPath = "/opt/content/images"
|
||||||
)
|
)
|
||||||
@@ -33,6 +34,9 @@ func clusterProvider(cluster clusterplugin.Cluster) yip.YipConfig {
|
|||||||
Token: cluster.ClusterToken,
|
Token: cluster.ClusterToken,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logrus.Infof("current node role %s", cluster.Role)
|
||||||
|
logrus.Infof("received cluster options %s", cluster.Options)
|
||||||
|
|
||||||
var userOptionConfig string
|
var userOptionConfig string
|
||||||
switch cluster.Role {
|
switch cluster.Role {
|
||||||
case clusterplugin.RoleInit:
|
case clusterplugin.RoleInit:
|
||||||
@@ -45,12 +49,15 @@ func clusterProvider(cluster clusterplugin.Cluster) yip.YipConfig {
|
|||||||
userOptionConfig = cluster.Options
|
userOptionConfig = cluster.Options
|
||||||
case clusterplugin.RoleWorker:
|
case clusterplugin.RoleWorker:
|
||||||
k3sConfig.Server = fmt.Sprintf("https://%s:6443", cluster.ControlPlaneHost)
|
k3sConfig.Server = fmt.Sprintf("https://%s:6443", cluster.ControlPlaneHost)
|
||||||
|
|
||||||
//Data received from upstream contains config for both control plane and worker. Thus, for worker, config is being filtered
|
//Data received from upstream contains config for both control plane and worker. Thus, for worker, config is being filtered
|
||||||
//via unmarshal into agent config.
|
//via unmarshal into agent config.
|
||||||
var agentCfg api.K3sAgentConfig
|
var agentCfg api.K3sAgentConfig
|
||||||
if err := yaml.Unmarshal([]byte(cluster.Options), &agentCfg); err == nil {
|
if err := yaml.Unmarshal([]byte(cluster.Options), &agentCfg); err == nil {
|
||||||
out, _ := yaml.Marshal(agentCfg)
|
out, _ := yaml.Marshal(agentCfg)
|
||||||
userOptionConfig = string(out)
|
userOptionConfig = string(out)
|
||||||
|
} else {
|
||||||
|
logrus.Fatalf("failed to un-marshal cluster options in k3s agent config %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,9 +73,7 @@ func clusterProvider(cluster clusterplugin.Cluster) yip.YipConfig {
|
|||||||
proxyOptions, _ := kyaml.YAMLToJSON([]byte(cluster.Options))
|
proxyOptions, _ := kyaml.YAMLToJSON([]byte(cluster.Options))
|
||||||
options, _ := kyaml.YAMLToJSON(providerConfig.Bytes())
|
options, _ := kyaml.YAMLToJSON(providerConfig.Bytes())
|
||||||
|
|
||||||
logrus.Infof("cluster.Env : %+v", cluster.Env)
|
logrus.Infof("received cluster env %+v", cluster.Env)
|
||||||
proxyValues := proxyEnv(proxyOptions, cluster.Env)
|
|
||||||
logrus.Infof("proxyValues : %s", proxyValues)
|
|
||||||
|
|
||||||
files := []yip.File{
|
files := []yip.File{
|
||||||
{
|
{
|
||||||
@@ -83,7 +88,10 @@ func clusterProvider(cluster clusterplugin.Cluster) yip.YipConfig {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proxyValues := proxyEnv(proxyOptions, cluster.Env)
|
||||||
|
|
||||||
if len(proxyValues) > 0 {
|
if len(proxyValues) > 0 {
|
||||||
|
logrus.Infof("setting proxy values %s", proxyValues)
|
||||||
files = append(files, yip.File{
|
files = append(files, yip.File{
|
||||||
Path: filepath.Join(containerdEnvConfigPath, systemName),
|
Path: filepath.Join(containerdEnvConfigPath, systemName),
|
||||||
Permissions: 0400,
|
Permissions: 0400,
|
||||||
@@ -91,7 +99,7 @@ func clusterProvider(cluster clusterplugin.Cluster) yip.YipConfig {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
stages := []yip.Stage{}
|
var stages []yip.Stage
|
||||||
|
|
||||||
stages = append(stages, yip.Stage{
|
stages = append(stages, yip.Stage{
|
||||||
Name: "Install K3s Configuration Files",
|
Name: "Install K3s Configuration Files",
|
||||||
@@ -108,9 +116,10 @@ func clusterProvider(cluster clusterplugin.Cluster) yip.YipConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
importStage = yip.Stage{
|
importStage = yip.Stage{
|
||||||
|
Name: "Run K3s Import Images Script",
|
||||||
Commands: []string{
|
Commands: []string{
|
||||||
"chmod +x /opt/k3s/scripts/import.sh",
|
"chmod +x /opt/k3s/scripts/import.sh",
|
||||||
fmt.Sprintf("/bin/sh /opt/k3s/scripts/import.sh %s > /var/log/import.log", cluster.LocalImagesPath),
|
fmt.Sprintf("/bin/sh /opt/k3s/scripts/import.sh %s > /var/log/k3s-import-images.log", cluster.LocalImagesPath),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
stages = append(stages, importStage)
|
stages = append(stages, importStage)
|
||||||
@@ -128,15 +137,12 @@ func clusterProvider(cluster clusterplugin.Cluster) yip.YipConfig {
|
|||||||
yip.Stage{
|
yip.Stage{
|
||||||
Name: "Enable Systemd Services",
|
Name: "Enable Systemd Services",
|
||||||
If: "[ -x /bin/systemctl ]",
|
If: "[ -x /bin/systemctl ]",
|
||||||
Systemctl: yip.Systemctl{
|
Commands: []string{
|
||||||
Enable: []string{
|
fmt.Sprintf("systemctl enable %s", systemName),
|
||||||
systemName,
|
fmt.Sprintf("systemctl restart %s", systemName),
|
||||||
},
|
|
||||||
Start: []string{
|
|
||||||
systemName,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
)
|
||||||
|
|
||||||
cfg := yip.YipConfig{
|
cfg := yip.YipConfig{
|
||||||
Name: "K3s Kairos Cluster Provider",
|
Name: "K3s Kairos Cluster Provider",
|
||||||
@@ -156,7 +162,9 @@ func proxyEnv(proxyOptions []byte, proxyMap map[string]string) string {
|
|||||||
httpProxy := proxyMap["HTTP_PROXY"]
|
httpProxy := proxyMap["HTTP_PROXY"]
|
||||||
httpsProxy := proxyMap["HTTPS_PROXY"]
|
httpsProxy := proxyMap["HTTPS_PROXY"]
|
||||||
userNoProxy := proxyMap["NO_PROXY"]
|
userNoProxy := proxyMap["NO_PROXY"]
|
||||||
|
|
||||||
defaultNoProxy := getDefaultNoProxy(proxyOptions)
|
defaultNoProxy := getDefaultNoProxy(proxyOptions)
|
||||||
|
logrus.Infof("setting default no proxy to %s", defaultNoProxy)
|
||||||
|
|
||||||
if len(httpProxy) > 0 {
|
if len(httpProxy) > 0 {
|
||||||
proxy = append(proxy, fmt.Sprintf("HTTP_PROXY=%s", httpProxy))
|
proxy = append(proxy, fmt.Sprintf("HTTP_PROXY=%s", httpProxy))
|
||||||
@@ -192,7 +200,7 @@ func getDefaultNoProxy(proxyOptions []byte) string {
|
|||||||
data := make(map[string]interface{})
|
data := make(map[string]interface{})
|
||||||
err := json.Unmarshal(proxyOptions, &data)
|
err := json.Unmarshal(proxyOptions, &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("error while unmarshalling user options", err)
|
logrus.Fatalf("error while unmarshalling user options %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if data != nil {
|
if data != nil {
|
||||||
@@ -206,7 +214,7 @@ func getDefaultNoProxy(proxyOptions []byte) string {
|
|||||||
noProxy = noProxy + "," + serviceCIDR
|
noProxy = noProxy + "," + serviceCIDR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
noProxy = noProxy + "," + getNodeCIDR() + "," + K8S_NO_PROXY
|
noProxy = noProxy + "," + getNodeCIDR() + "," + K8sNoProxy
|
||||||
|
|
||||||
return noProxy
|
return noProxy
|
||||||
}
|
}
|
||||||
@@ -226,6 +234,12 @@ func getNodeCIDR() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
f, err := os.OpenFile("/var/log/provider-k3s.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
logrus.SetOutput(f)
|
||||||
|
|
||||||
plugin := clusterplugin.ClusterPlugin{
|
plugin := clusterplugin.ClusterPlugin{
|
||||||
Provider: clusterProvider,
|
Provider: clusterProvider,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user