Add default provider taint and taint configuration options
This allows for more specificity when setting taint tolerations for workloads. Three new env variables are introduced: VKUBELET_TAINT_KEY (defaults to `virtual-kubelet.io/provider`) VKUBELET_TAINT_VALUE (defaults to provider name) VKUBELET_TAINT_EFFECT (defaults to `NoSchedule`) BREAKING CHANGES: - The default taint key of `azure.com/aci` is now `virtual-kubelet.io/provider`. - Specifying a custom taint key is now done via an environment variable rather than the `--taint` command line flag.
This commit is contained in:
committed by
Robbie Zhang
parent
9f07768875
commit
d47a0b2fc0
@@ -30,14 +30,23 @@ type Server struct {
|
||||
nodeName string
|
||||
namespace string
|
||||
k8sClient *kubernetes.Clientset
|
||||
taint string
|
||||
taint corev1.Taint
|
||||
disableTaint bool
|
||||
provider Provider
|
||||
podWatcher watch.Interface
|
||||
resourceManager *manager.ResourceManager
|
||||
}
|
||||
|
||||
func getEnv(key, defaultValue string) string {
|
||||
value, found := os.LookupEnv(key)
|
||||
if found {
|
||||
return value
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
// New creates a new virtual-kubelet server.
|
||||
func New(nodeName, operatingSystem, namespace, kubeConfig, taint, provider, providerConfig string) (*Server, error) {
|
||||
func New(nodeName, operatingSystem, namespace, kubeConfig, provider, providerConfig string, disableTaint bool) (*Server, error) {
|
||||
var config *rest.Config
|
||||
|
||||
// Check if the kubeConfig file exists.
|
||||
@@ -71,6 +80,27 @@ func New(nodeName, operatingSystem, namespace, kubeConfig, taint, provider, prov
|
||||
|
||||
internalIP := os.Getenv("VKUBELET_POD_IP")
|
||||
|
||||
vkTaintKey := getEnv("VKUBELET_TAINT_KEY", "virtual-kubelet.io/provider")
|
||||
vkTaintValue := getEnv("VKUBELET_TAINT_VALUE", provider)
|
||||
vkTaintEffectEnv := getEnv("VKUBELET_TAINT_EFFECT", "NoSchedule")
|
||||
var vkTaintEffect corev1.TaintEffect
|
||||
switch vkTaintEffectEnv {
|
||||
case "NoSchedule":
|
||||
vkTaintEffect = corev1.TaintEffectNoSchedule
|
||||
case "NoExecute":
|
||||
vkTaintEffect = corev1.TaintEffectNoExecute
|
||||
case "PreferNoSchedule":
|
||||
vkTaintEffect = corev1.TaintEffectPreferNoSchedule
|
||||
default:
|
||||
fmt.Printf("Taint effect '%s' is not supported\n", vkTaintEffectEnv)
|
||||
}
|
||||
|
||||
taint := corev1.Taint{
|
||||
Key: vkTaintKey,
|
||||
Value: vkTaintValue,
|
||||
Effect: vkTaintEffect,
|
||||
}
|
||||
|
||||
p, err = lookupProvider(provider, providerConfig, rm, nodeName, operatingSystem, internalIP, daemonEndpointPort)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -80,6 +110,7 @@ func New(nodeName, operatingSystem, namespace, kubeConfig, taint, provider, prov
|
||||
namespace: namespace,
|
||||
nodeName: nodeName,
|
||||
taint: taint,
|
||||
disableTaint: disableTaint,
|
||||
k8sClient: clientset,
|
||||
resourceManager: rm,
|
||||
provider: p,
|
||||
@@ -106,11 +137,8 @@ func New(nodeName, operatingSystem, namespace, kubeConfig, taint, provider, prov
|
||||
func (s *Server) registerNode() error {
|
||||
taints := make([]corev1.Taint, 0)
|
||||
|
||||
if s.taint != "" {
|
||||
taints = append(taints, corev1.Taint{
|
||||
Key: s.taint,
|
||||
Effect: corev1.TaintEffectNoSchedule,
|
||||
})
|
||||
if !s.disableTaint {
|
||||
taints = append(taints, s.taint)
|
||||
}
|
||||
|
||||
node := &corev1.Node{
|
||||
|
||||
Reference in New Issue
Block a user