From 5ffe62c5c7f8e5b6f0b00aafe3b920ccd0235938 Mon Sep 17 00:00:00 2001 From: eding Date: Wed, 22 Jul 2026 01:20:04 +0200 Subject: [PATCH] fix: configure cilium for talos --- internal/bootstrap/bootstrap.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/internal/bootstrap/bootstrap.go b/internal/bootstrap/bootstrap.go index b8e2b14..a935d8e 100644 --- a/internal/bootstrap/bootstrap.go +++ b/internal/bootstrap/bootstrap.go @@ -41,10 +41,16 @@ func (r Runner) Run() error { func(dir string) error { return ghrepo.WriteManifestsStructure(dir, r.Config.Flux.ManifestsRepo) }, func(dir string) error { clusterDir := filepath.Join(dir, strings.TrimPrefix(r.Config.Flux.ClusterPath, "./")) - if err := copyDir(filepath.Join(cicdTemplateDir, "base"), filepath.Join(dir, "base")); err != nil { + if err := copyDir(filepath.Join(cicdTemplateDir, "base"), filepath.Join(dir, "base"), false); err != nil { return err } - if err := copyDir(filepath.Join(cicdTemplateDir, "clusters", "template"), clusterDir); err != nil { + if err := copyDir(filepath.Join(cicdTemplateDir, "clusters", "template"), clusterDir, false); err != nil { + return err + } + if err := copyDir(filepath.Join(cicdTemplateDir, "base", "cilium"), filepath.Join(dir, "base", "cilium"), true); err != nil { + return err + } + if err := copyDir(filepath.Join(cicdTemplateDir, "base", "cilium-config"), filepath.Join(dir, "base", "cilium-config"), true); err != nil { return err } if err := renderCiliumConfig(filepath.Join(dir, "base", "cilium"), r.Config); err != nil { @@ -162,10 +168,10 @@ func installCilium(dir string, cfg config.Config) error { if err := os.MkdirAll(helmDir, 0755); err != nil { return err } - return utils.RunCommandInDir(dir, "helm", "upgrade", "--install", "cilium", "cilium", "--repo=https://helm.cilium.io", "--version=1.19.6", "--repository-config="+filepath.Join(helmDir, "repositories.yaml"), "--repository-cache="+helmDir, "--namespace=kube-system", "--create-namespace", "--kubeconfig=kubeconfig", "--wait", "--timeout=5m", "--set=kubeProxyReplacement=true", "--set=ipam.mode=kubernetes", "--set=k8sServiceHost="+cfg.Talos.KubeconfigEndpoint, "--set=k8sServicePort=6443", "--set=gatewayAPI.enabled=true", "--set=l2announcements.enabled=true") + return utils.RunCommandInDir(dir, "helm", "upgrade", "--install", "cilium", "cilium", "--repo=https://helm.cilium.io", "--version=1.19.6", "--repository-config="+filepath.Join(helmDir, "repositories.yaml"), "--repository-cache="+helmDir, "--namespace=kube-system", "--create-namespace", "--kubeconfig=kubeconfig", "--wait", "--timeout=5m", "--set=kubeProxyReplacement=true", "--set=ipam.mode=kubernetes", "--set=k8sServiceHost=localhost", "--set=k8sServicePort=7445", "--set=cgroup.autoMount.enabled=false", "--set=cgroup.hostRoot=/sys/fs/cgroup", "--set=bpf.hostLegacyRouting=true", "--set=securityContext.capabilities.ciliumAgent={CHOWN,KILL,NET_ADMIN,NET_RAW,IPC_LOCK,SYS_ADMIN,SYS_RESOURCE,DAC_OVERRIDE,FOWNER,SETGID,SETUID}", "--set=securityContext.capabilities.cleanCiliumState={NET_ADMIN,SYS_ADMIN,SYS_RESOURCE}", "--set=gatewayAPI.enabled=true", "--set=l2announcements.enabled=true") } -func copyDir(source, destination string) error { +func copyDir(source, destination string, overwrite bool) error { return filepath.Walk(source, func(path string, info os.FileInfo, err error) error { if err != nil { return err @@ -178,7 +184,7 @@ func copyDir(source, destination string) error { if info.IsDir() { return os.MkdirAll(target, 0755) } - if _, err := os.Stat(target); err == nil { + if _, err := os.Stat(target); err == nil && !overwrite { return nil } input, err := os.Open(path) @@ -186,7 +192,11 @@ func copyDir(source, destination string) error { return err } defer input.Close() - output, err := os.OpenFile(target, os.O_WRONLY|os.O_CREATE|os.O_EXCL, info.Mode()) + flags := os.O_WRONLY | os.O_CREATE | os.O_EXCL + if overwrite { + flags = os.O_WRONLY | os.O_CREATE | os.O_TRUNC + } + output, err := os.OpenFile(target, flags, info.Mode()) if err != nil { return err }