-
Notifications
You must be signed in to change notification settings - Fork 19
/
groot.go
131 lines (110 loc) · 3.51 KB
/
groot.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
package groot // import "code.cloudfoundry.org/grootfs/groot"
import (
"net/url"
"os"
"time"
"code.cloudfoundry.org/lager"
specsv1 "github.com/opencontainers/image-spec/specs-go/v1"
)
const (
GlobalLockKey = "global-groot-lock"
MetricImageCreationTime = "ImageCreationTime"
MetricImageDeletionTime = "ImageDeletionTime"
MetricImageStatsTime = "ImageStatsTime"
MetricImageCleanTime = "ImageCleanTime"
MetricDiskCachePercentage = "DiskCachePercentage"
MetricDiskCommittedPercentage = "DiskCommittedPercentage"
MetricDiskPurgeableCachePercentage = "DiskPurgeableCachePercentage"
)
//go:generate counterfeiter . ImageCloner
//go:generate counterfeiter . BaseImagePuller
//go:generate counterfeiter . Locksmith
//go:generate counterfeiter . DependencyManager
//go:generate counterfeiter . GarbageCollector
//go:generate counterfeiter . StoreMeasurer
//go:generate counterfeiter . RootFSConfigurer
//go:generate counterfeiter . MetricsEmitter
type ImageInfo struct {
Rootfs string `json:"rootfs"`
Image specsv1.Image `json:"image,omitempty"`
Mounts []MountInfo `json:"mounts,omitempty"`
Path string `json:"-"`
}
type MountInfo struct {
Destination string `json:"destination"`
Type string `json:"type"`
Source string `json:"source"`
Options []string `json:"options"`
}
type IDMappings struct {
UIDMappings []IDMappingSpec
GIDMappings []IDMappingSpec
}
type IDMappingSpec struct {
HostID int
NamespaceID int
Size int
}
type BaseImageSpec struct {
DiskLimit int64
ExcludeBaseImageFromQuota bool
BaseImageSrc *url.URL
UIDMappings []IDMappingSpec
GIDMappings []IDMappingSpec
OwnerUID int
OwnerGID int
}
type BaseImage struct {
BaseImage specsv1.Image
ChainIDs []string
}
type BaseImagePuller interface {
Pull(logger lager.Logger, spec BaseImageSpec) (BaseImage, error)
}
type ImageSpec struct {
ID string
Mount bool
DiskLimit int64
ExcludeBaseImageFromQuota bool
BaseVolumeIDs []string
BaseImage specsv1.Image
OwnerUID int
OwnerGID int
}
type ImageCloner interface {
Exists(id string) (bool, error)
Create(logger lager.Logger, spec ImageSpec) (ImageInfo, error)
Destroy(logger lager.Logger, id string) error
Stats(logger lager.Logger, id string) (VolumeStats, error)
}
type RootFSConfigurer interface {
Configure(rootFSPath string, baseImage *specsv1.Image) error
}
type DependencyManager interface {
Register(id string, chainIDs []string) error
Deregister(id string) error
}
type GarbageCollector interface {
UnusedVolumes(logger lager.Logger) ([]string, error)
MarkUnused(logger lager.Logger, unusedVolumes []string) error
Collect(logger lager.Logger) error
}
type StoreMeasurer interface {
Usage(logger lager.Logger) (int64, error)
CacheUsage(logger lager.Logger, volumes []string) int64
}
type Locksmith interface {
Lock(key string) (*os.File, error)
Unlock(lockFile *os.File) error
}
type MetricsEmitter interface {
TryEmitUsage(logger lager.Logger, name string, usage int64, units string)
TryEmitDurationFrom(logger lager.Logger, name string, from time.Time)
}
type DiskUsage struct {
TotalBytesUsed int64 `json:"total_bytes_used"`
ExclusiveBytesUsed int64 `json:"exclusive_bytes_used"`
}
type VolumeStats struct {
DiskUsage DiskUsage `json:"disk_usage"`
}