2023-12-19 00:17:56 -05:00
|
|
|
package scheduler_k3s
|
|
|
|
|
|
2024-01-17 18:06:18 -05:00
|
|
|
import (
|
2024-01-22 05:12:49 -05:00
|
|
|
"embed"
|
2024-01-17 18:06:18 -05:00
|
|
|
"sync"
|
|
|
|
|
|
2024-01-22 07:18:20 -05:00
|
|
|
certmanagerv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
|
2024-01-17 18:06:18 -05:00
|
|
|
traefikv1alpha1 "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
|
|
|
|
|
appsv1 "k8s.io/api/apps/v1"
|
2024-01-18 05:28:07 -05:00
|
|
|
batchv1 "k8s.io/api/batch/v1"
|
2024-01-17 18:06:18 -05:00
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
|
|
|
"k8s.io/apimachinery/pkg/runtime/serializer"
|
|
|
|
|
kjson "k8s.io/apimachinery/pkg/runtime/serializer/json"
|
|
|
|
|
)
|
|
|
|
|
|
2023-12-19 00:17:56 -05:00
|
|
|
var (
|
2024-01-17 18:06:18 -05:00
|
|
|
// DefaultProperties is a map of all valid k3s properties with corresponding default property values
|
|
|
|
|
DefaultProperties = map[string]string{
|
2024-01-22 08:01:11 -05:00
|
|
|
"deploy-timeout": "",
|
|
|
|
|
"letsencrypt-server": "",
|
2024-01-17 18:06:18 -05:00
|
|
|
"image-pull-secrets": "",
|
2024-01-22 08:01:11 -05:00
|
|
|
"namespace": "",
|
2024-01-17 18:06:18 -05:00
|
|
|
"rollback-on-failure": "",
|
|
|
|
|
}
|
2023-12-19 00:17:56 -05:00
|
|
|
|
2024-01-17 18:06:18 -05:00
|
|
|
// GlobalProperties is a map of all valid global k3s properties
|
2023-12-19 00:17:56 -05:00
|
|
|
GlobalProperties = map[string]bool{
|
2024-01-22 08:01:11 -05:00
|
|
|
"deploy-timeout": true,
|
|
|
|
|
"image-pull-secrets": true,
|
2024-01-22 21:15:21 -05:00
|
|
|
"letsencrypt-server": true,
|
2024-01-22 08:01:11 -05:00
|
|
|
"letsencrypt-email-prod": true,
|
|
|
|
|
"letsencrypt-email-stag": true,
|
|
|
|
|
"namespace": true,
|
|
|
|
|
"network-interface": true,
|
2024-01-30 10:20:12 -05:00
|
|
|
"proxy": true,
|
2024-01-22 08:01:11 -05:00
|
|
|
"rollback-on-failure": true,
|
|
|
|
|
"token": true,
|
2023-12-19 00:17:56 -05:00
|
|
|
}
|
|
|
|
|
)
|
2024-01-17 18:06:18 -05:00
|
|
|
|
|
|
|
|
const KubeConfigPath = "/etc/rancher/k3s/k3s.yaml"
|
|
|
|
|
|
2024-01-18 18:55:03 -05:00
|
|
|
const RegistryConfigPath = "/etc/rancher/k3s/registries.yaml"
|
|
|
|
|
|
2024-02-06 05:16:20 -05:00
|
|
|
const GlobalProcessType = "--global"
|
|
|
|
|
|
2024-01-17 18:06:18 -05:00
|
|
|
var (
|
|
|
|
|
runtimeScheme = runtime.NewScheme()
|
|
|
|
|
codecs = serializer.NewCodecFactory(runtimeScheme)
|
|
|
|
|
deserializer = codecs.UniversalDeserializer()
|
|
|
|
|
jsonSerializer = kjson.NewSerializerWithOptions(kjson.DefaultMetaFactory, runtimeScheme, runtimeScheme, kjson.SerializerOptions{})
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var k8sNativeSchemeOnce sync.Once
|
|
|
|
|
|
2024-01-22 01:25:01 -05:00
|
|
|
type Manifest struct {
|
|
|
|
|
Name string
|
|
|
|
|
Version string
|
|
|
|
|
Path string
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-22 05:12:49 -05:00
|
|
|
var KubernetesManifests = []Manifest{
|
2024-01-22 01:25:01 -05:00
|
|
|
{
|
|
|
|
|
Name: "system-upgrader",
|
|
|
|
|
Version: "0.13.2",
|
2024-01-22 05:12:49 -05:00
|
|
|
Path: "https://github.com/rancher/system-upgrade-controller/releases/download/v0.13.2/system-upgrade-controller.yaml",
|
2024-01-22 01:25:01 -05:00
|
|
|
},
|
2024-01-22 05:12:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type HelmChart struct {
|
|
|
|
|
ChartPath string
|
|
|
|
|
CreateNamespace bool
|
2024-01-30 10:20:12 -05:00
|
|
|
Namespace string
|
2024-01-22 05:12:49 -05:00
|
|
|
Path string
|
2024-01-30 10:20:12 -05:00
|
|
|
ReleaseName string
|
2024-01-22 05:12:49 -05:00
|
|
|
RepoURL string
|
2024-01-30 10:20:12 -05:00
|
|
|
Version string
|
2024-01-22 05:12:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var HelmCharts = []HelmChart{
|
2024-01-22 01:30:41 -05:00
|
|
|
{
|
2024-01-22 05:12:49 -05:00
|
|
|
ChartPath: "cert-manager",
|
|
|
|
|
CreateNamespace: true,
|
|
|
|
|
Namespace: "cert-manager",
|
|
|
|
|
ReleaseName: "cert-manager",
|
|
|
|
|
RepoURL: "https://charts.jetstack.io",
|
|
|
|
|
Version: "v1.13.3",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
ChartPath: "longhorn",
|
|
|
|
|
CreateNamespace: true,
|
|
|
|
|
Namespace: "longhorn-system",
|
|
|
|
|
ReleaseName: "longhorn",
|
|
|
|
|
RepoURL: "https://charts.longhorn.io",
|
|
|
|
|
Version: "1.5.3",
|
2024-01-22 01:30:41 -05:00
|
|
|
},
|
2024-01-24 03:58:39 -05:00
|
|
|
{
|
|
|
|
|
ChartPath: "traefik",
|
|
|
|
|
CreateNamespace: true,
|
|
|
|
|
Namespace: "traefik",
|
|
|
|
|
ReleaseName: "traefik",
|
|
|
|
|
RepoURL: "https://helm.traefik.io/traefik",
|
|
|
|
|
Version: "26.0.0",
|
|
|
|
|
},
|
2024-01-30 10:20:12 -05:00
|
|
|
{
|
|
|
|
|
ChartPath: "ingress-nginx",
|
|
|
|
|
CreateNamespace: true,
|
|
|
|
|
Namespace: "ingress-nginx",
|
|
|
|
|
ReleaseName: "ingress-nginx",
|
|
|
|
|
RepoURL: "https://kubernetes.github.io/ingress-nginx",
|
|
|
|
|
Version: "4.7.5",
|
|
|
|
|
},
|
2024-01-22 01:25:01 -05:00
|
|
|
}
|
|
|
|
|
|
2024-01-22 05:12:49 -05:00
|
|
|
type HelmRepository struct {
|
|
|
|
|
Name string
|
|
|
|
|
URL string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var HelmRepositories = []HelmRepository{
|
|
|
|
|
{
|
|
|
|
|
Name: "jetstack",
|
|
|
|
|
URL: "https://charts.jetstack.io",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Name: "longhorn",
|
|
|
|
|
URL: "https://charts.longhorn.io",
|
|
|
|
|
},
|
2024-01-24 03:58:39 -05:00
|
|
|
{
|
|
|
|
|
Name: "traefik",
|
|
|
|
|
URL: "https://helm.traefik.io/traefik",
|
|
|
|
|
},
|
2024-01-22 05:12:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ServerLabels = map[string]string{
|
|
|
|
|
"svccontroller.k3s.cattle.io/enablelb": "true",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var WorkerLabels = map[string]string{
|
|
|
|
|
"node-role.kubernetes.io/role": "worker",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//go:embed templates/*
|
|
|
|
|
var templates embed.FS
|
|
|
|
|
|
2024-01-17 18:06:18 -05:00
|
|
|
func init() {
|
|
|
|
|
k8sNativeSchemeOnce.Do(func() {
|
|
|
|
|
_ = appsv1.AddToScheme(runtimeScheme)
|
2024-01-18 05:28:07 -05:00
|
|
|
_ = batchv1.AddToScheme(runtimeScheme)
|
2024-01-22 07:18:20 -05:00
|
|
|
_ = certmanagerv1.AddToScheme(runtimeScheme)
|
2024-01-17 18:06:18 -05:00
|
|
|
_ = corev1.AddToScheme(runtimeScheme)
|
|
|
|
|
_ = traefikv1alpha1.AddToScheme(runtimeScheme)
|
|
|
|
|
})
|
|
|
|
|
}
|