-
Notifications
You must be signed in to change notification settings - Fork 274
/
nutanixdatacenterconfig_types.go
140 lines (115 loc) Β· 4.06 KB
/
nutanixdatacenterconfig_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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Important: Run "make generate" to regenerate code after modifying this file
// json tags are required; new fields must have json tags for the fields to be serialized
package v1alpha1
import (
"crypto/x509"
"encoding/pem"
"errors"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// NutanixDatacenterConfigSpec defines the desired state of NutanixDatacenterConfig
type NutanixDatacenterConfigSpec struct {
// Endpoint is the Endpoint of Nutanix Prism Central
// +kubebuilder:validation:Required
Endpoint string `json:"endpoint"`
// Port is the Port of Nutanix Prism Central
// +kubebuilder:validation:Required
// +kubebuilder:validation:Minimum=9440
Port int `json:"port"`
// AdditionalTrustBundle is the optional PEM-encoded certificate bundle for users that
// configured their Prism Central with certificates from non-publicly trusted CAs
AdditionalTrustBundle string `json:"additionalTrustBundle,omitempty"`
}
// NutanixDatacenterConfigStatus defines the observed state of NutanixDatacenterConfig
type NutanixDatacenterConfigStatus struct{}
// NutanixDatacenterConfig is the Schema for the NutanixDatacenterConfigs API
//
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
type NutanixDatacenterConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec NutanixDatacenterConfigSpec `json:"spec,omitempty"`
Status NutanixDatacenterConfigStatus `json:"status,omitempty"`
}
func (in *NutanixDatacenterConfig) Kind() string {
return in.TypeMeta.Kind
}
func (in *NutanixDatacenterConfig) ExpectedKind() string {
return NutanixDatacenterKind
}
func (in *NutanixDatacenterConfig) PauseReconcile() {
if in.Annotations == nil {
in.Annotations = map[string]string{}
}
in.Annotations[pausedAnnotation] = "true"
}
func (in *NutanixDatacenterConfig) IsReconcilePaused() bool {
if s, ok := in.Annotations[pausedAnnotation]; ok {
return s == "true"
}
return false
}
func (in *NutanixDatacenterConfig) ClearPauseAnnotation() {
if in.Annotations != nil {
delete(in.Annotations, pausedAnnotation)
}
}
func (in *NutanixDatacenterConfig) ConvertConfigToConfigGenerateStruct() *NutanixDatacenterConfigGenerate {
namespace := defaultEksaNamespace
if in.Namespace != "" {
namespace = in.Namespace
}
config := &NutanixDatacenterConfigGenerate{
TypeMeta: in.TypeMeta,
ObjectMeta: ObjectMeta{
Name: in.Name,
Annotations: in.Annotations,
Namespace: namespace,
},
Spec: in.Spec,
}
return config
}
func (in *NutanixDatacenterConfig) Marshallable() Marshallable {
return in.ConvertConfigToConfigGenerateStruct()
}
func (in *NutanixDatacenterConfig) Validate() error {
if len(in.Spec.Endpoint) <= 0 {
return errors.New("NutanixDatacenterConfig endpoint is not set or is empty")
}
if in.Spec.Port == 0 {
return errors.New("NutanixDatacenterConfig port is not set or is empty")
}
if len(in.Spec.AdditionalTrustBundle) > 0 {
certPem := []byte(in.Spec.AdditionalTrustBundle)
block, _ := pem.Decode(certPem)
if block == nil {
return errors.New("NutanixDatacenterConfig additionalTrustBundle is not valid: could not find a PEM block in the certificate")
}
if _, err := x509.ParseCertificates(block.Bytes); err != nil {
return fmt.Errorf("NutanixDatacenterConfig additionalTrustBundle is not valid: %s", err)
}
}
return nil
}
// NutanixDatacenterConfigGenerate is same as NutanixDatacenterConfig except stripped down for generation of yaml file during generate clusterconfig
//
// +kubebuilder:object:generate=false
type NutanixDatacenterConfigGenerate struct {
metav1.TypeMeta `json:",inline"`
ObjectMeta `json:"metadata,omitempty"`
Spec NutanixDatacenterConfigSpec `json:"spec,omitempty"`
}
// NutanixDatacenterConfigList contains a list of NutanixDatacenterConfig
//
// +kubebuilder:object:root=true
type NutanixDatacenterConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []NutanixDatacenterConfig `json:"items"`
}
func init() {
SchemeBuilder.Register(&NutanixDatacenterConfig{}, &NutanixDatacenterConfigList{})
}