36 Star 396 Fork 71

GVPrancher / rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
execute.go 1.74 KB
一键复制 编辑 原始数据 按行查看 历史
// +build !windows
package rkeworker
import (
"bytes"
"context"
"encoding/base64"
"io/ioutil"
"os"
"path/filepath"
"strings"
"github.com/rancher/norman/types"
"github.com/rancher/rancher/pkg/rkecerts"
)
func ExecutePlan(ctx context.Context, nodeConfig *NodeConfig, writeCertOnly bool) error {
var bundleChanged bool
if nodeConfig.Certs != "" {
bundle, err := rkecerts.Unmarshal(nodeConfig.Certs)
if err != nil {
return err
}
bundleChanged = bundle.Changed()
if err := bundle.Explode(); err != nil {
return err
}
}
f := fileWriter{}
for _, file := range nodeConfig.Files {
f.write(file.Name, file.Contents)
}
if writeCertOnly {
return nil
}
for name, process := range nodeConfig.Processes {
if strings.Contains(name, "sidekick") || strings.Contains(name, "share-mnt") {
if err := runProcess(ctx, name, process, false, false); err != nil {
return err
}
}
}
for name, process := range nodeConfig.Processes {
if !strings.Contains(name, "sidekick") {
if err := runProcess(ctx, name, process, true, bundleChanged); err != nil {
return err
}
}
}
return nil
}
type fileWriter struct {
errs []error
}
func (f *fileWriter) write(path string, base64Content string) {
if path == "" {
return
}
content, err := base64.StdEncoding.DecodeString(base64Content)
if err != nil {
f.errs = append(f.errs, err)
return
}
existing, err := ioutil.ReadFile(path)
if err == nil && bytes.Equal(existing, content) {
return
}
dir := filepath.Dir(path)
if err := os.MkdirAll(dir, 0700); err != nil {
f.errs = append(f.errs, err)
}
if err := ioutil.WriteFile(path, content, 0600); err != nil {
f.errs = append(f.errs, err)
}
}
func (f *fileWriter) err() error {
return types.NewErrors(f.errs...)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.4-rc22

搜索帮助

344bd9b3 5694891 D2dac590 5694891