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-02-28 16:15:20 -05:00
|
|
|
kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1"
|
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": "",
|
2025-07-08 20:52:26 -04:00
|
|
|
"kustomize-root-path": "",
|
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": "",
|
2025-03-06 22:48:49 -05:00
|
|
|
"shm-size": "",
|
2024-01-17 18:06:18 -05:00
|
|
|
}
|
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-30 10:57:24 -05:00
|
|
|
"ingress-class": true,
|
2024-02-14 03:50:15 -05:00
|
|
|
"kube-context": true,
|
|
|
|
|
"kubeconfig-path": true,
|
2025-07-08 20:52:26 -04:00
|
|
|
"kustomize-root-path": 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,
|
|
|
|
|
"rollback-on-failure": true,
|
2025-03-06 22:48:49 -05:00
|
|
|
"shm-size": true,
|
2024-01-22 08:01:11 -05:00
|
|
|
"token": true,
|
2023-12-19 00:17:56 -05:00
|
|
|
}
|
|
|
|
|
)
|
2024-01-17 18:06:18 -05:00
|
|
|
|
2024-03-12 23:25:46 -04:00
|
|
|
const DefaultIngressClass = "nginx"
|
2024-01-30 10:57:24 -05:00
|
|
|
const GlobalProcessType = "--global"
|
2024-01-17 18:06:18 -05:00
|
|
|
const KubeConfigPath = "/etc/rancher/k3s/k3s.yaml"
|
2024-02-14 03:50:15 -05:00
|
|
|
const DefaultKubeContext = ""
|
2024-02-28 11:44:02 -05:00
|
|
|
const TriggerAuthPropertyPrefix = "trigger-auth."
|
2024-01-18 18:55:03 -05:00
|
|
|
|
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",
|
2024-03-12 21:07:19 -04:00
|
|
|
Version: "4.10.0",
|
2024-01-30 10:20:12 -05:00
|
|
|
},
|
2024-02-25 20:34:29 -05:00
|
|
|
{
|
|
|
|
|
ChartPath: "keda",
|
|
|
|
|
CreateNamespace: true,
|
|
|
|
|
Namespace: "keda",
|
|
|
|
|
ReleaseName: "keda",
|
|
|
|
|
RepoURL: "https://kedacore.github.io/charts",
|
2024-12-10 21:47:33 -05:00
|
|
|
Version: "2.16.0",
|
2024-02-25 20:34:29 -05:00
|
|
|
},
|
2024-11-13 02:15:47 -05:00
|
|
|
{
|
|
|
|
|
ChartPath: "keda-add-ons-http",
|
|
|
|
|
CreateNamespace: true,
|
|
|
|
|
Namespace: "keda",
|
|
|
|
|
ReleaseName: "keda-add-ons-http",
|
|
|
|
|
RepoURL: "https://kedacore.github.io/charts",
|
|
|
|
|
Version: "0.8.0",
|
|
|
|
|
},
|
2025-04-14 04:35:21 -04:00
|
|
|
{
|
|
|
|
|
ChartPath: "vector",
|
|
|
|
|
CreateNamespace: true,
|
|
|
|
|
Namespace: "vector",
|
|
|
|
|
ReleaseName: "vector",
|
|
|
|
|
RepoURL: "https://helm.vector.dev",
|
|
|
|
|
Version: "0.42.0",
|
|
|
|
|
},
|
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
|
|
|
}
|
|
|
|
|
|
2025-11-20 02:18:55 -05:00
|
|
|
// NodeProfile is a profile for a node in the k3s cluster
|
|
|
|
|
type NodeProfile struct {
|
|
|
|
|
// Name is the name of the node profile
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
// Role is the role of the node
|
|
|
|
|
Role string `json:"role"`
|
|
|
|
|
// AllowUknownHosts is whether to allow unknown hosts
|
|
|
|
|
AllowUknownHosts bool `json:"allow_unknown_hosts,omitempty"`
|
|
|
|
|
// TaintScheduling is whether to taint the node for scheduling
|
|
|
|
|
TaintScheduling bool `json:"taint_scheduling,omitempty"`
|
|
|
|
|
// KubeletArgs is a list of kubelet arguments
|
|
|
|
|
KubeletArgs []string `json:"kubelet_args,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ServerLabels are the labels for a server node
|
2024-01-22 05:12:49 -05:00
|
|
|
var ServerLabels = map[string]string{
|
|
|
|
|
"svccontroller.k3s.cattle.io/enablelb": "true",
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-20 02:18:55 -05:00
|
|
|
// WorkerLabels are the labels for a worker node
|
2024-01-22 05:12:49 -05:00
|
|
|
var WorkerLabels = map[string]string{
|
2024-02-14 21:52:08 -05:00
|
|
|
"node-role.kubernetes.io/worker": "worker",
|
2024-01-22 05:12:49 -05:00
|
|
|
}
|
|
|
|
|
|
2024-02-28 14:40:43 -05:00
|
|
|
//go:embed all:templates
|
2024-01-22 05:12:49 -05:00
|
|
|
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)
|
2024-02-28 16:15:20 -05:00
|
|
|
_ = kedav1alpha1.AddToScheme(runtimeScheme)
|
2024-01-17 18:06:18 -05:00
|
|
|
})
|
|
|
|
|
}
|