aboutsummaryrefslogtreecommitdiff
path: root/plugin/kubernetes/object/pod.go
blob: 04cbe1ad23bf2f6eb52a1eafd5335a0264ad60e0 (plain) (blame)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package object

import (
	"errors"
	"fmt"

	api "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/runtime"
)

// Pod is a stripped down api.Pod with only the items we need for CoreDNS.
type Pod struct {
	// Don't add new fields to this struct without talking to the CoreDNS maintainers.
	Version   string
	PodIP     string
	Name      string
	Namespace string

	*Empty
}

var errPodTerminating = errors.New("pod terminating")

// ToPod returns a function that converts an api.Pod to a *Pod.
func ToPod(skipCleanup bool) ToFunc {
	return func(obj interface{}) (interface{}, error) {
		apiPod, ok := obj.(*api.Pod)
		if !ok {
			return nil, fmt.Errorf("unexpected object %v", obj)
		}
		pod := toPod(skipCleanup, apiPod)
		t := apiPod.ObjectMeta.DeletionTimestamp
		if t != nil && !(*t).Time.IsZero() {
			// if the pod is in the process of termination, return an error so it can be ignored
			// during add/update event processing
			return pod, errPodTerminating
		}
		return pod, nil
	}
}

func toPod(skipCleanup bool, pod *api.Pod) *Pod {
	p := &Pod{
		Version:   pod.GetResourceVersion(),
		PodIP:     pod.Status.PodIP,
		Namespace: pod.GetNamespace(),
		Name:      pod.GetName(),
	}

	if !skipCleanup {
		*pod = api.Pod{}
	}

	return p
}

var _ runtime.Object = &Pod{}

// DeepCopyObject implements the ObjectKind interface.
func (p *Pod) DeepCopyObject() runtime.Object {
	p1 := &Pod{
		Version:   p.Version,
		PodIP:     p.PodIP,
		Namespace: p.Namespace,
		Name:      p.Name,
	}
	return p1
}

// GetNamespace implements the metav1.Object interface.
func (p *Pod) GetNamespace() string { return p.Namespace }

// SetNamespace implements the metav1.Object interface.
func (p *Pod) SetNamespace(namespace string) {}

// GetName implements the metav1.Object interface.
func (p *Pod) GetName() string { return p.Name }

// SetName implements the metav1.Object interface.
func (p *Pod) SetName(name string) {}

// GetResourceVersion implements the metav1.Object interface.
func (p *Pod) GetResourceVersion() string { return p.Version }

// SetResourceVersion implements the metav1.Object interface.
func (p *Pod) SetResourceVersion(version string) {}
>[console.log] Fix logging `Symbol` valuesGravatar Jarred Sumner 1-3/+2 2022-11-27Now that utf16 is fast we can just count the length instead of re-allocatingGravatar Jarred Sumner 1-5/+1 2022-11-27Remove extra indentGravatar Jarred Sumner 1-2/+0 2022-11-27Fix strangeness with Bun.env keysGravatar Jarred Sumner 1-9/+10 2022-11-27Fix crash in Headers.prototype.countGravatar Jarred Sumner 1-2/+5 2022-11-27Fix crash in OnigurumaRegExp gettersGravatar Jarred Sumner 1-0/+6 2022-11-26Fix build issueGravatar Jarred Sumner 2-15/+17 2022-11-26[bun:sqlite] Fix bug with latin1 supplemental charactersGravatar Jarred Sumner 2-2/+31 2022-11-26prettier?Gravatar Jarred Sumner 1-336/+339 2022-11-26Update mimallocGravatar Jarred Sumner 1-0/+0 2022-11-26Update string_immutable.zigGravatar Jarred Sumner 1-1/+1 2022-11-26Faster UTF16 -> UTF8 and UTF8 -> UTF16 (#1552)Gravatar Jarred Sumner 14-6/+31329 2022-11-26Make HTTP status text more consistent with other HTTP serversGravatar Jarred Sumner 2-2/+153 h='13' height='13' alt='Gravatar' /> dave caruso 2-144/+305 2023-04-05Update `typecheck` (#2572)Gravatar Colin McDonnell 3-4/+8 2023-04-05prependGravatar Jarred Sumner 1-7/+3 2023-04-05Add tests for `bun test` with preload scripts (#2566)Gravatar Jake Boone 2-1/+107 2023-04-05Disable buffering when we clear terminalGravatar Jarred Sumner 1-0/+2 2023-04-05PrettierGravatar Jarred Sumner 3-4/+4 2023-04-05fix(fetch.proxy) fix proxy authentication (#2554)Gravatar Ciro Spaciari 3-31/+186 2023-04-05fix: build warnings (#2562)Gravatar hiroki osame 4-4/+1 2023-04-05In Documentation, move --watch before the script name (#2569)Gravatar Lawlzer 1-4/+5 2023-04-05fix `deepEquals` with array holes and accessors (#2557)Gravatar Dylan Conway 2-10/+249 2023-04-05fix: modules to have null prototype (#2561)Gravatar hiroki osame 2-2/+9 2023-04-04:clock1: :clock2: :clock3:Gravatar Jarred Sumner 1-1/+1 2023-04-04Implement `import.meta.main` (#2556)Gravatar Jarred Sumner 10-8/+89 2023-04-04Dylan/fix some failing tests (#2544)Gravatar Jarred Sumner 10-29/+72 2023-04-04Add npm benchmark (#2555)Gravatar Colin McDonnell 13-1/+271 2023-04-03Use absolute paths morebun-v0.5.9Gravatar Jarred Sumner 2-6/+11 2023-04-03Fix test failureGravatar Jarred Sumner 1-15/+18