-
Notifications
You must be signed in to change notification settings - Fork 19
/
package.go
144 lines (113 loc) · 3.94 KB
/
package.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
// Package api defines the API outline for working with
// different container runtimes.
//
// The user should first establish some kind of connection
// as client with their desired container runtime. The
// client configuraton could be either by specifying it
// manually, or by recognizing them on the host first.
//
// After establishing a client connection with container
// runtime, the user could invoke the client API to enumerate
// containers and images by their IDs, and open one of these
// entities furtherly.
package api
import (
"context"
imageV1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/opencontainers/runtime-spec/specs-go"
)
// Layer is the open layer object from a image.
type Layer interface {
FileSystem
Close() error
ID() string
Opaques() ([]string, error)
Whiteouts() ([]string, error)
}
// Image is the open image object from a runtime.
type Image interface {
FileSystem
Close() error
ID() string
Repos() ([]string, error)
RepoRefs() ([]string, error)
OCISpecV1() (*imageV1.Image, error)
}
type Container interface {
FileSystem
Psutil
Close() error
ID() string
Name() string
ImageID() string
OCISpec() (*specs.Spec, error)
OCIState() (*specs.State, error)
}
// Runtime is the connection established with a specific
// container runtime, depending on the implementation and
// container runtime internal nature.
type Runtime interface {
Close() error
// ListImageIDs attempt to enumerate the images by their
// IDs managed by the container runtime, which could be
// used to open the image.
ListImageIDs() ([]string, error)
// FindImageIDs attempt to match image ID by specifying
// their human readable identifiers. It must follow the
// following rules.
//
// 1. When pattern is image ID recognizable by this
// container runtime, it will be searched first.
// 2. When pattern is pure hexadecimal, the digest value
// portion will be matched.
// 3. When pattern is a single identifier, all images
// with the specified identifier will be matched.
// 4. When pattern is a repository path, all images with
// the specified repository but different versions
// will be matched.
// 5. When pattern is a named tagged or canonical
// reference, the whole portion will be matched.
FindImageIDs(pattern string) ([]string, error)
// OpenImageByID attempt to open a image by its ID.
OpenImageByID(id string) (Image, error)
// ListContainerIDs attempt to open a container by its ID.
ListContainerIDs() ([]string, error)
// FindContainerIDs attempt to match container ID by specifying
// their human readable identifiers. It must follow the
// following rules.
FindContainerIDs(pattern string) ([]string, error)
// OpenContainerByID attempt to open a container by its ID.
OpenContainerByID(id string) (Container, error)
}
type ClusterResource interface {
Close() error
// Kind return resource kind
Kind() string
// Get attempt to get resource raw bytes from cluster
Get(ctx context.Context, name string) ([]byte, error)
// List attempts to list resources from cluster
// return resource name for Get method
List(ctx context.Context) ([]string, error)
// Create attempts to create resource in cluster
Create(ctx context.Context, resource []byte) error
// Update attempts to update resource in cluster
Update(ctx context.Context, resource []byte) error
}
// Cluster is the connection established with a specific
// specs cluster
type Cluster interface {
Close() error
// Version return version of cluster
Version() string
// ConfigPath return config path of cluster
ConfigPath() string
// ConfigBytes return config path of cluster
ConfigBytes() []byte
// ListNamespaces attempt to list all namespaces in cluster
ListNamespaces() ([]string, error)
// InCluster return kubernetes client whether in cluster
InCluster() bool
// Resource attempt to open ClusterResource
// accord schema.GroupVersionResource
Resource(namespace string, kind string) (ClusterResource, error)
}