Remove providers (#670)
* Move all but mock provider out of tree These have all been moved to repos under github.com/virtual-kubelet. * Introduce a providers.Store This essentially moves the the old register/ handling into a first class object that can be controlled from the CLI rather than through build tags deep in the code. This actually would have made it a bit easier to build the provider repos and makes the cmd/ code more re-usable.
This commit is contained in:
@@ -35,14 +35,14 @@ const (
|
||||
// See: https://github.com/virtual-kubelet/virtual-kubelet/issues/632
|
||||
/*
|
||||
var (
|
||||
_ providers.Provider = (*MockLegacyProvider)(nil)
|
||||
_ providers.PodMetricsProvider = (*MockLegacyProvider)(nil)
|
||||
_ providers.Provider = (*MockV0Provider)(nil)
|
||||
_ providers.PodMetricsProvider = (*MockV0Provider)(nil)
|
||||
_ node.PodNotifier = (*MockProvider)(nil)
|
||||
)
|
||||
*/
|
||||
|
||||
// MockLegacyProvider implements the virtual-kubelet provider interface and stores pods in memory.
|
||||
type MockLegacyProvider struct {
|
||||
// MockV0Provider implements the virtual-kubelet provider interface and stores pods in memory.
|
||||
type MockV0Provider struct {
|
||||
nodeName string
|
||||
operatingSystem string
|
||||
internalIP string
|
||||
@@ -53,9 +53,9 @@ type MockLegacyProvider struct {
|
||||
notifier func(*v1.Pod)
|
||||
}
|
||||
|
||||
// MockProvider is like MockLegacyProvider, but implements the PodNotifier interface
|
||||
// MockProvider is like MockV0Provider, but implements the PodNotifier interface
|
||||
type MockProvider struct {
|
||||
*MockLegacyProvider
|
||||
*MockV0Provider
|
||||
}
|
||||
|
||||
// MockConfig contains a mock virtual-kubelet's configurable parameters.
|
||||
@@ -65,8 +65,8 @@ type MockConfig struct {
|
||||
Pods string `json:"pods,omitempty"`
|
||||
}
|
||||
|
||||
// NewMockProviderMockConfig creates a new MockLegacyProvider. Mock legacy provider does not implement the new asynchronous podnotifier interface
|
||||
func NewMockLegacyProviderMockConfig(config MockConfig, nodeName, operatingSystem string, internalIP string, daemonEndpointPort int32) (*MockLegacyProvider, error) {
|
||||
// NewMockProviderMockConfig creates a new MockV0Provider. Mock legacy provider does not implement the new asynchronous podnotifier interface
|
||||
func NewMockV0ProviderMockConfig(config MockConfig, nodeName, operatingSystem string, internalIP string, daemonEndpointPort int32) (*MockV0Provider, error) {
|
||||
//set defaults
|
||||
if config.CPU == "" {
|
||||
config.CPU = defaultCPUCapacity
|
||||
@@ -77,7 +77,7 @@ func NewMockLegacyProviderMockConfig(config MockConfig, nodeName, operatingSyste
|
||||
if config.Pods == "" {
|
||||
config.Pods = defaultPodCapacity
|
||||
}
|
||||
provider := MockLegacyProvider{
|
||||
provider := MockV0Provider{
|
||||
nodeName: nodeName,
|
||||
operatingSystem: operatingSystem,
|
||||
internalIP: internalIP,
|
||||
@@ -94,21 +94,21 @@ func NewMockLegacyProviderMockConfig(config MockConfig, nodeName, operatingSyste
|
||||
return &provider, nil
|
||||
}
|
||||
|
||||
// NewMockLegacyProvider creates a new MockLegacyProvider
|
||||
func NewMockLegacyProvider(providerConfig, nodeName, operatingSystem string, internalIP string, daemonEndpointPort int32) (*MockLegacyProvider, error) {
|
||||
// NewMockV0Provider creates a new MockV0Provider
|
||||
func NewMockV0Provider(providerConfig, nodeName, operatingSystem string, internalIP string, daemonEndpointPort int32) (*MockV0Provider, error) {
|
||||
config, err := loadConfig(providerConfig, nodeName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewMockLegacyProviderMockConfig(config, nodeName, operatingSystem, internalIP, daemonEndpointPort)
|
||||
return NewMockV0ProviderMockConfig(config, nodeName, operatingSystem, internalIP, daemonEndpointPort)
|
||||
}
|
||||
|
||||
// NewMockProviderMockConfig creates a new MockProvider with the given config
|
||||
func NewMockProviderMockConfig(config MockConfig, nodeName, operatingSystem string, internalIP string, daemonEndpointPort int32) (*MockProvider, error) {
|
||||
p, err := NewMockLegacyProviderMockConfig(config, nodeName, operatingSystem, internalIP, daemonEndpointPort)
|
||||
p, err := NewMockV0ProviderMockConfig(config, nodeName, operatingSystem, internalIP, daemonEndpointPort)
|
||||
|
||||
return &MockProvider{MockLegacyProvider: p}, err
|
||||
return &MockProvider{MockV0Provider: p}, err
|
||||
}
|
||||
|
||||
// NewMockProvider creates a new MockProvider, which implements the PodNotifier interface
|
||||
@@ -158,7 +158,7 @@ func loadConfig(providerConfig, nodeName string) (config MockConfig, err error)
|
||||
}
|
||||
|
||||
// CreatePod accepts a Pod definition and stores it in memory.
|
||||
func (p *MockLegacyProvider) CreatePod(ctx context.Context, pod *v1.Pod) error {
|
||||
func (p *MockV0Provider) CreatePod(ctx context.Context, pod *v1.Pod) error {
|
||||
ctx, span := trace.StartSpan(ctx, "CreatePod")
|
||||
defer span.End()
|
||||
|
||||
@@ -215,7 +215,7 @@ func (p *MockLegacyProvider) CreatePod(ctx context.Context, pod *v1.Pod) error {
|
||||
}
|
||||
|
||||
// UpdatePod accepts a Pod definition and updates its reference.
|
||||
func (p *MockLegacyProvider) UpdatePod(ctx context.Context, pod *v1.Pod) error {
|
||||
func (p *MockV0Provider) UpdatePod(ctx context.Context, pod *v1.Pod) error {
|
||||
ctx, span := trace.StartSpan(ctx, "UpdatePod")
|
||||
defer span.End()
|
||||
|
||||
@@ -236,7 +236,7 @@ func (p *MockLegacyProvider) UpdatePod(ctx context.Context, pod *v1.Pod) error {
|
||||
}
|
||||
|
||||
// DeletePod deletes the specified pod out of memory.
|
||||
func (p *MockLegacyProvider) DeletePod(ctx context.Context, pod *v1.Pod) (err error) {
|
||||
func (p *MockV0Provider) DeletePod(ctx context.Context, pod *v1.Pod) (err error) {
|
||||
ctx, span := trace.StartSpan(ctx, "DeletePod")
|
||||
defer span.End()
|
||||
|
||||
@@ -277,7 +277,7 @@ func (p *MockLegacyProvider) DeletePod(ctx context.Context, pod *v1.Pod) (err er
|
||||
}
|
||||
|
||||
// GetPod returns a pod by name that is stored in memory.
|
||||
func (p *MockLegacyProvider) GetPod(ctx context.Context, namespace, name string) (pod *v1.Pod, err error) {
|
||||
func (p *MockV0Provider) GetPod(ctx context.Context, namespace, name string) (pod *v1.Pod, err error) {
|
||||
ctx, span := trace.StartSpan(ctx, "GetPod")
|
||||
defer func() {
|
||||
span.SetStatus(err)
|
||||
@@ -301,7 +301,7 @@ func (p *MockLegacyProvider) GetPod(ctx context.Context, namespace, name string)
|
||||
}
|
||||
|
||||
// GetContainerLogs retrieves the logs of a container by name from the provider.
|
||||
func (p *MockLegacyProvider) GetContainerLogs(ctx context.Context, namespace, podName, containerName string, opts api.ContainerLogOpts) (io.ReadCloser, error) {
|
||||
func (p *MockV0Provider) GetContainerLogs(ctx context.Context, namespace, podName, containerName string, opts api.ContainerLogOpts) (io.ReadCloser, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "GetContainerLogs")
|
||||
defer span.End()
|
||||
|
||||
@@ -314,20 +314,20 @@ func (p *MockLegacyProvider) GetContainerLogs(ctx context.Context, namespace, po
|
||||
|
||||
// Get full pod name as defined in the provider context
|
||||
// TODO: Implementation
|
||||
func (p *MockLegacyProvider) GetPodFullName(namespace string, pod string) string {
|
||||
func (p *MockV0Provider) GetPodFullName(namespace string, pod string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// RunInContainer executes a command in a container in the pod, copying data
|
||||
// between in/out/err and the container's stdin/stdout/stderr.
|
||||
func (p *MockLegacyProvider) RunInContainer(ctx context.Context, namespace, name, container string, cmd []string, attach api.AttachIO) error {
|
||||
func (p *MockV0Provider) RunInContainer(ctx context.Context, namespace, name, container string, cmd []string, attach api.AttachIO) error {
|
||||
log.G(context.TODO()).Infof("receive ExecInContainer %q", container)
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetPodStatus returns the status of a pod by name that is "running".
|
||||
// returns nil if a pod by that name is not found.
|
||||
func (p *MockLegacyProvider) GetPodStatus(ctx context.Context, namespace, name string) (*v1.PodStatus, error) {
|
||||
func (p *MockV0Provider) GetPodStatus(ctx context.Context, namespace, name string) (*v1.PodStatus, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "GetPodStatus")
|
||||
defer span.End()
|
||||
|
||||
@@ -345,7 +345,7 @@ func (p *MockLegacyProvider) GetPodStatus(ctx context.Context, namespace, name s
|
||||
}
|
||||
|
||||
// GetPods returns a list of all pods known to be "running".
|
||||
func (p *MockLegacyProvider) GetPods(ctx context.Context) ([]*v1.Pod, error) {
|
||||
func (p *MockV0Provider) GetPods(ctx context.Context) ([]*v1.Pod, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "GetPods")
|
||||
defer span.End()
|
||||
|
||||
@@ -361,7 +361,7 @@ func (p *MockLegacyProvider) GetPods(ctx context.Context) ([]*v1.Pod, error) {
|
||||
}
|
||||
|
||||
// Capacity returns a resource list containing the capacity limits.
|
||||
func (p *MockLegacyProvider) Capacity(ctx context.Context) v1.ResourceList {
|
||||
func (p *MockV0Provider) Capacity(ctx context.Context) v1.ResourceList {
|
||||
ctx, span := trace.StartSpan(ctx, "Capacity")
|
||||
defer span.End()
|
||||
|
||||
@@ -374,7 +374,7 @@ func (p *MockLegacyProvider) Capacity(ctx context.Context) v1.ResourceList {
|
||||
|
||||
// NodeConditions returns a list of conditions (Ready, OutOfDisk, etc), for updates to the node status
|
||||
// within Kubernetes.
|
||||
func (p *MockLegacyProvider) NodeConditions(ctx context.Context) []v1.NodeCondition {
|
||||
func (p *MockV0Provider) NodeConditions(ctx context.Context) []v1.NodeCondition {
|
||||
ctx, span := trace.StartSpan(ctx, "NodeConditions")
|
||||
defer span.End()
|
||||
|
||||
@@ -426,7 +426,7 @@ func (p *MockLegacyProvider) NodeConditions(ctx context.Context) []v1.NodeCondit
|
||||
|
||||
// NodeAddresses returns a list of addresses for the node status
|
||||
// within Kubernetes.
|
||||
func (p *MockLegacyProvider) NodeAddresses(ctx context.Context) []v1.NodeAddress {
|
||||
func (p *MockV0Provider) NodeAddresses(ctx context.Context) []v1.NodeAddress {
|
||||
ctx, span := trace.StartSpan(ctx, "NodeAddresses")
|
||||
defer span.End()
|
||||
|
||||
@@ -440,7 +440,7 @@ func (p *MockLegacyProvider) NodeAddresses(ctx context.Context) []v1.NodeAddress
|
||||
|
||||
// NodeDaemonEndpoints returns NodeDaemonEndpoints for the node status
|
||||
// within Kubernetes.
|
||||
func (p *MockLegacyProvider) NodeDaemonEndpoints(ctx context.Context) *v1.NodeDaemonEndpoints {
|
||||
func (p *MockV0Provider) NodeDaemonEndpoints(ctx context.Context) *v1.NodeDaemonEndpoints {
|
||||
ctx, span := trace.StartSpan(ctx, "NodeDaemonEndpoints")
|
||||
defer span.End()
|
||||
|
||||
@@ -454,13 +454,13 @@ func (p *MockLegacyProvider) NodeDaemonEndpoints(ctx context.Context) *v1.NodeDa
|
||||
// OperatingSystem returns the operating system for this provider.
|
||||
// This is a noop to default to Linux for now.
|
||||
|
||||
func (p *MockLegacyProvider) OperatingSystem() string {
|
||||
func (p *MockV0Provider) OperatingSystem() string {
|
||||
// This is harcoded due to: https://github.com/virtual-kubelet/virtual-kubelet/issues/632
|
||||
return "Linux"
|
||||
}
|
||||
|
||||
// GetStatsSummary returns dummy stats for all pods known by this provider.
|
||||
func (p *MockLegacyProvider) GetStatsSummary(ctx context.Context) (*stats.Summary, error) {
|
||||
func (p *MockV0Provider) GetStatsSummary(ctx context.Context) (*stats.Summary, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "GetStatsSummary")
|
||||
defer span.End()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user