-
Notifications
You must be signed in to change notification settings - Fork 10
/
resources.go
123 lines (97 loc) · 2.38 KB
/
resources.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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
type kubeResource interface {
APIVersion() string
Kind() string
Name() string
Namespace() string
UID() types.UID
Annotations() map[string]string
Labels() map[string]string
TemplateLabels() map[string]string
Replicas() int32
StatusReadyReplicas() int32
Selector() *metav1.LabelSelector
}
type statefulSet struct {
appsv1.StatefulSet
}
func (s statefulSet) APIVersion() string {
return s.StatefulSet.APIVersion
}
func (s statefulSet) Kind() string {
return s.StatefulSet.Kind
}
func (s statefulSet) Name() string {
return s.StatefulSet.Name
}
func (s statefulSet) Namespace() string {
return s.StatefulSet.Namespace
}
func (s statefulSet) UID() types.UID {
return s.StatefulSet.UID
}
func (s statefulSet) Annotations() map[string]string {
return s.StatefulSet.Annotations
}
func (s statefulSet) Labels() map[string]string {
return s.StatefulSet.Labels
}
func (s statefulSet) TemplateLabels() map[string]string {
return s.StatefulSet.Spec.Template.Labels
}
func (s statefulSet) Replicas() int32 {
if s.StatefulSet.Spec.Replicas == nil {
return 1
}
return *s.StatefulSet.Spec.Replicas
}
func (s statefulSet) StatusReadyReplicas() int32 {
return s.StatefulSet.Status.ReadyReplicas
}
func (s statefulSet) Selector() *metav1.LabelSelector {
return s.StatefulSet.Spec.Selector
}
type deployment struct {
appsv1.Deployment
}
func (d deployment) APIVersion() string {
return d.Deployment.APIVersion
}
func (d deployment) Kind() string {
return d.Deployment.Kind
}
func (d deployment) Name() string {
return d.Deployment.Name
}
func (d deployment) Namespace() string {
return d.Deployment.Namespace
}
func (d deployment) UID() types.UID {
return d.Deployment.UID
}
func (d deployment) Annotations() map[string]string {
return d.Deployment.Annotations
}
func (d deployment) Labels() map[string]string {
return d.Deployment.Labels
}
func (d deployment) TemplateLabels() map[string]string {
return d.Deployment.Spec.Template.Labels
}
func (d deployment) Replicas() int32 {
if d.Deployment.Spec.Replicas == nil {
return 1
}
return *d.Deployment.Spec.Replicas
}
func (d deployment) StatusReadyReplicas() int32 {
return d.Deployment.Status.ReadyReplicas
}
func (d deployment) Selector() *metav1.LabelSelector {
return d.Deployment.Spec.Selector
}