-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
types.go
157 lines (125 loc) 路 4.16 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package dao
import (
"context"
"io"
"time"
"github.com/derailed/k9s/internal/client"
"github.com/derailed/k9s/internal/watch"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/informers"
restclient "k8s.io/client-go/rest"
)
// ResourceMetas represents a collection of resource metadata.
type ResourceMetas map[client.GVR]metav1.APIResource
// Accessors represents a collection of dao accessors.
type Accessors map[client.GVR]Accessor
// Factory represents a resource factory.
type Factory interface {
// Client retrieves an api client.
Client() client.Connection
// Get fetch a given resource.
Get(gvr, path string, wait bool, sel labels.Selector) (runtime.Object, error)
// List fetch a collection of resources.
List(gvr, ns string, wait bool, sel labels.Selector) ([]runtime.Object, error)
// ForResource fetch an informer for a given resource.
ForResource(ns, gvr string) (informers.GenericInformer, error)
// CanForResource fetch an informer for a given resource if authorized
CanForResource(ns, gvr string, verbs []string) (informers.GenericInformer, error)
// WaitForCacheSync synchronize the cache.
WaitForCacheSync()
// DeleteForwarder deletes a pod forwarder.
DeleteForwarder(path string)
// Forwards returns all portforwards.
Forwarders() watch.Forwarders
}
// Getter represents a resource getter.
type Getter interface {
// Get return a given resource.
Get(ctx context.Context, path string) (runtime.Object, error)
}
// Lister represents a resource lister.
type Lister interface {
// List returns a resource collection.
List(ctx context.Context, ns string) ([]runtime.Object, error)
}
// Accessor represents an accessible k8s resource.
type Accessor interface {
Lister
Getter
// Init the resource with a factory object.
Init(Factory, client.GVR)
// GVR returns a gvr a string.
GVR() string
}
// DrainOptions tracks drain attributes.
type DrainOptions struct {
GracePeriodSeconds int
Timeout time.Duration
IgnoreAllDaemonSets bool
DeleteEmptyDirData bool
Force bool
}
// NodeMaintainer performs node maintenance operations.
type NodeMaintainer interface {
// ToggleCordon toggles cordon/uncordon a node.
ToggleCordon(path string, cordon bool) error
// Drain drains the given node.
Drain(path string, opts DrainOptions, w io.Writer) error
}
// Loggable represents resources with logs.
type Loggable interface {
// TaiLogs streams resource logs.
TailLogs(ctx context.Context, c LogChan, opts *LogOptions) error
}
// Describer describes a resource.
type Describer interface {
// Describe describes a resource.
Describe(path string) (string, error)
// ToYAML dumps a resource to YAML.
ToYAML(path string, showManaged bool) (string, error)
}
// Scalable represents resources that can scale.
type Scalable interface {
// Scale scales a resource up or down.
Scale(ctx context.Context, path string, replicas int32) error
}
// Controller represents a pod controller.
type Controller interface {
// Pod returns a pod instance matching the selector.
Pod(path string) (string, error)
}
// Nuker represents a resource deleter.
type Nuker interface {
// Delete removes a resource from the api server.
Delete(path 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(ctx context.Context, path string) error
}
// Runnable represents a runnable resource.
type Runnable interface {
// Run triggers a run.
Run(path string) error
}
// Logger represents a resource that exposes logs.
type Logger interface {
// Logs tails a resource logs.
Logs(path string, opts *v1.PodLogOptions) (*restclient.Request, error)
}
// ContainsPodSpec represents a resource with a pod template.
type ContainsPodSpec interface {
// Get PodSpec of a resource
GetPodSpec(path string) (*v1.PodSpec, error)
// Set Images for a resource
SetImages(ctx context.Context, path string, imageSpecs ImageSpecs) error
}