-
Notifications
You must be signed in to change notification settings - Fork 277
/
nutanixdatacenterconfig_types.go
177 lines (146 loc) Β· 5.53 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// 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"
"github.com/aws/eks-anywhere/pkg/constants"
)
// 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:Default=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"`
// Insecure is the optional flag to skip TLS verification. Nutanix Prism
// Central installation by default ships with a self-signed certificate
// that will fail TLS verification because the certificate is not issued by
// a public CA and does not have the IP SANs with the Prism Central endpoint.
// To accommodate the scenario where the user has not changed the default
// Certificate that ships with Prism Central, we allow the user to skip TLS
// verification. This is not recommended for production use.
Insecure bool `json:"insecure,omitempty"`
// CredentialRef is the reference to the secret name that contains the credentials
// for the Nutanix Prism Central. The namespace for the secret is assumed to be a constant i.e. eksa-system.
// +optional
CredentialRef *Ref `json:"credentialRef,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)
}
}
if in.Spec.CredentialRef != nil {
if in.Spec.CredentialRef.Kind != constants.SecretKind {
return fmt.Errorf("NutanixDatacenterConfig credentialRef Kind (%s) is not a secret", in.Spec.CredentialRef.Kind)
}
if len(in.Spec.CredentialRef.Name) <= 0 {
return errors.New("NutanixDatacenterConfig credentialRef name is not set or is empty")
}
}
return nil
}
// SetDefaults sets default values for the NutanixDatacenterConfig object.
func (in *NutanixDatacenterConfig) SetDefaults() {
if in.Spec.CredentialRef == nil {
in.Spec.CredentialRef = &Ref{
Kind: constants.SecretKind,
Name: constants.NutanixCredentialsName,
}
}
}
// 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{})
}