-
Notifications
You must be signed in to change notification settings - Fork 272
/
vspheremachineconfig_types.go
145 lines (117 loc) Β· 3.99 KB
/
vspheremachineconfig_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
package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
// VSphereMachineConfigSpec defines the desired state of VSphereMachineConfig
type VSphereMachineConfigSpec struct {
DiskGiB int `json:"diskGiB,omitempty"`
Datastore string `json:"datastore"`
Folder string `json:"folder"`
NumCPUs int `json:"numCPUs"`
MemoryMiB int `json:"memoryMiB"`
OSFamily OSFamily `json:"osFamily"`
ResourcePool string `json:"resourcePool"`
StoragePolicyName string `json:"storagePolicyName,omitempty"`
Template string `json:"template,omitempty"`
Users []UserConfiguration `json:"users,omitempty"`
}
func (c *VSphereMachineConfig) PauseReconcile() {
c.Annotations[pausedAnnotation] = "true"
}
func (c *VSphereMachineConfig) IsReconcilePaused() bool {
if s, ok := c.Annotations[pausedAnnotation]; ok {
return s == "true"
}
return false
}
func (c *VSphereMachineConfig) SetControlPlane() {
c.Annotations[controlPlaneAnnotation] = "true"
}
func (c *VSphereMachineConfig) IsControlPlane() bool {
if s, ok := c.Annotations[controlPlaneAnnotation]; ok {
return s == "true"
}
return false
}
func (c *VSphereMachineConfig) SetEtcd() {
c.Annotations[etcdAnnotation] = "true"
}
func (c *VSphereMachineConfig) IsEtcd() bool {
if s, ok := c.Annotations[etcdAnnotation]; ok {
return s == "true"
}
return false
}
func (c *VSphereMachineConfig) SetManagedBy(clusterName string) {
if c.Annotations == nil {
c.Annotations = map[string]string{}
}
c.Annotations[managementAnnotation] = clusterName
}
// IsManaged returns true if the vspheremachineconfig is associated with a workload cluster
func (c *VSphereMachineConfig) IsManaged() bool {
if s, ok := c.Annotations[managementAnnotation]; ok {
return s != ""
}
return false
}
func (c *VSphereMachineConfig) OSFamily() OSFamily {
return c.Spec.OSFamily
}
func (c *VSphereMachineConfig) GetNamespace() string {
return c.Namespace
}
func (c *VSphereMachineConfig) GetName() string {
return c.Name
}
// VSphereMachineConfigStatus defines the observed state of VSphereMachineConfig
type VSphereMachineConfigStatus struct{}
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// VSphereMachineConfig is the Schema for the vspheremachineconfigs API
type VSphereMachineConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec VSphereMachineConfigSpec `json:"spec,omitempty"`
Status VSphereMachineConfigStatus `json:"status,omitempty"`
}
func (c *VSphereMachineConfig) ConvertConfigToConfigGenerateStruct() *VSphereMachineConfigGenerate {
namespace := defaultEksaNamespace
if c.Namespace != "" {
namespace = c.Namespace
}
config := &VSphereMachineConfigGenerate{
TypeMeta: c.TypeMeta,
ObjectMeta: ObjectMeta{
Name: c.Name,
Annotations: c.Annotations,
Namespace: namespace,
},
Spec: c.Spec,
}
return config
}
func (c *VSphereMachineConfig) Marshallable() Marshallable {
return c.ConvertConfigToConfigGenerateStruct()
}
func (c *VSphereMachineConfig) Validate() error {
return nil
}
// +kubebuilder:object:generate=false
// Same as VSphereMachineConfig except stripped down for generation of yaml file during generate clusterconfig
type VSphereMachineConfigGenerate struct {
metav1.TypeMeta `json:",inline"`
ObjectMeta `json:"metadata,omitempty"`
Spec VSphereMachineConfigSpec `json:"spec,omitempty"`
}
//+kubebuilder:object:root=true
// VSphereMachineConfigList contains a list of VSphereMachineConfig
type VSphereMachineConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []VSphereMachineConfig `json:"items"`
}
func init() {
SchemeBuilder.Register(&VSphereMachineConfig{}, &VSphereMachineConfigList{})
}