-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtypes.go
97 lines (81 loc) · 3.33 KB
/
types.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
package kommons
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
type CRD struct {
Kind string `yaml:"kind,omitempty"`
APIVersion string `yaml:"apiVersion,omitempty"`
Metadata Metadata `yaml:"metadata,omitempty"`
Spec map[string]interface{} `yaml:"spec,omitempty"`
}
type Metadata struct {
Name string `yaml:"name,omitempty"`
Namespace string `yaml:"namespace,omitempty"`
Labels map[string]string `yaml:"labels,omitempty"`
Annotations map[string]string `yaml:"annotations,omitempty"`
}
type DynamicKind struct {
APIVersion, Kind string
}
func (dk DynamicKind) SetGroupVersionKind(gvk schema.GroupVersionKind) {}
func (dk DynamicKind) GroupVersionKind() schema.GroupVersionKind {
return schema.FromAPIVersionAndKind(dk.APIVersion, dk.Kind)
}
type RuntimeObjectWithMetadata interface {
GetObjectMeta() metav1.Object
GetObjectKind() schema.ObjectKind
DeepCopyObject() runtime.Object
}
// +kubebuilder:object:generate=true
type EnvVar struct {
Name string `json:"name,omitempty" yaml:"name,omitempty" protobuf:"bytes,1,opt,name=name"`
Value string `json:"value,omitempty" yaml:"value,omitempty" protobuf:"bytes,2,opt,name=value"`
ValueFrom *EnvVarSource `json:"valueFrom,omitempty" yaml:"valueFrom,omitempty" protobuf:"bytes,3,opt,name=valueFrom"`
}
func (e EnvVar) GetKey() string {
if e.ValueFrom.SecretKeyRef != nil {
return e.ValueFrom.SecretKeyRef.Key
}
if e.ValueFrom.ConfigMapKeyRef != nil {
return e.ValueFrom.ConfigMapKeyRef.Key
}
return ""
}
func (e EnvVar) GetCacheKey() string {
if e.ValueFrom == nil {
return e.Name
}
if e.ValueFrom.SecretKeyRef != nil {
return e.Name + e.ValueFrom.SecretKeyRef.Name + e.ValueFrom.SecretKeyRef.Key
}
if e.ValueFrom.ConfigMapKeyRef != nil {
return e.Name + e.ValueFrom.ConfigMapKeyRef.Name + e.ValueFrom.ConfigMapKeyRef.Key
}
return e.Name
}
func (e EnvVar) IsEmpty() bool {
return e.Value == "" && e.ValueFrom == nil
}
// +kubebuilder:object:generate=true
type EnvVarSource struct {
ConfigMapKeyRef *ConfigMapKeySelector `json:"configMapKeyRef,omitempty" yaml:"configMapKeyRef,omitempty" protobuf:"bytes,3,opt,name=configMapKeyRef"`
SecretKeyRef *SecretKeySelector `json:"secretKeyRef,omitempty" yaml:"secretKeyRef,omitempty" protobuf:"bytes,4,opt,name=secretKeyRef"`
}
// +kubebuilder:object:generate=true
type ConfigMapKeySelector struct {
LocalObjectReference `json:",inline" yaml:",inline" protobuf:"bytes,1,opt,name=localObjectReference"`
Key string `json:"key" yaml:"key" protobuf:"bytes,2,opt,name=key"`
Optional *bool `json:"optional,omitempty" yaml:"optional,omitempty" protobuf:"varint,3,opt,name=optional"`
}
// +kubebuilder:object:generate=true
type SecretKeySelector struct {
LocalObjectReference `json:",inline" yaml:",inline" protobuf:"bytes,1,opt,name=localObjectReference"`
Key string `json:"key" yaml:"key" protobuf:"bytes,2,opt,name=key"`
Optional *bool `json:"optional,omitempty" yaml:"optional,omitempty" protobuf:"varint,3,opt,name=optional"`
}
// +kubebuilder:object:generate=true
type LocalObjectReference struct {
Name string `json:"name,omitempty" yaml:"name,omitempty" protobuf:"bytes,1,opt,name=name"`
}