Refactor provider init (#360)

* Refactor provider init

This moves provider init out of vkubelet setup, instead preferring to
initialize vkubelet with a provider.

* Split API server configuration from setup.

This makes sure that configuration (which is done primarily through env
vars) is separate from actually standing up the servers.

This also makes sure to abort daemon initialization if the API servers
are not able to start.
This commit is contained in:
Brian Goff
2018-09-26 13:18:02 -07:00
committed by Robbie Zhang
parent 6b97713af3
commit 083f6dee05
21 changed files with 518 additions and 293 deletions

56
cmd/taint.go Normal file
View File

@@ -0,0 +1,56 @@
package cmd
import (
"os"
"github.com/cpuguy83/strongerrors"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
)
// Default taint values
const (
DefaultTaintEffect = corev1.TaintEffectPreferNoSchedule
DefaultTaintKey = "virtual-kubelet.io/provider"
)
func getEnv(key, defaultValue string) string {
value, found := os.LookupEnv(key)
if found {
return value
}
return defaultValue
}
// getTaint creates a taint using the provided key/value.
// Taint effect is read from the environment
// The taint key/value may be overwritten by the environment.
func getTaint(key, value string) (*corev1.Taint, error) {
if key == "" {
key = DefaultTaintKey
value = provider
}
key = getEnv("VKUBELET_TAINT_KEY", key)
value = getEnv("VKUBELET_TAINT_VALUE", value)
effectEnv := getEnv("VKUBELET_TAINT_EFFECT", string(DefaultTaintEffect))
var effect corev1.TaintEffect
switch effectEnv {
case "NoSchedule":
effect = corev1.TaintEffectNoSchedule
case "NoExecute":
effect = corev1.TaintEffectNoExecute
case "PreferNoSchedule":
effect = corev1.TaintEffectPreferNoSchedule
default:
return nil, strongerrors.InvalidArgument(errors.Errorf("taint effect %q is not supported", effectEnv))
}
return &corev1.Taint{
Key: key,
Value: value,
Effect: effect,
}, nil
}