...
1
16
17 package resources
18
19 import (
20 "context"
21 "fmt"
22
23 v1 "k8s.io/api/core/v1"
24 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25 clientset "k8s.io/client-go/kubernetes"
26
27 staticpodutil "k8s.io/kubernetes/cmd/kubeadm/app/util/staticpod"
28 )
29
30
31 type FakeStaticPod struct {
32 NodeName string
33 Component string
34 Annotations map[string]string
35 }
36
37
38
39 func (p *FakeStaticPod) Pod(suffix string) *v1.Pod {
40 pod := staticpodutil.ComponentPod(
41 v1.Container{
42 Name: p.Component,
43 Image: fmt.Sprintf("%s-image:tag", p.Component),
44 },
45 map[string]v1.Volume{},
46 p.Annotations,
47 )
48 if len(suffix) > 0 {
49 pod.ObjectMeta.Name = fmt.Sprintf("%s-%s-%s", p.Component, p.NodeName, suffix)
50 } else {
51 pod.ObjectMeta.Name = fmt.Sprintf("%s-%s", p.Component, p.NodeName)
52 }
53 pod.Spec.NodeName = p.NodeName
54 return &pod
55 }
56
57
58 func (p *FakeStaticPod) Create(client clientset.Interface) error {
59 return p.CreateWithPodSuffix(client, "")
60 }
61
62
63
64 func (p *FakeStaticPod) CreateWithPodSuffix(client clientset.Interface, suffix string) error {
65 _, err := client.CoreV1().Pods(metav1.NamespaceSystem).Create(context.TODO(), p.Pod(suffix), metav1.CreateOptions{})
66 return err
67 }
68
View as plain text