package common import ( "flag" "os" "strings" "github.com/hashicorp/go-version" "github.com/peterbourgon/ff/v3" ) const ( MountPath = "/boot" ArtefactsPath = MountPath + "/versions" ArtefactsTempPath = ArtefactsPath + "/.tmp" LiveBootPath = MountPath + "/live" ScriptsPath = MountPath + "/patching" ScriptsTempPath = ScriptsPath + "/.tmp" EnvFilePath = "/data/patching.env" LegacyScriptsPath = MountPath + "/upgrade" PatchsetMount = "/mnt/patchset" RebootPath = "/mnt/run/reboot-required" BootFiles = "boot/" ScriptFiles = "patching/" KiB = int64(1024) MiB = KiB * KiB // Patch Ordering VersionLabel = "feature.node.kubernetes.io/ien-version" ControlPlaneLabel = "node-role.kubernetes.io/control-plane" ) type Config struct { MountPath string ArtefactsPath string ArtefactsTempPath string LiveBootPath string ScriptsPath string ScriptsTempPath string EnvFilePath string LegacyScriptsPath string BootFiles string ScriptFiles string PatchsetMount string RebootPath string } func NewConfig() (Config, error) { fs := flag.NewFlagSet("patching", flag.ExitOnError) cfg := Config{} envFilePath, err := getEnvPath() if err != nil { return Config{}, err } cfg.MountPath = *fs.String("mount-path", MountPath, "Where the container boot volume is mounted") cfg.ArtefactsPath = *fs.String("artefacts-path", ArtefactsPath, "Where artefacts are created as part of the patching process") cfg.ArtefactsTempPath = *fs.String("artefacts-temp-path", ArtefactsTempPath, "The temporary location for artefacts while extracting files") cfg.LiveBootPath = *fs.String("live-boot-path", LiveBootPath, "Contains 'filesystem.squashfs'") cfg.ScriptsPath = *fs.String("scripts-path", ScriptsPath, "Contains patching scripts and configuration") cfg.ScriptsTempPath = *fs.String("scripts-temp-path", ScriptsTempPath, "The temporary location for patching scripts while extracting files") cfg.EnvFilePath = *fs.String("env-file-path", envFilePath, "Contains 'patching.env'") cfg.LegacyScriptsPath = *fs.String("legacy-scripts-path", LegacyScriptsPath, "The location used in legacy versions, before '/upgrade' was renamed to '/patching'") cfg.BootFiles = BootFiles cfg.ScriptFiles = ScriptFiles cfg.PatchsetMount = PatchsetMount cfg.RebootPath = RebootPath if err := ff.Parse(fs, os.Args[1:], ff.WithEnvVarNoPrefix()); err != nil { return Config{}, err } return cfg, nil } func ReadCurrentVer() (string, error) { currentVerBytes, err := os.ReadFile("/mnt/version") if err != nil { return "", err } currentVer := strings.TrimSpace(string(currentVerBytes)) return currentVer, nil } func getEnvPath() (string, error) { ver, err := ReadCurrentVer() if err != nil { return "", err } bwcVer, _ := version.NewVersion("v1.14.0") currentVer, err := version.NewVersion(ver) if err != nil { return "", err } if currentVer.LessThan(bwcVer) { return "/boot/patching/patching.env", nil } return EnvFilePath, nil }