refactor: place all required manifests in a single location
This will make it easier for us to apply the installs.
This commit is contained in:
@@ -104,6 +104,31 @@ func (k KubernetesClient) AnnotateNode(ctx context.Context, input AnnotateNodeIn
|
|||||||
return nil
|
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
|
// CreateJobInput contains all the information needed to create a Kubernetes job
|
||||||
type CreateJobInput struct {
|
type CreateJobInput struct {
|
||||||
// Job is the Kubernetes job
|
// Job is the Kubernetes job
|
||||||
|
|||||||
@@ -43,6 +43,25 @@ var (
|
|||||||
|
|
||||||
var k8sNativeSchemeOnce sync.Once
|
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() {
|
func init() {
|
||||||
k8sNativeSchemeOnce.Do(func() {
|
k8sNativeSchemeOnce.Do(func() {
|
||||||
_ = appsv1.AddToScheme(runtimeScheme)
|
_ = appsv1.AddToScheme(runtimeScheme)
|
||||||
|
|||||||
@@ -213,41 +213,18 @@ func CommandInitialize(taintScheduling bool) error {
|
|||||||
return fmt.Errorf("Invalid exit code from setfacl command: %d", registryAclCmd.ExitCode)
|
return fmt.Errorf("Invalid exit code from setfacl command: %d", registryAclCmd.ExitCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
common.LogInfo2Quiet("Installing longhorn")
|
clientset, err := NewKubernetesClient()
|
||||||
longhornCmd, err := common.CallExecCommand(common.ExecCommandInput{
|
for _, manifest := range Manifests {
|
||||||
Command: "kubectl",
|
common.LogInfo2Quiet(fmt.Sprintf("Installing %s@%s", manifest.Name, manifest.Version))
|
||||||
Args: []string{
|
err = clientset.ApplyKubernetesManifest(context.Background(), ApplyKubernetesManifestInput{
|
||||||
"apply",
|
Manifest: manifest.Path,
|
||||||
"-f",
|
})
|
||||||
"https://raw.githubusercontent.com/longhorn/longhorn/v1.4.0/deploy/longhorn.yaml",
|
if err != nil {
|
||||||
},
|
return fmt.Errorf("Unable to apply kubernetes manifest: %w", err)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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")
|
common.LogInfo2Quiet("Labeling node svccontroller.k3s.cattle.io/enablelb=true")
|
||||||
clientset, err := NewKubernetesClient()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Unable to create kubernetes client: %w", err)
|
return fmt.Errorf("Unable to create kubernetes client: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user