Initial upgrade flow for control-plane
This commit is contained in:
@@ -5,9 +5,14 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
system "example.com/monok8s/pkg/system"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
const (
|
||||
storageConfPath = "/etc/containers/storage.conf"
|
||||
)
|
||||
|
||||
func ConfigureDefaultCNI(ctx context.Context, n *NodeContext) error {
|
||||
@@ -60,3 +65,56 @@ func ConfigureDefaultCNI(ctx context.Context, n *NodeContext) error {
|
||||
func StartCRIO(ctx context.Context, n *NodeContext) error {
|
||||
return system.EnsureServiceRunning(ctx, n.SystemRunner, "crio")
|
||||
}
|
||||
|
||||
func RestartCRIO(ctx context.Context, nctx *NodeContext) error {
|
||||
_, err := nctx.SystemRunner.RunWithOptions(
|
||||
ctx,
|
||||
"rc-service",
|
||||
[]string{"crio", "restart"},
|
||||
system.RunOptions{
|
||||
Timeout: 60 * time.Second,
|
||||
OnStdoutLine: func(line string) { klog.Infof("[crio] %s", line) },
|
||||
OnStderrLine: func(line string) { klog.Infof("[crio] %s", line) },
|
||||
},
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
func writeCRIOStorageConfig(ctx context.Context, nctx *NodeContext, altSource string) error {
|
||||
|
||||
additionalStores := []string{
|
||||
"/usr/lib/monok8s/imagestore",
|
||||
}
|
||||
|
||||
if altSource != "" {
|
||||
additionalStores = append(additionalStores, altSource)
|
||||
}
|
||||
|
||||
var b strings.Builder
|
||||
b.WriteString("# Generated File. DO NOT MODIFY.\n")
|
||||
b.WriteString("[storage]\n")
|
||||
b.WriteString("driver = \"overlay\"\n")
|
||||
b.WriteString("runroot = \"/run/containers/storage\"\n")
|
||||
b.WriteString("graphroot = \"/var/lib/containers/storage\"\n\n")
|
||||
b.WriteString("[storage.options]\n")
|
||||
b.WriteString("additionalimagestores = [\n")
|
||||
for _, s := range additionalStores {
|
||||
b.WriteString(fmt.Sprintf(" %q,\n", s))
|
||||
}
|
||||
b.WriteString("]\n")
|
||||
|
||||
content := b.String()
|
||||
|
||||
path := storageConfPath
|
||||
tmp := path + ".tmp"
|
||||
if err := os.WriteFile(tmp, []byte(content), 0o644); err != nil {
|
||||
return fmt.Errorf("write temp storage.conf: %w", err)
|
||||
}
|
||||
if err := os.Rename(tmp, path); err != nil {
|
||||
_ = os.Remove(tmp)
|
||||
return fmt.Errorf("replace storage.conf: %w", err)
|
||||
}
|
||||
|
||||
klog.InfoS("wrote CRI-O storage config", "path", path, "additionalImageStores", additionalStores)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user