Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add runtime classes hook and runtimes chart #7382

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions pkg/rke2/rc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ import (
"sync"

"github.com/k3s-io/k3s/pkg/cli/cmds"
"github.com/k3s-io/k3s/pkg/util"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)

const runtimeClassesChart = "rke2-runtimeclasses"
const (
runtimeClassesChart = "rke2-runtimeclasses"
namespace = "kube-system"
helm = "Helm"
helmReleaseName = "meta.helm.sh/release-name"
helmManageBy = "app.kubernetes.io/managed-by"
helmReleaseNamespace = "meta.helm.sh/release-namespace"
vitorsavian marked this conversation as resolved.
Show resolved Hide resolved
)

var runtimes = map[string]bool{
"nvidia": true,
Expand All @@ -26,12 +32,7 @@ func setRuntimes() cmds.StartupHook {
<-args.APIServerReady
logrus.Info("Setting runtimes")

config, err := clientcmd.BuildConfigFromFlags("", args.KubeConfigSupervisor)
if err != nil {
logrus.Fatalf("runtimes: new k8s restConfig: %v", err)
}

client, err := kubernetes.NewForConfig(config)
client, err := util.GetClientSet(args.KubeConfigSupervisor)
if err != nil {
logrus.Fatalf("runtimes: new k8s client: %v", err)
}
Expand All @@ -51,25 +52,23 @@ func setRuntimes() cmds.StartupHook {
}

if c.Labels == nil {
labels := make(map[string]string)
c.SetLabels(labels)
c.Labels = map[string]string{}
}

if managedBy, ok := c.Labels["app.kubernetes.io/managed-by"]; !ok || managedBy != "Helm" {
c.Labels["app.kubernetes.io/managed-by"] = "Helm"
if managedBy, ok := c.Labels[helmManageBy]; !ok || managedBy != helm {
c.Labels[helmManageBy] = helm
}

if c.Annotations == nil {
annotations := make(map[string]string)
c.SetAnnotations(annotations)
c.Annotations = map[string]string{}
}

if releaseName, ok := c.Annotations["meta.helm.sh/release-name"]; !ok || releaseName != runtimeClassesChart {
c.Annotations["meta.helm.sh/release-name"] = runtimeClassesChart
if releaseName, ok := c.Annotations[helmReleaseName]; !ok || releaseName != runtimeClassesChart {
c.Annotations[helmReleaseName] = runtimeClassesChart
}

if namespace, ok := c.Annotations["meta.helm.sh/release-namespace"]; !ok || namespace != "kube-system" {
c.Annotations["meta.helm.sh/release-namespace"] = "kube-system"
if ns, ok := c.Annotations[helmReleaseNamespace]; !ok || ns != namespace {
c.Annotations[helmReleaseNamespace] = namespace
}

_, err = rcClient.Update(context.Background(), &c, metav1.UpdateOptions{})
Expand Down
Loading