-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcluster.go
49 lines (39 loc) · 1.7 KB
/
cluster.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
package kube
import (
"context"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/version"
)
// GetVersion returns server's version.
func (c *Client) GetVersion() (*version.Info, error) {
return c.client.Discovery().ServerVersion()
}
// GetNodes returns a NodeList.
func (c *Client) GetNodes(ctx context.Context, label ...string) (*corev1.NodeList, error) {
return c.client.CoreV1().Nodes().List(ctx, listOptions(label))
}
// GetNode returns a Node with the given name.
func (c *Client) GetNode(ctx context.Context, name string) (*corev1.Node, error) {
return c.client.CoreV1().Nodes().Get(ctx, name, metav1.GetOptions{})
}
// DeleteNode deletes a Node.
func (c *Client) DeleteNode(ctx context.Context, name string) error {
return c.client.CoreV1().Nodes().Delete(ctx, name, metav1.DeleteOptions{})
}
// GetNamespaces returns a NamespaceList.
func (c *Client) GetNamespaces(ctx context.Context, label ...string) (*corev1.NamespaceList, error) {
return c.client.CoreV1().Namespaces().List(ctx, listOptions(label))
}
// GetNamespace returns a Namespace with the given name.
func (c *Client) GetNamespace(ctx context.Context, name string) (*corev1.Namespace, error) {
return c.client.CoreV1().Namespaces().Get(ctx, name, metav1.GetOptions{})
}
// CreateNamespace creates a Namespace.
func (c *Client) CreateNamespace(ctx context.Context, namespace *corev1.Namespace) (*corev1.Namespace, error) {
return c.client.CoreV1().Namespaces().Create(ctx, namespace, metav1.CreateOptions{})
}
// DeleteNamespace deletes a Node.
func (c *Client) DeleteNamespace(ctx context.Context, name string) error {
return c.client.CoreV1().Namespaces().Delete(ctx, name, metav1.DeleteOptions{})
}