Skip to content

Commit 8ae1fdc

Browse files
committed
apis: support both yaml and json in types.go
1 parent 7424efd commit 8ae1fdc

1 file changed

Lines changed: 43 additions & 43 deletions

File tree

apis/v1/types.go

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,25 @@ type Application struct {
3737

3838
// ApplicationSpec defines the desired state of an Application
3939
type ApplicationSpec struct {
40-
Project string `yaml:"project"` // CloudStack project ID or name
41-
Components []ComponentRef `yaml:"components" gorm:"serializer:json"` // Dependent components (ordered)
40+
Project string `json:"project,omitempty" yaml:"project"` // CloudStack project ID or name
41+
Components []ComponentRef `json:"components,omitempty" yaml:"components" gorm:"serializer:json"` // Dependent components (ordered)
4242
}
4343

4444
// ComponentRef references a Component within an Application
4545
type ComponentRef struct {
46-
Name string `yaml:"name"` // Component name
47-
VirtualMachineSpec string `yaml:"virtualMachineSpec"` // Reusable VM spec name
48-
Replicas int `yaml:"replicas"` // Number of VM replicas
49-
HealthChecks []HealthCheck `yaml:"healthChecks,omitempty" gorm:"serializer:json"`
46+
Name string `json:"name" yaml:"name"` // Component name
47+
VirtualMachineSpec string `json:"virtualMachineSpec" yaml:"virtualMachineSpec"` // Reusable VM spec name
48+
Replicas int `json:"replicas" yaml:"replicas"` // Number of VM replicas
49+
HealthChecks []HealthCheck `json:"healthChecks,omitempty" yaml:"healthChecks,omitempty" gorm:"serializer:json"`
5050
}
5151

5252
// HealthCheck defines a simple health check configuration for VMs
5353
type HealthCheck struct {
54-
Type string `yaml:"type"` // e.g. ping, http
55-
Interval string `yaml:"interval,omitempty"` // e.g. 10s
56-
Timeout string `yaml:"timeout,omitempty"` // e.g. 5s
57-
Path string `yaml:"path,omitempty"` // HTTP path for http checks
58-
Port int `yaml:"port,omitempty"` // Optional port for TCP/HTTP checks
54+
Type string `json:"type" yaml:"type"` // e.g. ping, http
55+
Interval string `json:"interval,omitempty" yaml:"interval,omitempty"` // e.g. 10s
56+
Timeout string `json:"timeout,omitempty" yaml:"timeout,omitempty"` // e.g. 5s
57+
Path string `json:"path,omitempty" yaml:"path,omitempty"` // HTTP path for http checks
58+
Port int `json:"port,omitempty" yaml:"port,omitempty"` // Optional port for TCP/HTTP checks
5959
}
6060

6161
// Component represents a set of VMs for a specific role (e.g. frontend/backend)
@@ -74,18 +74,18 @@ type Component struct {
7474

7575
// ComponentSpec defines the desired state of a Component
7676
type ComponentSpec struct {
77-
VirtualMachineSpec string `yaml:"virtualMachineSpec"` // Reusable VM spec name
78-
Replicas int `yaml:"replicas"` // Number of VM replicas
79-
Overrides ComponentOverrides `yaml:"overrides,omitempty" gorm:"serializer:json"`
80-
HealthChecks []HealthCheck `yaml:"healthChecks,omitempty" gorm:"serializer:json"`
77+
VirtualMachineSpec string `json:"virtualMachineSpec" yaml:"virtualMachineSpec"` // Reusable VM spec name
78+
Replicas int `json:"replicas" yaml:"replicas"` // Number of VM replicas
79+
Overrides ComponentOverrides `json:"overrides,omitempty" yaml:"overrides,omitempty" gorm:"serializer:json"`
80+
HealthChecks []HealthCheck `json:"healthChecks,omitempty" yaml:"healthChecks,omitempty" gorm:"serializer:json"`
8181
}
8282

8383
// ComponentOverrides allows limited, safe overrides to a reused VM spec
8484
type ComponentOverrides struct {
85-
UserDataRefs []string `yaml:"userDataRefs,omitempty" gorm:"serializer:json"`
86-
SSHKeys []string `yaml:"sshKeys,omitempty" gorm:"serializer:json"`
87-
SecurityGroups []string `yaml:"securityGroups,omitempty" gorm:"serializer:json"`
88-
AffinityGroups []string `yaml:"affinityGroups,omitempty" gorm:"serializer:json"`
85+
UserDataRefs []string `json:"userDataRefs,omitempty" yaml:"userDataRefs,omitempty" gorm:"serializer:json"`
86+
SSHKeys []string `json:"sshKeys,omitempty" yaml:"sshKeys,omitempty" gorm:"serializer:json"`
87+
SecurityGroups []string `json:"securityGroups,omitempty" yaml:"securityGroups,omitempty" gorm:"serializer:json"`
88+
AffinityGroups []string `json:"affinityGroups,omitempty" yaml:"affinityGroups,omitempty" gorm:"serializer:json"`
8989
}
9090

9191
// VirtualMachine represents an individual VM instance in CloudStack
@@ -102,19 +102,19 @@ type VirtualMachine struct {
102102

103103
// VirtualMachineSpec defines reusable VM configuration (template/offering/network)
104104
type VirtualMachineSpec struct {
105-
Zone string `yaml:"zone"` // CloudStack zone ID or name
106-
Project string `yaml:"project"` // CloudStack project ID or name
107-
Template string `yaml:"template"` // VM template name/ID
108-
ServiceOffering string `yaml:"serviceOffering"` // VM service offering (size)
109-
NetworkIDs []string `yaml:"networkIds" gorm:"serializer:json"` // Attached networks
110-
SSHKeys []string `yaml:"sshKeys" gorm:"serializer:json"` // SSH keys for access
111-
SecurityGroups []string `yaml:"securityGroups" gorm:"serializer:json"` // Firewall groups
112-
AffinityGroups []string `yaml:"affinityGroups" gorm:"serializer:json"` // Host/VM affinity rules
113-
UserDataRefs []string `yaml:"userDataRefs,omitempty" gorm:"serializer:json"` // Optional references to UserData resources
114-
Volumes []VolumeSpec `yaml:"volumes,omitempty" gorm:"serializer:json"` // Desired or observed attached volumes
115-
HealthChecks []HealthCheck `yaml:"healthChecks,omitempty" gorm:"serializer:json"`
105+
Zone string `json:"zone,omitempty" yaml:"zone"` // CloudStack zone ID or name
106+
Project string `json:"project,omitempty" yaml:"project"` // CloudStack project ID or name
107+
Template string `json:"template,omitempty" yaml:"template"` // VM template name/ID
108+
ServiceOffering string `json:"serviceOffering,omitempty" yaml:"serviceOffering"` // VM service offering (size)
109+
NetworkIDs []string `json:"networkIds,omitempty" yaml:"networkIds" gorm:"serializer:json"` // Attached networks
110+
SSHKeys []string `json:"sshKeys,omitempty" yaml:"sshKeys" gorm:"serializer:json"` // SSH keys for access
111+
SecurityGroups []string `json:"securityGroups,omitempty" yaml:"securityGroups" gorm:"serializer:json"` // Firewall groups
112+
AffinityGroups []string `json:"affinityGroups,omitempty" yaml:"affinityGroups" gorm:"serializer:json"` // Host/VM affinity rules
113+
UserDataRefs []string `json:"userDataRefs,omitempty" yaml:"userDataRefs,omitempty" gorm:"serializer:json"` // Optional references to UserData resources
114+
Volumes []VolumeSpec `json:"volumes,omitempty" yaml:"volumes,omitempty" gorm:"serializer:json"` // Desired or observed attached volumes
115+
HealthChecks []HealthCheck `json:"healthChecks,omitempty" yaml:"healthChecks,omitempty" gorm:"serializer:json"`
116116
// Parameters allows passing provider-specific deploy-time options
117-
Parameters map[string]string `yaml:"parameters,omitempty" gorm:"serializer:json"`
117+
Parameters map[string]string `json:"parameters,omitempty" yaml:"parameters,omitempty" gorm:"serializer:json"`
118118
}
119119

120120
// VirtualMachineSpecResource is the persisted wrapper for reusable VM specs
@@ -139,15 +139,15 @@ type Network struct {
139139

140140
// NetworkSpec defines the desired state of a Network
141141
type NetworkSpec struct {
142-
Zone string `yaml:"zone"` // CloudStack zone ID or name
143-
NetworkOffering string `yaml:"networkOffering,omitempty"` // Network offering ID or name for creation
144-
Vlan interface{} `yaml:"vlan,omitempty"` // Optional VLAN tag for shared networks; may be string or number
145-
BypassVlanOverlapCheck bool `yaml:"bypassVlanOverlapCheck,omitempty"` // When true, do not normalize or validate VLAN value
146-
Description string `yaml:"description,omitempty"` // Human-friendly description / displayText
147-
Gateway string `yaml:"gateway,omitempty"` // Gateway IP for shared networks
148-
Netmask string `yaml:"netmask,omitempty"` // Netmask for shared networks
149-
StartIP string `yaml:"startIp,omitempty"` // Start IP for static IP range (shared network)
150-
EndIP string `yaml:"endIp,omitempty"` // End IP for static IP range (shared network)
142+
Zone string `json:"zone,omitempty" yaml:"zone"` // CloudStack zone ID or name
143+
NetworkOffering string `json:"networkOffering,omitempty" yaml:"networkOffering,omitempty"` // Network offering ID or name for creation
144+
Vlan interface{} `json:"vlan,omitempty" yaml:"vlan,omitempty"` // Optional VLAN tag for shared networks; may be string or number
145+
BypassVlanOverlapCheck bool `json:"bypassVlanOverlapCheck,omitempty" yaml:"bypassVlanOverlapCheck,omitempty"` // When true, do not normalize or validate VLAN value
146+
Description string `json:"description,omitempty" yaml:"description,omitempty"` // Human-friendly description / displayText
147+
Gateway string `json:"gateway,omitempty" yaml:"gateway,omitempty"` // Gateway IP for shared networks
148+
Netmask string `json:"netmask,omitempty" yaml:"netmask,omitempty"` // Netmask for shared networks
149+
StartIP string `json:"startIp,omitempty" yaml:"startIp,omitempty"` // Start IP for static IP range (shared network)
150+
EndIP string `json:"endIp,omitempty" yaml:"endIp,omitempty"` // End IP for static IP range (shared network)
151151
}
152152

153153
// Volume represents a disk attached to a VM in CloudStack
@@ -184,7 +184,7 @@ type SSHKey struct {
184184

185185
// SSHKeySpec holds the public key material for registering an SSH keypair
186186
type SSHKeySpec struct {
187-
PublicKey string `yaml:"publicKey"`
187+
PublicKey string `json:"publicKey,omitempty" yaml:"publicKey"`
188188
}
189189

190190
// SecurityGroup represents a firewall rule set for VMs in CloudStack
@@ -208,7 +208,7 @@ type AffinityGroup struct {
208208

209209
// AffinitySpec defines the type of affinity rule
210210
type AffinitySpec struct {
211-
Type string `yaml:"type"` // hostAntiAffinity/hostAffinity
211+
Type string `json:"type,omitempty" yaml:"type"` // hostAntiAffinity/hostAffinity
212212
}
213213

214214
// UserData represents initialization scripts for VMs in CloudStack
@@ -222,7 +222,7 @@ type UserData struct {
222222

223223
// UserDataSpec defines the initialization script content
224224
type UserDataSpec struct {
225-
Script string `yaml:"script"` // Base64-encoded user data script
225+
Script string `json:"script,omitempty" yaml:"script"` // Base64-encoded user data script
226226
}
227227

228228
// TableName overrides to ensure consistent table names across DB operations

0 commit comments

Comments
 (0)