-
Notifications
You must be signed in to change notification settings - Fork 277
/
vspheredatacenterconfig_types.go
149 lines (116 loc) Β· 4.28 KB
/
vspheredatacenterconfig_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
package v1alpha1
import (
"errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/aws/eks-anywhere/pkg/logger"
)
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
// VSphereDatacenterConfigSpec defines the desired state of VSphereDatacenterConfig.
type VSphereDatacenterConfigSpec struct {
// Important: Run "make generate" to regenerate code after modifying this file
Datacenter string `json:"datacenter"`
Network string `json:"network"`
Server string `json:"server"`
Thumbprint string `json:"thumbprint"`
Insecure bool `json:"insecure"`
}
// VSphereDatacenterConfigStatus defines the observed state of VSphereDatacenterConfig.
type VSphereDatacenterConfigStatus struct { // Important: Run "make generate" to regenerate code after modifying this file
// SpecValid is set to true if vspheredatacenterconfig is validated.
SpecValid bool `json:"specValid,omitempty"`
// ObservedGeneration is the latest generation observed by the controller.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// FailureMessage indicates that there is a fatal problem reconciling the
// state, and will be set to a descriptive error message.
FailureMessage *string `json:"failureMessage,omitempty"`
}
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// VSphereDatacenterConfig is the Schema for the VSphereDatacenterConfigs API.
type VSphereDatacenterConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec VSphereDatacenterConfigSpec `json:"spec,omitempty"`
Status VSphereDatacenterConfigStatus `json:"status,omitempty"`
}
func (v *VSphereDatacenterConfig) Kind() string {
return v.TypeMeta.Kind
}
func (v *VSphereDatacenterConfig) ExpectedKind() string {
return VSphereDatacenterKind
}
func (v *VSphereDatacenterConfig) PauseReconcile() {
if v.Annotations == nil {
v.Annotations = map[string]string{}
}
v.Annotations[pausedAnnotation] = "true"
}
func (v *VSphereDatacenterConfig) IsReconcilePaused() bool {
if s, ok := v.Annotations[pausedAnnotation]; ok {
return s == "true"
}
return false
}
func (v *VSphereDatacenterConfig) ClearPauseAnnotation() {
if v.Annotations != nil {
delete(v.Annotations, pausedAnnotation)
}
}
func (v *VSphereDatacenterConfig) SetDefaults() {
v.Spec.Network = generateFullVCenterPath(networkFolderType, v.Spec.Network, v.Spec.Datacenter)
if v.Spec.Insecure {
logger.Info("Warning: VSphereDatacenterConfig configured in insecure mode")
v.Spec.Thumbprint = ""
}
}
func (v *VSphereDatacenterConfig) Validate() error {
if len(v.Spec.Server) <= 0 {
return errors.New("VSphereDatacenterConfig server is not set or is empty")
}
if len(v.Spec.Datacenter) <= 0 {
return errors.New("VSphereDatacenterConfig datacenter is not set or is empty")
}
if len(v.Spec.Network) <= 0 {
return errors.New("VSphereDatacenterConfig VM network is not set or is empty")
}
if err := validatePath(networkFolderType, v.Spec.Network, v.Spec.Datacenter); err != nil {
return err
}
return nil
}
func (v *VSphereDatacenterConfig) ConvertConfigToConfigGenerateStruct() *VSphereDatacenterConfigGenerate {
namespace := defaultEksaNamespace
if v.Namespace != "" {
namespace = v.Namespace
}
config := &VSphereDatacenterConfigGenerate{
TypeMeta: v.TypeMeta,
ObjectMeta: ObjectMeta{
Name: v.Name,
Annotations: v.Annotations,
Namespace: namespace,
},
Spec: v.Spec,
}
return config
}
func (v *VSphereDatacenterConfig) Marshallable() Marshallable {
return v.ConvertConfigToConfigGenerateStruct()
}
// +kubebuilder:object:generate=false
// Same as VSphereDatacenterConfig except stripped down for generation of yaml file during generate clusterconfig.
type VSphereDatacenterConfigGenerate struct {
metav1.TypeMeta `json:",inline"`
ObjectMeta `json:"metadata,omitempty"`
Spec VSphereDatacenterConfigSpec `json:"spec,omitempty"`
}
//+kubebuilder:object:root=true
// VSphereDatacenterConfigList contains a list of VSphereDatacenterConfig.
type VSphereDatacenterConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []VSphereDatacenterConfig `json:"items"`
}
func init() {
SchemeBuilder.Register(&VSphereDatacenterConfig{}, &VSphereDatacenterConfigList{})
}