Skip to content

Commit

Permalink
Add node pressure eviction
Browse files Browse the repository at this point in the history
  • Loading branch information
bsenel committed Jan 26, 2022
1 parent 6b33849 commit 1b8c999
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 15 deletions.
19 changes: 12 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@ package main

import (
"fmt"
"github.com/EdgeNet-project/node/pkg/cluster"
"github.com/EdgeNet-project/node/pkg/network"
"github.com/EdgeNet-project/node/pkg/platforms"
"github.com/EdgeNet-project/node/pkg/utils"
"github.com/thanhpk/randstr"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"gopkg.in/yaml.v3"
"log"
"math/rand"
"net"
"os"
"path/filepath"
"strings"
"time"

"github.com/EdgeNet-project/node/pkg/cluster"
"github.com/EdgeNet-project/node/pkg/network"
"github.com/EdgeNet-project/node/pkg/platforms"
"github.com/EdgeNet-project/node/pkg/utils"
"github.com/thanhpk/randstr"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"gopkg.in/yaml.v3"
)

const defaultKubeconfigURL = "https://raw.githubusercontent.com/EdgeNet-project/edgenet/master/configs/public.cfg"
Expand Down Expand Up @@ -238,6 +239,10 @@ func main() {
network.SetKubeletNodeIP(kubeletEnvFileDebian, nodeIP)
network.SetKubeletNodeIP(kubeletEnvFileRedHat, nodeIP)

log.Println("step=set-node-pressure-eviction")
cluster.SetKubeletNodePressureEviction(kubeletEnvFileDebian)
cluster.SetKubeletNodePressureEviction(kubeletEnvFileRedHat)

log.Println("step=join-cluster")
cluster.Join(defaultKubeconfigURL, hostname, nodeIP)
}
39 changes: 34 additions & 5 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@ package cluster

import (
"context"
"io/ioutil"
"log"
"net"
"net/http"
"strings"

"github.com/EdgeNet-project/edgenet/pkg/apis/core/v1alpha"
v1alpha2 "github.com/EdgeNet-project/edgenet/pkg/apis/networking/v1alpha"
"github.com/EdgeNet-project/edgenet/pkg/generated/clientset/versioned"
"github.com/EdgeNet-project/node/pkg/utils"
"io/ioutil"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"log"
"net"
"net/http"
"strings"
)

func check(err error) {
Expand Down Expand Up @@ -133,3 +134,31 @@ func Join(configURL string, hostname string, externalIP net.IP) {
log.Print("node-contribution-status=created")
}
}

// SetKubeletNodePressureEviction sets the eviction thresholds, system reserved resources and minimum reclaim in the kubelet configuration.
func SetKubeletNodePressureEviction(kubeletEnvFile string) {
if dat, err := ioutil.ReadFile(kubeletEnvFile); err == nil {
// TODO: Set these parameters via the config file specified by the Kubelet's --config flag.
// https://kubernetes.io/docs/tasks/administer-cluster/kubelet-config-file/
// TODO: Dynamically assign system reserved memory as 10% (X%) of the capacity.
kubeletConfig := string(dat)

splitFn := func(c rune) bool {
return c == '"'
}
split := strings.FieldsFunc(kubeletConfig, splitFn)

parameters := "--eviction-hard=memory.available<250Mi,nodefs.available<10%%,imagefs.available<15%% --system-reserved=cpu=200m,memory=500Mi --eviction-minimum-reclaim=memory.available=0Mi,nodefs.available=500Mi,imagefs.available=2Gi "
for key, value := range split {
if key == 0 {
kubeletConfig = value + "\"" + parameters
} else if key != len(split)-1 {
kubeletConfig += value
} else {
kubeletConfig += value + "\"\n"
}
}

check(ioutil.WriteFile(kubeletEnvFile, []byte(kubeletConfig), 0644))
}
}
7 changes: 4 additions & 3 deletions pkg/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ package network
import (
"errors"
"fmt"
"github.com/txn2/txeh"
"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"
"io/ioutil"
"net"
"os"
"os/exec"
"strings"

"github.com/txn2/txeh"
"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"
)

func check(err error) {
Expand Down

0 comments on commit 1b8c999

Please sign in to comment.