k9s/internal/dao/types.go

65 lines
1.6 KiB
Go

package dao
import (
"context"
"github.com/derailed/k9s/internal/k8s"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/informers"
)
type Factory interface {
// Client retrieves an api client.
Client() k8s.Connection
// Get fetch a given resource.
Get(ns, gvr, n string, sel labels.Selector) (runtime.Object, error)
// List fetch a collection of resources.
List(ns, gvr string, sel labels.Selector) ([]runtime.Object, error)
// ForResource fetch an informer for a given resource.
ForResource(ns, gvr string) informers.GenericInformer
// WaitForCacheSync synchronize the cache.
WaitForCacheSync() map[schema.GroupVersionResource]bool
}
// Accessor represents an accessible k8s resource.
type Accessor interface {
Nuker
// Init the resource with a factory object.
Init(Factory, GVR)
}
// Loggable represents resources with logs.
type Loggable interface {
// TaiLogs streams resource logs.
TailLogs(ctx context.Context, c chan<- string, opts LogOptions) error
}
type Scalable interface {
Scale(ns, n string, replicas int32) error
}
// Nuker represents a resource deleter.
type Nuker interface {
// Delete removes a resource from the api server.
Delete(ns, n string, cascade, force bool) error
}
// Switchable represents a switchable resource.
type Switchable interface {
// Switch changes the active context.
Switch(ctx string) error
}
// Restartable represents a restartable resource.
type Restartable interface {
// Restart performs a rollout restart.
Restart(ns, n string) error
}