forked from Azure/AgentBaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpod.go
More file actions
69 lines (54 loc) · 1.83 KB
/
pod.go
File metadata and controls
69 lines (54 loc) · 1.83 KB
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
package e2e_test
import (
"context"
"fmt"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/yaml"
)
// Returns the name of a pod that's a member of the 'debug' daemonset, running on an aks-nodepool node.
func getDebugPodName(kube *kubeclient) (string, error) {
podList := corev1.PodList{}
if err := kube.dynamic.List(context.Background(), &podList, client.MatchingLabels{"app": "debug"}); err != nil {
return "", fmt.Errorf("failed to list debug pod: %w", err)
}
if len(podList.Items) < 1 {
return "", fmt.Errorf("failed to find debug pod, list by selector returned no results")
}
podName := podList.Items[0].Name
return podName, nil
}
func ensureDebugDaemonset(ctx context.Context, kube *kubeclient) error {
manifest := getDebugDaemonset()
var ds appsv1.DaemonSet
if err := yaml.Unmarshal([]byte(manifest), &ds); err != nil {
return fmt.Errorf("failed to unmarshal debug daemonset manifest: %w", err)
}
desired := ds.DeepCopy()
_, err := controllerutil.CreateOrUpdate(ctx, kube.dynamic, &ds, func() error {
ds = *desired
return nil
})
if err != nil {
return fmt.Errorf("failed to apply debug daemonset: %w", err)
}
return nil
}
func ensureTestNginxPod(ctx context.Context, kube *kubeclient, nodeName string) error {
manifest := getNginxPodTemplate(nodeName)
var obj corev1.Pod
if err := yaml.Unmarshal([]byte(manifest), &obj); err != nil {
return fmt.Errorf("failed to unmarshal nginx pod manifest: %w", err)
}
desired := obj.DeepCopy()
_, err := controllerutil.CreateOrUpdate(ctx, kube.dynamic, &obj, func() error {
obj = *desired
return nil
})
if err != nil {
return fmt.Errorf("failed to apply nginx test pod: %w", err)
}
return waitUntilPodRunning(ctx, kube, nodeName)
}