代码拉取完成,页面将自动刷新
// +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...)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。