-
Notifications
You must be signed in to change notification settings - Fork 278
/
snowdatacenterconfig_types.go
118 lines (92 loc) · 3.28 KB
/
snowdatacenterconfig_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package v1alpha1
import (
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
SnowIdentityKind = "Secret"
SnowCredentialsKey = "credentials"
SnowCertificatesKey = "ca-bundle"
)
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
// SnowDatacenterConfigSpec defines the desired state of SnowDatacenterConfig.
type SnowDatacenterConfigSpec struct { // Important: Run "make generate" to regenerate code after modifying this file
// IdentityRef is a reference to an identity for the Snow API to be used when reconciling this cluster
IdentityRef Ref `json:"identityRef,omitempty"`
}
// SnowDatacenterConfigStatus defines the observed state of SnowDatacenterConfig.
type SnowDatacenterConfigStatus struct{}
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// SnowDatacenterConfig is the Schema for the SnowDatacenterConfigs API.
type SnowDatacenterConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec SnowDatacenterConfigSpec `json:"spec,omitempty"`
Status SnowDatacenterConfigStatus `json:"status,omitempty"`
}
func (s *SnowDatacenterConfig) Kind() string {
return s.TypeMeta.Kind
}
func (s *SnowDatacenterConfig) ExpectedKind() string {
return SnowDatacenterKind
}
func (s *SnowDatacenterConfig) PauseReconcile() {
if s.Annotations == nil {
s.Annotations = map[string]string{}
}
s.Annotations[pausedAnnotation] = "true"
}
func (s *SnowDatacenterConfig) ClearPauseAnnotation() {
if s.Annotations != nil {
delete(s.Annotations, pausedAnnotation)
}
}
func (s *SnowDatacenterConfig) Validate() error {
if len(s.Spec.IdentityRef.Name) == 0 {
return fmt.Errorf("SnowDatacenterConfig IdentityRef name must not be empty")
}
if len(s.Spec.IdentityRef.Kind) == 0 {
return fmt.Errorf("SnowDatacenterConfig IdentityRef kind must not be empty")
}
if s.Spec.IdentityRef.Kind != SnowIdentityKind {
return fmt.Errorf("SnowDatacenterConfig IdentityRef kind %s is invalid, the only supported kind is %s", s.Spec.IdentityRef.Kind, SnowIdentityKind)
}
return nil
}
func (s *SnowDatacenterConfig) ConvertConfigToConfigGenerateStruct() *SnowDatacenterConfigGenerate {
namespace := defaultEksaNamespace
if s.Namespace != "" {
namespace = s.Namespace
}
config := &SnowDatacenterConfigGenerate{
TypeMeta: s.TypeMeta,
ObjectMeta: ObjectMeta{
Name: s.Name,
Annotations: s.Annotations,
Namespace: namespace,
},
Spec: s.Spec,
}
return config
}
func (s *SnowDatacenterConfig) Marshallable() Marshallable {
return s.ConvertConfigToConfigGenerateStruct()
}
// +kubebuilder:object:generate=false
// Same as SnowDatacenterConfig except stripped down for generation of yaml file during generate clusterconfig.
type SnowDatacenterConfigGenerate struct {
metav1.TypeMeta `json:",inline"`
ObjectMeta `json:"metadata,omitempty"`
Spec SnowDatacenterConfigSpec `json:"spec,omitempty"`
}
//+kubebuilder:object:root=true
// SnowDatacenterConfigList contains a list of SnowDatacenterConfig.
type SnowDatacenterConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []SnowDatacenterConfig `json:"items"`
}
func init() {
SchemeBuilder.Register(&SnowDatacenterConfig{}, &SnowDatacenterConfigList{})
}