Implement provider node APIs
This commit is contained in:
@@ -3,10 +3,13 @@ package aws
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/manager"
|
"github.com/virtual-kubelet/virtual-kubelet/manager"
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FargateProvider implements the virtual-kubelet provider interface.
|
// FargateProvider implements the virtual-kubelet provider interface.
|
||||||
@@ -16,10 +19,21 @@ type FargateProvider struct {
|
|||||||
operatingSystem string
|
operatingSystem string
|
||||||
internalIP string
|
internalIP string
|
||||||
daemonEndpointPort int32
|
daemonEndpointPort int32
|
||||||
|
|
||||||
|
capacity capacity
|
||||||
|
lastTransitionTime time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
// Capacity represents the provisioned capacity on a Fargate cluster.
|
||||||
|
type capacity struct {
|
||||||
|
cpu string
|
||||||
|
memory string
|
||||||
|
storage string
|
||||||
|
pods string
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errNotImplemented = fmt.Errorf("Not implemented by Fargate provider")
|
errNotImplemented = fmt.Errorf("not implemented by Fargate provider")
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewFargateProvider creates a new Fargate provider.
|
// NewFargateProvider creates a new Fargate provider.
|
||||||
@@ -55,31 +69,31 @@ func (p *FargateProvider) CreatePod(pod *corev1.Pod) error {
|
|||||||
|
|
||||||
// UpdatePod takes a Kubernetes Pod and updates it within the provider.
|
// UpdatePod takes a Kubernetes Pod and updates it within the provider.
|
||||||
func (p *FargateProvider) UpdatePod(pod *corev1.Pod) error {
|
func (p *FargateProvider) UpdatePod(pod *corev1.Pod) error {
|
||||||
log.Printf("Received UpdatePod request for %+v.\n", pod)
|
log.Printf("Received UpdatePod request for %s/%s.\n", pod.Namespace, pod.Name)
|
||||||
return errNotImplemented
|
return errNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeletePod takes a Kubernetes Pod and deletes it from the provider.
|
// DeletePod takes a Kubernetes Pod and deletes it from the provider.
|
||||||
func (p *FargateProvider) DeletePod(pod *corev1.Pod) error {
|
func (p *FargateProvider) DeletePod(pod *corev1.Pod) error {
|
||||||
log.Printf("Received DeletePod request for %+v.\n", pod)
|
log.Printf("Received DeletePod request for %s/%s.\n", pod.Namespace, pod.Name)
|
||||||
return errNotImplemented
|
return errNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPod retrieves a pod by name from the provider (can be cached).
|
// GetPod retrieves a pod by name from the provider (can be cached).
|
||||||
func (p *FargateProvider) GetPod(namespace, name string) (*corev1.Pod, error) {
|
func (p *FargateProvider) GetPod(namespace, name string) (*corev1.Pod, error) {
|
||||||
log.Printf("Received GetPod request for %s::%s.\n", namespace, name)
|
log.Printf("Received GetPod request for %s/%s.\n", namespace, name)
|
||||||
return nil, errNotImplemented
|
return nil, errNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetContainerLogs retrieves the logs of a container by name from the provider.
|
// GetContainerLogs retrieves the logs of a container by name from the provider.
|
||||||
func (p *FargateProvider) GetContainerLogs(namespace, podName, containerName string, tail int) (string, error) {
|
func (p *FargateProvider) GetContainerLogs(namespace, podName, containerName string, tail int) (string, error) {
|
||||||
log.Printf("Received GetContainerLogs request for %s::%s::%s.\n", namespace, podName, containerName)
|
log.Printf("Received GetContainerLogs request for %s/%s/%s.\n", namespace, podName, containerName)
|
||||||
return "", errNotImplemented
|
return "", errNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPodStatus retrieves the status of a pod by name from the provider.
|
// GetPodStatus retrieves the status of a pod by name from the provider.
|
||||||
func (p *FargateProvider) GetPodStatus(namespace, name string) (*corev1.PodStatus, error) {
|
func (p *FargateProvider) GetPodStatus(namespace, name string) (*corev1.PodStatus, error) {
|
||||||
log.Printf("Received GetPodStatus request for %s::%s.\n", namespace, name)
|
log.Printf("Received GetPodStatus request for %s/%s.\n", namespace, name)
|
||||||
return nil, errNotImplemented
|
return nil, errNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,30 +106,104 @@ func (p *FargateProvider) GetPods() ([]*corev1.Pod, error) {
|
|||||||
// Capacity returns a resource list with the capacity constraints of the provider.
|
// Capacity returns a resource list with the capacity constraints of the provider.
|
||||||
func (p *FargateProvider) Capacity() corev1.ResourceList {
|
func (p *FargateProvider) Capacity() corev1.ResourceList {
|
||||||
log.Println("Received Capacity request.")
|
log.Println("Received Capacity request.")
|
||||||
return nil
|
|
||||||
|
return corev1.ResourceList{
|
||||||
|
corev1.ResourceCPU: resource.MustParse(p.capacity.cpu),
|
||||||
|
corev1.ResourceMemory: resource.MustParse(p.capacity.memory),
|
||||||
|
corev1.ResourceStorage: resource.MustParse(p.capacity.storage),
|
||||||
|
corev1.ResourcePods: resource.MustParse(p.capacity.pods),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NodeConditions returns a list of conditions (Ready, OutOfDisk, etc), which is polled
|
// NodeConditions returns a list of conditions (Ready, OutOfDisk, etc), which is polled
|
||||||
// periodically to update the node status within Kubernetes.
|
// periodically to update the node status within Kubernetes.
|
||||||
func (p *FargateProvider) NodeConditions() []corev1.NodeCondition {
|
func (p *FargateProvider) NodeConditions() []corev1.NodeCondition {
|
||||||
log.Println("Received NodeConditions request.")
|
log.Println("Received NodeConditions request.")
|
||||||
return nil
|
|
||||||
|
lastHeartbeatTime := metav1.Now()
|
||||||
|
lastTransitionTime := metav1.NewTime(p.lastTransitionTime)
|
||||||
|
lastTransitionReason := "Fargate cluster is ready"
|
||||||
|
lastTransitionMessage := "ok"
|
||||||
|
|
||||||
|
// Return static thumbs-up values for all conditions.
|
||||||
|
return []corev1.NodeCondition{
|
||||||
|
{
|
||||||
|
Type: corev1.NodeReady,
|
||||||
|
Status: corev1.ConditionTrue,
|
||||||
|
LastHeartbeatTime: lastHeartbeatTime,
|
||||||
|
LastTransitionTime: lastTransitionTime,
|
||||||
|
Reason: lastTransitionReason,
|
||||||
|
Message: lastTransitionMessage,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: corev1.NodeOutOfDisk,
|
||||||
|
Status: corev1.ConditionFalse,
|
||||||
|
LastHeartbeatTime: lastHeartbeatTime,
|
||||||
|
LastTransitionTime: lastTransitionTime,
|
||||||
|
Reason: lastTransitionReason,
|
||||||
|
Message: lastTransitionMessage,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: corev1.NodeMemoryPressure,
|
||||||
|
Status: corev1.ConditionFalse,
|
||||||
|
LastHeartbeatTime: lastHeartbeatTime,
|
||||||
|
LastTransitionTime: lastTransitionTime,
|
||||||
|
Reason: lastTransitionReason,
|
||||||
|
Message: lastTransitionMessage,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: corev1.NodeDiskPressure,
|
||||||
|
Status: corev1.ConditionFalse,
|
||||||
|
LastHeartbeatTime: lastHeartbeatTime,
|
||||||
|
LastTransitionTime: lastTransitionTime,
|
||||||
|
Reason: lastTransitionReason,
|
||||||
|
Message: lastTransitionMessage,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: corev1.NodeNetworkUnavailable,
|
||||||
|
Status: corev1.ConditionFalse,
|
||||||
|
LastHeartbeatTime: lastHeartbeatTime,
|
||||||
|
LastTransitionTime: lastTransitionTime,
|
||||||
|
Reason: lastTransitionReason,
|
||||||
|
Message: lastTransitionMessage,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: corev1.NodeConfigOK,
|
||||||
|
Status: corev1.ConditionTrue,
|
||||||
|
LastHeartbeatTime: lastHeartbeatTime,
|
||||||
|
LastTransitionTime: lastTransitionTime,
|
||||||
|
Reason: lastTransitionReason,
|
||||||
|
Message: lastTransitionMessage,
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NodeAddresses returns a list of addresses for the node status within Kubernetes.
|
// NodeAddresses returns a list of addresses for the node status within Kubernetes.
|
||||||
func (p *FargateProvider) NodeAddresses() []corev1.NodeAddress {
|
func (p *FargateProvider) NodeAddresses() []corev1.NodeAddress {
|
||||||
log.Println("Received NodeAddresses request.")
|
log.Println("Received NodeAddresses request.")
|
||||||
return nil
|
|
||||||
|
return []corev1.NodeAddress{
|
||||||
|
{
|
||||||
|
Type: corev1.NodeInternalIP,
|
||||||
|
Address: p.internalIP,
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NodeDaemonEndpoints returns NodeDaemonEndpoints for the node status within Kubernetes.
|
// NodeDaemonEndpoints returns NodeDaemonEndpoints for the node status within Kubernetes.
|
||||||
func (p *FargateProvider) NodeDaemonEndpoints() *corev1.NodeDaemonEndpoints {
|
func (p *FargateProvider) NodeDaemonEndpoints() *corev1.NodeDaemonEndpoints {
|
||||||
log.Println("Received NodeDaemonEndpoints request.")
|
log.Println("Received NodeDaemonEndpoints request.")
|
||||||
return nil
|
|
||||||
|
return &corev1.NodeDaemonEndpoints{
|
||||||
|
KubeletEndpoint: corev1.DaemonEndpoint{
|
||||||
|
Port: p.daemonEndpointPort,
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// OperatingSystem returns the operating system the provider is for.
|
// OperatingSystem returns the operating system the provider is for.
|
||||||
func (p *FargateProvider) OperatingSystem() string {
|
func (p *FargateProvider) OperatingSystem() string {
|
||||||
log.Println("Received OperatingSystem request.")
|
log.Println("Received OperatingSystem request.")
|
||||||
|
|
||||||
return p.operatingSystem
|
return p.operatingSystem
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user