diff --git a/plugins/scheduler-k3s/k8s.go b/plugins/scheduler-k3s/k8s.go index fa05e8fc7..413309f95 100644 --- a/plugins/scheduler-k3s/k8s.go +++ b/plugins/scheduler-k3s/k8s.go @@ -104,6 +104,31 @@ func (k KubernetesClient) AnnotateNode(ctx context.Context, input AnnotateNodeIn return nil } +type ApplyKubernetesManifestInput struct { + // Manifest is the path to the Kubernetes manifest + Manifest string +} + +func (k KubernetesClient) ApplyKubernetesManifest(ctx context.Context, input ApplyKubernetesManifestInput) error { + upgradeCmd, err := common.CallExecCommand(common.ExecCommandInput{ + Command: "kubectl", + Args: []string{ + "apply", + "-f", + input.Manifest, + }, + StreamStdio: true, + }) + if err != nil { + return fmt.Errorf("Unable to call kubectl command: %w", err) + } + if upgradeCmd.ExitCode != 0 { + return fmt.Errorf("Invalid exit code from kubectl command: %d", upgradeCmd.ExitCode) + } + + return nil +} + // CreateJobInput contains all the information needed to create a Kubernetes job type CreateJobInput struct { // Job is the Kubernetes job diff --git a/plugins/scheduler-k3s/scheduler_k3s.go b/plugins/scheduler-k3s/scheduler_k3s.go index 715d37fac..37228e64e 100644 --- a/plugins/scheduler-k3s/scheduler_k3s.go +++ b/plugins/scheduler-k3s/scheduler_k3s.go @@ -43,6 +43,25 @@ var ( var k8sNativeSchemeOnce sync.Once +type Manifest struct { + Name string + Version string + Path string +} + +var Manifests = []Manifest{ + { + Name: "longhorn", + Version: "1.5.3", + Path: "https://raw.githubusercontent.com/longhorn/longhorn/v1.5.3/deploy/longhorn.yaml", + }, + { + Name: "system-upgrader", + Version: "0.13.2", + Path: "https://github.com/rancher/system-upgrade-controller/releases/v0.13.2/download/system-upgrade-controller.yaml", + }, +} + func init() { k8sNativeSchemeOnce.Do(func() { _ = appsv1.AddToScheme(runtimeScheme) diff --git a/plugins/scheduler-k3s/subcommands.go b/plugins/scheduler-k3s/subcommands.go index 321505aba..1e94e4311 100644 --- a/plugins/scheduler-k3s/subcommands.go +++ b/plugins/scheduler-k3s/subcommands.go @@ -213,41 +213,18 @@ func CommandInitialize(taintScheduling bool) error { return fmt.Errorf("Invalid exit code from setfacl command: %d", registryAclCmd.ExitCode) } - common.LogInfo2Quiet("Installing longhorn") - longhornCmd, err := common.CallExecCommand(common.ExecCommandInput{ - Command: "kubectl", - Args: []string{ - "apply", - "-f", - "https://raw.githubusercontent.com/longhorn/longhorn/v1.4.0/deploy/longhorn.yaml", - }, - StreamStdio: true, - }) - if err != nil { - return fmt.Errorf("Unable to call kubectl command: %w", err) - } - if longhornCmd.ExitCode != 0 { - return fmt.Errorf("Invalid exit code from kubectl command: %d", longhornCmd.ExitCode) + clientset, err := NewKubernetesClient() + for _, manifest := range Manifests { + common.LogInfo2Quiet(fmt.Sprintf("Installing %s@%s", manifest.Name, manifest.Version)) + err = clientset.ApplyKubernetesManifest(context.Background(), ApplyKubernetesManifestInput{ + Manifest: manifest.Path, + }) + if err != nil { + return fmt.Errorf("Unable to apply kubernetes manifest: %w", err) + } } - common.LogInfo2Quiet("Installing k3s automatic upgrader") - upgradeCmd, err := common.CallExecCommand(common.ExecCommandInput{ - Command: "kubectl", - Args: []string{ - "apply", - "-f", - "https://github.com/rancher/system-upgrade-controller/releases/latest/download/system-upgrade-controller.yaml", - }, - StreamStdio: true, - }) - if err != nil { - return fmt.Errorf("Unable to call kubectl command: %w", err) - } - if upgradeCmd.ExitCode != 0 { - return fmt.Errorf("Invalid exit code from kubectl command: %d", upgradeCmd.ExitCode) - } common.LogInfo2Quiet("Labeling node svccontroller.k3s.cattle.io/enablelb=true") - clientset, err := NewKubernetesClient() if err != nil { return fmt.Errorf("Unable to create kubernetes client: %w", err) }