This starts the work of having a `NodeProvider` which is responsible for providing node details. It splits the responsibilities of node management off to a new controller. The primary change here is to add the framework pieces for node management and move the VK CLI to use this new controller. It also adds support for node leases where available. This can be enabled via the command line (disabled by default), but may fall back if we find that leaess aren't supported on the cluster.
57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"github.com/virtual-kubelet/virtual-kubelet/providers"
|
|
"github.com/virtual-kubelet/virtual-kubelet/version"
|
|
v1 "k8s.io/api/core/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
)
|
|
|
|
var (
|
|
// vkVersion is a concatenation of the Kubernetes version the VK is built against, the string "vk" and the VK release version.
|
|
// TODO @pires revisit after VK 1.0 is released as agreed in https://github.com/virtual-kubelet/virtual-kubelet/pull/446#issuecomment-448423176.
|
|
vkVersion = strings.Join([]string{"v1.13.1", "vk", version.Version}, "-")
|
|
)
|
|
|
|
// NodeFromProvider builds a kubernetes node object from a provider
|
|
// This is a temporary solution until node stuff actually split off from the provider interface itself.
|
|
func NodeFromProvider(ctx context.Context, name string, taint *v1.Taint, p providers.Provider) *v1.Node {
|
|
taints := make([]v1.Taint, 0)
|
|
|
|
if taint != nil {
|
|
taints = append(taints, *taint)
|
|
}
|
|
|
|
node := &v1.Node{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: name,
|
|
Labels: map[string]string{
|
|
"type": "virtual-kubelet",
|
|
"kubernetes.io/role": "agent",
|
|
"beta.kubernetes.io/os": strings.ToLower(p.OperatingSystem()),
|
|
"kubernetes.io/hostname": name,
|
|
"alpha.service-controller.kubernetes.io/exclude-balancer": "true",
|
|
},
|
|
},
|
|
Spec: v1.NodeSpec{
|
|
Taints: taints,
|
|
},
|
|
Status: v1.NodeStatus{
|
|
NodeInfo: v1.NodeSystemInfo{
|
|
OperatingSystem: p.OperatingSystem(),
|
|
Architecture: "amd64",
|
|
KubeletVersion: vkVersion,
|
|
},
|
|
Capacity: p.Capacity(ctx),
|
|
Allocatable: p.Capacity(ctx),
|
|
Conditions: p.NodeConditions(ctx),
|
|
Addresses: p.NodeAddresses(ctx),
|
|
DaemonEndpoints: *p.NodeDaemonEndpoints(ctx),
|
|
},
|
|
}
|
|
return node
|
|
}
|