-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployment.go
53 lines (49 loc) · 1.17 KB
/
deployment.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
package main
import (
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
)
func (c *Client) GetDeployments(namespace string) ([]appsv1.Deployment, error) {
dps, err := c.clientSet.AppsV1().Deployments(namespace).List(c.ctx, metav1.ListOptions{})
if err != nil {
return nil, err
}
return dps.Items, nil
}
func (c *Client) RestartDeployment(dp *appsv1.Deployment) (*appsv1.Deployment, error) {
diff, err := GenerateDiff(dp)
if err != nil {
return nil, err
}
return c.clientSet.AppsV1().Deployments(dp.Namespace).Patch(
c.ctx,
dp.Name,
types.StrategicMergePatchType,
diff,
metav1.PatchOptions{},
)
}
func (c *Client) WaitDeployment(dp *appsv1.Deployment) error {
w, err := c.clientSet.AppsV1().Deployments(dp.Namespace).Watch(c.ctx, metav1.ListOptions{})
if err != nil {
return err
}
stop := false
for !stop {
result := <-w.ResultChan()
rdp := result.Object.(*appsv1.Deployment)
if rdp == nil {
continue
}
if !(rdp.Name == dp.Name && rdp.Namespace == dp.Namespace) {
continue
}
if result.Type == watch.Modified {
stop = true
}
}
w.Stop()
return nil
}