-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
65 lines (51 loc) · 1.95 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"encoding/json"
"github.com/kairos-io/kairos/provider-kubeadm/domain"
"github.com/kairos-io/kairos/provider-kubeadm/stages"
"github.com/kairos-io/kairos/provider-kubeadm/utils"
kyaml "sigs.k8s.io/yaml"
"github.com/kairos-io/kairos-sdk/clusterplugin"
yip "github.com/mudler/yip/pkg/schema"
"github.com/sirupsen/logrus"
)
func main() {
plugin := clusterplugin.ClusterPlugin{
Provider: clusterProvider,
}
if err := plugin.Run(); err != nil {
logrus.Fatal(err)
}
}
func clusterProvider(cluster clusterplugin.Cluster) yip.YipConfig {
var finalStages []yip.Stage
var kubeadmConfig domain.KubeadmConfig
if cluster.Options != "" {
userOptions, _ := kyaml.YAMLToJSON([]byte(cluster.Options))
_ = json.Unmarshal(userOptions, &kubeadmConfig)
}
preStage := []yip.Stage{
stages.GetPreKubeadmProxyStage(kubeadmConfig, cluster),
stages.GetPreKubeadmCommandStages(),
stages.GetPreKubeadmSwapOffDisableStage(),
stages.GetPreKubeadmImportCoreK8sImageStage(),
stages.GetPreKubeadmStoreKubeadmVersionStage(),
}
if cluster.ImportLocalImages {
preStage = append(preStage, stages.GetPreKubeadmImportLocalImageStage(cluster))
}
cluster.ClusterToken = utils.TransformToken(cluster.ClusterToken)
finalStages = append(finalStages, preStage...)
if cluster.Role == clusterplugin.RoleInit {
finalStages = append(finalStages, stages.GetInitYipStages(cluster, kubeadmConfig.InitConfiguration, kubeadmConfig.ClusterConfiguration, kubeadmConfig.KubeletConfiguration)...)
} else if (cluster.Role == clusterplugin.RoleControlPlane) || (cluster.Role == clusterplugin.RoleWorker) {
finalStages = append(finalStages, stages.GetJoinYipStages(cluster, kubeadmConfig.ClusterConfiguration, kubeadmConfig.InitConfiguration, kubeadmConfig.JoinConfiguration, kubeadmConfig.KubeletConfiguration)...)
}
cfg := yip.YipConfig{
Name: "Kubeadm Kairos Cluster Provider",
Stages: map[string][]yip.Stage{
"boot.before": finalStages,
},
}
return cfg
}