forked from kubernetes-sigs/kind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.go
99 lines (82 loc) · 3.19 KB
/
context.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
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cluster
import (
"sigs.k8s.io/kind/pkg/cluster/constants"
"sigs.k8s.io/kind/pkg/cluster/create"
"sigs.k8s.io/kind/pkg/cluster/nodes"
internalcontext "sigs.k8s.io/kind/pkg/internal/cluster/context"
internalcreate "sigs.k8s.io/kind/pkg/internal/cluster/create"
internaldelete "sigs.k8s.io/kind/pkg/internal/cluster/delete"
internallogs "sigs.k8s.io/kind/pkg/internal/cluster/logs"
)
// TODO(bentheelder): reimplement GetControlPlaneMeta for Context
// DefaultName is the default cluster name
const DefaultName = constants.DefaultClusterName
// Context is used to create / manipulate kubernetes-in-docker clusters
// See: NewContext()
type Context struct {
// the internal context type, shared between implementations of more
// advanced methods like create
ic *internalcontext.Context
}
// NewContext returns a new cluster management context
// if name is "" the default name will be used (constants.DefaultClusterName)
func NewContext(name string) *Context {
// wrap a new internal context
return &Context{
ic: internalcontext.NewContext(name),
}
}
// Validate will be called before creating new resources using the context
// It will not be called before deleting or listing resources, so as to allow
// contexts based around previously valid values to be used in newer versions
// You can call this early yourself to check validation before creation calls,
// though it will be called internally.
func (c *Context) Validate() error {
return c.ic.Validate()
}
// Name returns context name / cluster name
func (c *Context) Name() string {
return c.ic.Name()
}
// KubeConfigPath returns the path to where the Kubeconfig would be placed
// by kind based on the configuration.
func (c *Context) KubeConfigPath() string {
return c.ic.KubeConfigPath()
}
// Create provisions and starts a kubernetes-in-docker cluster
func (c *Context) Create(options ...create.ClusterOption) error {
return internalcreate.Cluster(c.ic, options...)
}
// Delete tears down a kubernetes-in-docker cluster
func (c *Context) Delete() error {
return internaldelete.Cluster(c.ic)
}
// ListNodes returns the list of container IDs for the "nodes" in the cluster
func (c *Context) ListNodes() ([]nodes.Node, error) {
return c.ic.ListNodes()
}
// ListInternalNodes returns the list of container IDs for the "nodes" in the cluster
// that are not external
func (c *Context) ListInternalNodes() ([]nodes.Node, error) {
return c.ic.ListInternalNodes()
}
// CollectLogs will populate dir with cluster logs and other debug files
func (c *Context) CollectLogs(dir string) error {
nodes, err := c.ListInternalNodes()
if err != nil {
return err
}
return internallogs.Collect(nodes, dir)
}