|
| 1 | +/* |
| 2 | +Copyright 2024 The Kubernetes Authors All rights reserved. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package main |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + "os" |
| 22 | + "os/exec" |
| 23 | + "path/filepath" |
| 24 | + "regexp" |
| 25 | + "strings" |
| 26 | + "time" |
| 27 | + |
| 28 | + "k8s.io/klog/v2" |
| 29 | + "k8s.io/minikube/hack/update" |
| 30 | +) |
| 31 | + |
| 32 | +func main() { |
| 33 | + if _, err := exec.LookPath("helm"); err != nil { |
| 34 | + klog.Fatal("helm not found on system, either install or add to PATH") |
| 35 | + } |
| 36 | + |
| 37 | + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) |
| 38 | + defer cancel() |
| 39 | + |
| 40 | + stable, _, _, err := update.GHReleases(ctx, "cilium", "cilium") |
| 41 | + if err != nil { |
| 42 | + klog.Fatalf("Unable to get stable version: %v", err) |
| 43 | + } |
| 44 | + version := strings.TrimPrefix(stable.Tag, "v") |
| 45 | + |
| 46 | + // Add the cilium repo to helm |
| 47 | + if err := exec.Command("helm", "repo", "add", "cilium", "https://helm.cilium.io/").Run(); err != nil { |
| 48 | + klog.Fatal(err) |
| 49 | + } |
| 50 | + |
| 51 | + // Generate the cilium YAML |
| 52 | + yamlBytes, err := exec.Command("helm", "template", "cilium", "cilium/cilium", "--version", version, "--namespace", "kube-system").Output() |
| 53 | + if err != nil { |
| 54 | + klog.Fatal(err) |
| 55 | + } |
| 56 | + yaml := string(yamlBytes) |
| 57 | + |
| 58 | + // Remove the cilium/templates/cilium-ca-secret.yaml section |
| 59 | + re := regexp.MustCompile(`# Source: cilium\/templates\/cilium-ca-secret\.yaml(\n.*?)+---\n`) |
| 60 | + yaml = re.ReplaceAllString(yaml, "") |
| 61 | + |
| 62 | + // Remove the cilium/templates/hubble/tls-helm/server-secret.yaml section |
| 63 | + re = regexp.MustCompile(`# Source: cilium\/templates\/hubble\/tls-helm\/server-secret\.yaml(\n.*?)+---\n`) |
| 64 | + yaml = re.ReplaceAllString(yaml, "") |
| 65 | + |
| 66 | + // Replace `cluster-pool-ipv4-cidr` with PodSubnet template |
| 67 | + re = regexp.MustCompile(`10\.0\.0\.0\/8`) |
| 68 | + yaml = re.ReplaceAllString(yaml, "{{ .PodSubnet }}") |
| 69 | + |
| 70 | + // Change replicas to 1 |
| 71 | + re = regexp.MustCompile(`replicas:.+`) |
| 72 | + yaml = re.ReplaceAllString(yaml, "replicas: 1") |
| 73 | + |
| 74 | + filename := filepath.Join(update.FSRoot, "pkg/minikube/cni/cilium.yaml") |
| 75 | + if err := os.WriteFile(filename, []byte(yaml), 0644); err != nil { |
| 76 | + klog.Fatal(err) |
| 77 | + } |
| 78 | +} |
0 commit comments