MCPcopy
hub / github.com/redspread/spread / NewPod

Function NewPod

pkg/entity/pod.go:29–64  ·  view source on GitHub ↗

NewPod creates a Entity for a corresponding *kube.Pod. Pod must be valid.

(kubePod *kube.Pod, defaults kube.ObjectMeta, source string, objects ...deploy.KubeObject)

Source from the content-addressed store, hash-verified

27
28// NewPod creates a Entity for a corresponding *kube.Pod. Pod must be valid.
29func NewPod(kubePod *kube.Pod, defaults kube.ObjectMeta, source string, objects ...deploy.KubeObject) (*Pod, error) {
30 if kubePod == nil {
31 return nil, fmt.Errorf("cannot create Pod from nil `%s`", source)
32 }
33
34 // deep copy
35 kubePod, err := copyPod(kubePod)
36 if err != nil {
37 return nil, err
38 }
39
40 base, err := newBase(EntityPod, defaults, source, objects)
41 if err != nil {
42 return nil, fmt.Errorf("could not create Pod from `%s`: %v", source, err)
43 }
44
45 pod := Pod{base: base}
46 for _, v := range kubePod.Spec.Containers {
47 container, err := NewContainer(v, defaults, source)
48 if err != nil {
49 return nil, err
50 }
51 pod.containers = append(pod.containers, container)
52 }
53 kubePod.Spec.Containers = []kube.Container{}
54
55 base.setDefaults(kubePod)
56 if err := validatePod(kubePod, true); err != nil {
57 return nil, fmt.Errorf("could not create Pod from `%s`: %v", source, err)
58 }
59
60 sort.Sort(pod.containers)
61
62 pod.pod = kubePod
63 return &pod, nil
64}
65
66// NewPodFromPodSpec creates a new Pod using ObjectMeta and a PodSpec.
67func NewPodFromPodSpec(meta kube.ObjectMeta, podSpec kube.PodSpec, defaults kube.ObjectMeta, source string, objects ...deploy.KubeObject) (*Pod, error) {

Callers 12

NewPodFromPodSpecFunction · 0.85
TestPodNilFunction · 0.85
TestPodInvalidFunction · 0.85
TestPodNoContainersFunction · 0.85
TestPodNoImageFunction · 0.85
TestPodBadObjectsFunction · 0.85
TestPodAttachImageFunction · 0.85
TestPodAttachContainerFunction · 0.85
TestRCAttachPodFunction · 0.85

Calls 5

copyPodFunction · 0.85
newBaseFunction · 0.85
NewContainerFunction · 0.85
validatePodFunction · 0.85
setDefaultsMethod · 0.80

Tested by 11

TestPodNilFunction · 0.68
TestPodInvalidFunction · 0.68
TestPodNoContainersFunction · 0.68
TestPodNoImageFunction · 0.68
TestPodBadObjectsFunction · 0.68
TestPodAttachImageFunction · 0.68
TestPodAttachContainerFunction · 0.68
TestRCAttachPodFunction · 0.68