This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
/
interfaces.go
310 lines (275 loc) · 8.55 KB
/
interfaces.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
// Copyright Jetstack Ltd. See LICENSE for details.
package interfaces
import (
"context"
"io"
"net"
"os"
vault "github.com/hashicorp/vault/api"
"github.com/jetstack/vault-unsealer/pkg/kv"
"github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh"
clusterv1alpha1 "github.com/jetstack/tarmak/pkg/apis/cluster/v1alpha1"
tarmakv1alpha1 "github.com/jetstack/tarmak/pkg/apis/tarmak/v1alpha1"
"github.com/jetstack/tarmak/pkg/tarmak/role"
"github.com/jetstack/tarmak/pkg/tarmak/utils/input"
wingclient "github.com/jetstack/tarmak/pkg/wing/client/clientset/versioned"
)
type Cluster interface {
Variables() map[string]interface{}
Environment() Environment
Name() string
NetworkCIDR() *net.IPNet
RemoteState() string
// get the absolute config path to cluster's config folder
ConfigPath() string
Config() *clusterv1alpha1.Cluster
Images() []string // This returns all neccessary base images
SSHConfigPath() string
SSHHostKeysPath() string
ClusterName() string
Log() *logrus.Entry
APITunnel() Tunnel
Region() string
Subnets() []clusterv1alpha1.Subnet // Return subnets per AZ
Role(string) *role.Role
Roles() []*role.Role
InstancePools() []InstancePool
InstancePool(string) InstancePool
ImageIDs() (map[string]string, error)
Parameters() map[string]string
Type() string
ListHosts() ([]Host, error)
// This enforces a reapply of the puppet.tar.gz on every instance in the cluster
ReapplyConfiguration() error
// This waits until all instances have congverged successfully
WaitForConvergance() error
// This upload the puppet.tar.gz to the cluster, warning there is some duplication as terraform is also uploading this puppet.tar.gz
UploadConfiguration() error
// Verify the cluster (these contain more expensive calls like AWS calls
Verify() error
// Validate the cluster (these contain less expensive local calls)
Validate() error
// This state is either destroy or apply
GetState() string
SetState(string)
// get the terrform output for this cluster
TerraformOutput() (map[string]interface{}, error)
// return public api hostname
PublicAPIHostname() string
// cluster uses encrypted EBS
AmazonEBSEncrypted() bool
}
type Environment interface {
Tarmak() Tarmak
Location() string // this returns the location of the environment (e.g. the region)
Variables() map[string]interface{}
Provider() Provider
// Verify the cluster (these contain more expensive calls like AWS calls
Verify() error
// Validate the cluster (these contain less expensive local calls)
Validate() error
Name() string
HubName() string
Clusters() []Cluster
Cluster(name string) (cluster Cluster, err error)
SSHPrivateKeyPath() string
SSHPrivateKey() (signer interface{})
Log() *logrus.Entry
Parameters() map[string]string
Config() *tarmakv1alpha1.Environment
Type() string
WingTunnel() Tunnel
WingClientset() (*wingclient.Clientset, Tunnel, error)
// get the absolute config path to the environment's config folder
ConfigPath() string
// this verifies if the connection to the bastion instance is working
VerifyBastionAvailable() error
// return the cluster which is the hub
Hub() Cluster
// return the vault for the environment
Vault() Vault
}
type Provider interface {
Cloud() string
Name() string
Parameters() map[string]string
Region() string
// Verify the cluster (these contain more expensive calls like AWS calls)
Verify() error
// Validate the cluster (these contain less expensive local calls)
Validate() error
Reset() // reset all caches within the provider
RemoteStateBucketName() string
RemoteStateBucketAvailable() (bool, error)
RemoteState(namespace, clusterName, stackName string) string
PublicZone() string
Environment() ([]string, error)
Variables() map[string]interface{}
QueryImages(tags map[string]string) ([]*tarmakv1alpha1.Image, error)
DefaultImage(version string) (*tarmakv1alpha1.Image, error)
VaultKV() (kv.Service, error)
VaultKVWithParams(kmsKeyID, unsealKeyName string) (kv.Service, error)
ListHosts(Cluster) ([]Host, error)
InstanceType(string) (string, error)
VolumeType(string) (string, error)
String() string
AskEnvironmentLocation(Initialize) (string, error)
AskInstancePoolZones(Initialize) (zones []string, err error)
UploadConfiguration(Cluster, io.ReadSeeker, string) error
EnsureRemoteResources() error
LegacyPuppetTFName() string
// Remove provider
Remove() error
}
type Tarmak interface {
Variables() map[string]interface{}
Log() *logrus.Entry
RootPath() (string, error)
// get the absolute config path to tarmak's config folder
ConfigPath() string
Cluster() Cluster
ClusterFlags() tarmakv1alpha1.ClusterFlags
Environments() []Environment
Environment() Environment
Providers() []Provider
Provider() Provider
Terraform() Terraform
Packer() Packer
Puppet() Puppet
Config() Config
SSH() SSH
Version() string
HomeDirExpand(in string) (string, error)
HomeDir() string
KeepContainers() bool
CancellationContext() CancellationContext
Cleanup()
// get a provider by name
ProviderByName(string) (Provider, error)
// get an environment by name
EnvironmentByName(string) (Environment, error)
EnsureRemoteResources() error
}
type Config interface {
Cluster(environment string, name string) (cluster *clusterv1alpha1.Cluster, err error)
Clusters(environment string) (clusters []*clusterv1alpha1.Cluster)
AppendCluster(cluster *clusterv1alpha1.Cluster) error
UniqueClusterName(environment, name string) error
Provider(name string) (provider *tarmakv1alpha1.Provider, err error)
Providers() (providers []*tarmakv1alpha1.Provider)
AppendProvider(prov *tarmakv1alpha1.Provider) error
UniqueProviderName(name string) error
ValidName(name, regex string) error
ReadConfig() (*tarmakv1alpha1.Config, error)
Environment(name string) (environment *tarmakv1alpha1.Environment, err error)
Environments() (environments []*tarmakv1alpha1.Environment)
AppendEnvironment(*tarmakv1alpha1.Environment) error
UniqueEnvironmentName(name string) error
// currently selected <env name>-<cluster name>
CurrentCluster() (string, error)
// currently selected cluster name
CurrentClusterName() (string, error)
// currently selected env name
CurrentEnvironmentName() (string, error)
// remove environment
RemoveEnvironment(environment string) error
Contact() string
Project() string
WingDevMode() bool
SetCurrentCluster(string) error
IgnoreMissingPublicKeyTags() bool
}
type Packer interface {
IDs(encrypted bool) (map[string]string, error)
List() ([]*tarmakv1alpha1.Image, error)
Build(imageNames []string) error
}
type Terraform interface {
Output(cluster Cluster) (map[string]interface{}, error)
Prepare(cluster Cluster) error
}
type SSH interface {
WriteConfig(Cluster) error
PassThrough([]string) error
Tunnel(destination, destinationPort, localPort string, daemonize bool) Tunnel
Execute(host string, cmd []string, stdin io.Reader, stdout, stderr io.Writer) (returnCode int, err error)
Validate() error
Cleanup()
}
type Logs interface {
Aggregate(group string, flags tarmakv1alpha1.ClusterLogsFlags) error
}
type Tunnel interface {
Start() error
Stop()
Port() string
BindAddress() string
Done() <-chan struct{}
}
type VaultTunnel interface {
Tunnel
VaultClient() *vault.Client
}
type Host interface {
ID() string
Hostname() string
User() string
Roles() []string
SSHConfig(strictChecking string) string
Parameters() map[string]string
SSHHostPublicKeys() ([]ssh.PublicKey, error)
Aliases() []string
}
type Puppet interface {
TarGz(io.Writer) error
Initialize(packerbuild bool) error
}
type Kubectl interface {
}
type Vault interface {
Tunnel() (VaultTunnel, error)
RootToken() (string, error)
TunnelFromFQDNs(vaultInternalFQDNs []string, vaultCA string) (VaultTunnel, error)
VerifyInitFromFQDNs(instances []string, vaultCA, vaultKMSKeyID, vaultUnsealKeyName string) error
}
type InstancePool interface {
AmazonAdditionalIAMPolicies() []string
Config() *clusterv1alpha1.InstancePool
TFName() string
Name() string
Image() string
Role() *role.Role
Volumes() []Volume
RootVolume() Volume
Zones() []string
Validate() error
MinCount() int
MaxCount() int
InstanceType() string
Labels() (string, error)
Taints() (string, error)
}
type Volume interface {
Name() string
Size() int
Type() string
Device() string
}
type Initialize interface {
Input() *input.Input
AskProjectName() (string, error)
AskContact() (string, error)
Config() Config
Tarmak() Tarmak
CurrentProvider() Provider
CurrentEnvironment() Environment
}
type CancellationContext interface {
Done() <-chan struct{}
Err() error
Signal() os.Signal
WaitOrCancel(f func() error)
WaitOrCancelReturnCode(f func() (int, error))
TryOrCancel(done <-chan struct{}) context.Context
}