Skip to content

Commit

Permalink
fix: ssset better errors, doc and validation (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiGuranIonos authored Jun 6, 2024
1 parent f0c58a5 commit 33e507b
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 63 deletions.
13 changes: 4 additions & 9 deletions apis/compute/v1alpha1/serverset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type ServerSetTemplateSpec struct {
// NICs are the network interfaces of the server.
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinItems=1
NICs []ServerSetTemplateNIC `json:"nics,omitempty"`
NICs []ServerSetTemplateNIC `json:"nics"`
}

// ServerSetTemplateNIC are the configurable fields of a ServerSetTemplateNIC.
Expand All @@ -94,15 +94,10 @@ type ServerSetTemplateNIC struct {
DHCPv6 *bool `json:"dhcpv6"`
// +kubebuilder:validation:Optional
VNetID string `json:"vnetId,omitempty"`
// The Referenced LAN must be created before the ServerSet is applied
//
// +kubebuilder:validation:Required
Reference string `json:"reference"`
}

// ServerSetTemplateVolumeMount are the configurable fields of a ServerSetTemplateVolumeMount.
// It is used to mount a volume to a server.
type ServerSetTemplateVolumeMount struct {
// +kubebuilder:validation:Required
Reference string `json:"reference"`
LanReference string `json:"lanReference"`
}

// ServerSetTemplate are the configurable fields of a ServerSetTemplate.
Expand Down
15 changes: 0 additions & 15 deletions apis/compute/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions cluster/local/integration_tests_serverset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ spec:
nics:
- name: nic-sample
dhcp: false
reference: examplelan
lanReference: examplelan
bootVolumeTemplate:
metadata:
name: volumeboot
Expand Down Expand Up @@ -131,7 +131,7 @@ spec:
nics:
- name: nic-sample
dhcp: true
reference: examplelan
lanReference: examplelan
bootVolumeTemplate:
metadata:
name: volumeboot
Expand Down Expand Up @@ -218,7 +218,7 @@ spec:
nics:
- name: nic-sample
dhcp: true
reference: examplelan
lanReference: examplelan
bootVolumeTemplate:
metadata:
name: volumeboot
Expand Down
6 changes: 4 additions & 2 deletions docs/api/compute-engine/serverset.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,17 @@ available CPU architectures can be retrieved from the datacenter resource.
* properties:
* `dhcp` (boolean)
* `dhcpv6` (boolean)
* `lanReference` (string)
* description: The Referenced LAN must be created before the ServerSet is applied
* `name` (string)
* description: Name of the NIC. Replica index, NIC index, and version are appended to the name. Resulting name will be in format: {name}-{replicaIndex}-{nicIndex}-{version}.
Version increases if the NIC is re-created due to an immutable field changing. E.g. if the bootvolume type or image are changed and the strategy is createAllBeforeDestroy, the NIC is re-created and the version is increased.
* pattern: [a-z0-9]([-a-z0-9]*[a-z0-9])?
* `reference` (string)
* `vnetId` (string)
* required properties:
* `dhcp`
* `lanReference`
* `name`
* `reference`
* `ram` (integer)
* description: The memory size for the server in MB, such as 2048. Size must be specified in multiples of 256 MB with a minimum of 256 MB.
however, if you set ramHotPlug to TRUE then you must use a minimum of 1024 MB. If you set the RAM size more than 240GB,
Expand All @@ -272,6 +273,7 @@ then ramHotPlug will be set to FALSE and can not be set to TRUE unless RAM size
* multiple of: 1024.000000
* required properties:
* `cores`
* `nics`
* `ram`
* required properties:
* `metadata`
Expand Down
6 changes: 4 additions & 2 deletions docs/api/compute-engine/statefulserverset.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,17 @@ available CPU architectures can be retrieved from the datacenter resource.
* properties:
* `dhcp` (boolean)
* `dhcpv6` (boolean)
* `lanReference` (string)
* description: The Referenced LAN must be created before the ServerSet is applied
* `name` (string)
* description: Name of the NIC. Replica index, NIC index, and version are appended to the name. Resulting name will be in format: {name}-{replicaIndex}-{nicIndex}-{version}.
Version increases if the NIC is re-created due to an immutable field changing. E.g. if the bootvolume type or image are changed and the strategy is createAllBeforeDestroy, the NIC is re-created and the version is increased.
* pattern: [a-z0-9]([-a-z0-9]*[a-z0-9])?
* `reference` (string)
* `vnetId` (string)
* required properties:
* `dhcp`
* `lanReference`
* `name`
* `reference`
* `ram` (integer)
* description: The memory size for the server in MB, such as 2048. Size must be specified in multiples of 256 MB with a minimum of 256 MB.
however, if you set ramHotPlug to TRUE then you must use a minimum of 1024 MB. If you set the RAM size more than 240GB,
Expand All @@ -298,6 +299,7 @@ then ramHotPlug will be set to FALSE and can not be set to TRUE unless RAM size
* multiple of: 1024.000000
* required properties:
* `cores`
* `nics`
* `ram`
* required properties:
* `metadata`
Expand Down
12 changes: 8 additions & 4 deletions examples/ionoscloud/compute/serverset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ spec:
providerConfigRef:
name: example
forProvider:
replicas: 2
replicas: 1
datacenterConfig:
datacenterIdRef:
name: example
Expand All @@ -81,9 +81,13 @@ spec:
ram: 1024
nics:
- name: nic-sample
dhcp: true
# vnetId: "3330fa34-927f-11ee-8008-6202af74e858"
reference: examplelan
dhcp: false
# needs to be created before serverset. Serverset will not wait until it is populated
lanReference: examplelan
- name: nic-sample2
dhcp: false
dhcpv6: true
lanReference: examplelan2
bootVolumeTemplate:
metadata:
name: volumeboot
Expand Down
3 changes: 2 additions & 1 deletion examples/ionoscloud/compute/statefulserverset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ spec:
dhcp: false
dhcpv6: false
# should reference lan metadata name
reference: customer
# needs to be created before serverset. StatefulServerset will not wait until it is populated
lanReference: customer
bootVolumeTemplate:
metadata:
name: boot-volume
Expand Down
7 changes: 6 additions & 1 deletion internal/clients/compute/nic/nic.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ func GenerateUpdateNicInput(cr *v1alpha1.Nic, ips []string) (*sdkgo.NicPropertie
Lan: &lanID,
FirewallActive: &cr.Spec.ForProvider.FirewallActive,
Dhcp: &cr.Spec.ForProvider.Dhcp,
Dhcpv6: cr.Spec.ForProvider.DhcpV6,
}

if cr.Spec.ForProvider.DhcpV6 == nil {
instanceUpdateInput.SetDhcpv6Nil()
} else {
instanceUpdateInput.Dhcpv6 = cr.Spec.ForProvider.DhcpV6
}

if cr.Spec.ForProvider.Name != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ func (k *kubeLANController) isAvailable(ctx context.Context, name, namespace str
return false, err
}
if !kube.IsSuccessfullyCreated(obj) {
return false, kube.ErrExternalCreateFailed
conditions := obj.Status.ResourceStatus.Conditions
return false, fmt.Errorf("reason %s %w", conditions[len(conditions)-1].Message, kube.ErrExternalCreateFailed)
}
if obj != nil && obj.Status.AtProvider.LanID != "" && strings.EqualFold(obj.Status.AtProvider.State, ionoscloud.Available) {
return true, nil
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/compute/statefulserverset/objects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ func createSSetTemplate() v1alpha1.ServerSetTemplate {
RAM: serverRAM,
NICs: []v1alpha1.ServerSetTemplateNIC{
{
Name: nicName,
DHCP: true,
Reference: nicLAN,
Name: nicName,
DHCP: true,
LanReference: nicLAN,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func (k *kubeServerSetController) isAvailable(ctx context.Context, name, namespa
return false, nil
}
if !kube.IsSuccessfullyCreated(obj) {
// todo add here the internal ReconcileError if possible
return false, kube.ErrExternalCreateFailed
conditions := obj.Status.ResourceStatus.Conditions
return false, fmt.Errorf("reason %s %w", conditions[len(conditions)-1].Message, kube.ErrExternalCreateFailed)
}
if (len(obj.Status.AtProvider.ReplicaStatuses) == obj.Spec.ForProvider.Replicas) &&
(obj.GetCondition(xpv1.TypeReady).Equal(xpv1.Available())) {
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/serverset/bootvolume_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ func (k *kubeBootVolumeController) isAvailable(ctx context.Context, name, namesp
return false, err
}
if !kube.IsSuccessfullyCreated(obj) {
return false, kube.ErrExternalCreateFailed
conditions := obj.Status.ResourceStatus.Conditions
return false, fmt.Errorf("reason %s %w", conditions[len(conditions)-1].Message, kube.ErrExternalCreateFailed)
}
if obj != nil && obj.Status.AtProvider.VolumeID != "" && strings.EqualFold(obj.Status.AtProvider.State, ionoscloud.Available) {
return true, nil
Expand Down
5 changes: 3 additions & 2 deletions internal/controller/serverset/nic_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func (k *kubeNicController) isAvailable(ctx context.Context, name, namespace str
return false, err
}
if !kube.IsSuccessfullyCreated(obj) {
return false, kube.ErrExternalCreateFailed
conditions := obj.Status.ResourceStatus.Conditions
return false, fmt.Errorf("reason %s %w", conditions[len(conditions)-1].Message, kube.ErrExternalCreateFailed)
}

if obj != nil && obj.Status.AtProvider.NicID != "" && strings.EqualFold(obj.Status.AtProvider.State, ionoscloud.Available) {
Expand Down Expand Up @@ -184,7 +185,7 @@ func (k *kubeNicController) EnsureNICs(ctx context.Context, cr *v1alpha1.ServerS
// check if the NIC is attached to the server
if len(servers) > 0 {
for nicx := range cr.Spec.ForProvider.Template.Spec.NICs {
if err := k.ensure(ctx, cr, servers[0].Status.AtProvider.ServerID, cr.Spec.ForProvider.Template.Spec.NICs[nicx].Reference, replicaIndex, nicx, version); err != nil {
if err := k.ensure(ctx, cr, servers[0].Status.AtProvider.ServerID, cr.Spec.ForProvider.Template.Spec.NICs[nicx].LanReference, replicaIndex, nicx, version); err != nil {
return err
}
}
Expand Down
8 changes: 4 additions & 4 deletions internal/controller/serverset/nic_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ func createServerSetWithoutVNetAndIPV4() *v1alpha1.ServerSet {
s := createBasicServerSet()
s.Spec.ForProvider.Template.Spec.NICs = []v1alpha1.ServerSetTemplateNIC{
{
Name: "nic2",
DHCP: false,
Reference: "data",
Name: "nic2",
DHCP: false,
LanReference: "data",
},
}
return s
Expand All @@ -229,7 +229,7 @@ func createServerSetWithDhcpV6() *v1alpha1.ServerSet {
s := createBasicServerSet()
for nicIndex := range s.Spec.ForProvider.Template.Spec.NICs {
s.Spec.ForProvider.Template.Spec.NICs[nicIndex].DHCPv6 = ionoscloud.PtrBool(true)
s.Spec.ForProvider.Template.Spec.NICs[nicIndex].Reference = dataLAN
s.Spec.ForProvider.Template.Spec.NICs[nicIndex].LanReference = dataLAN
}
return s
}
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/serverset/server_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func (k *kubeServerController) isAvailable(ctx context.Context, name, namespace
}
}
if !kube.IsSuccessfullyCreated(obj) {
return false, kube.ErrExternalCreateFailed
conditions := obj.Status.ResourceStatus.Conditions
return false, fmt.Errorf("reason %s %w", conditions[len(conditions)-1].Message, kube.ErrExternalCreateFailed)
}
if obj.Status.AtProvider.ServerID != "" && strings.EqualFold(obj.Status.AtProvider.State, ionoscloud.Available) {
return true, nil
Expand Down
12 changes: 6 additions & 6 deletions internal/controller/serverset/serverset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1916,9 +1916,9 @@ func createBasicServerSet() *v1alpha1.ServerSet {
CPUFamily: serverSetCPUFamily,
NICs: []v1alpha1.ServerSetTemplateNIC{
{
Name: "nic1",
DHCP: false,
Reference: "user",
Name: "nic1",
DHCP: false,
LanReference: "user",
},
},
},
Expand Down Expand Up @@ -2008,9 +2008,9 @@ func createServerSetWithNrOfNICsUpdated() *v1alpha1.ServerSet {
sset := createBasicServerSet()
sset.Spec.ForProvider.Template.Spec.NICs = append(
sset.Spec.ForProvider.Template.Spec.NICs, v1alpha1.ServerSetTemplateNIC{
Name: "nic2",
DHCP: true,
Reference: "management",
Name: "nic2",
DHCP: true,
LanReference: "management",
})

return sset
Expand Down
9 changes: 6 additions & 3 deletions package/crds/compute.ionoscloud.crossplane.io_serversets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -419,21 +419,23 @@ spec:
type: boolean
dhcpv6:
type: boolean
lanReference:
description: The Referenced LAN must be created
before the ServerSet is applied
type: string
name:
description: |-
Name of the NIC. Replica index, NIC index, and version are appended to the name. Resulting name will be in format: {name}-{replicaIndex}-{nicIndex}-{version}.
Version increases if the NIC is re-created due to an immutable field changing. E.g. if the bootvolume type or image are changed and the strategy is createAllBeforeDestroy, the NIC is re-created and the version is increased.
maxLength: 50
pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?'
type: string
reference:
type: string
vnetId:
type: string
required:
- dhcp
- lanReference
- name
- reference
type: object
x-kubernetes-validations:
- message: Only one of 'dhcp' or 'dhcpv6' can be set
Expand All @@ -452,6 +454,7 @@ spec:
type: integer
required:
- cores
- nics
- ram
type: object
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,21 +470,23 @@ spec:
type: boolean
dhcpv6:
type: boolean
lanReference:
description: The Referenced LAN must be created
before the ServerSet is applied
type: string
name:
description: |-
Name of the NIC. Replica index, NIC index, and version are appended to the name. Resulting name will be in format: {name}-{replicaIndex}-{nicIndex}-{version}.
Version increases if the NIC is re-created due to an immutable field changing. E.g. if the bootvolume type or image are changed and the strategy is createAllBeforeDestroy, the NIC is re-created and the version is increased.
maxLength: 50
pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?'
type: string
reference:
type: string
vnetId:
type: string
required:
- dhcp
- lanReference
- name
- reference
type: object
x-kubernetes-validations:
- message: Only one of 'dhcp' or 'dhcpv6' can be set
Expand All @@ -503,6 +505,7 @@ spec:
type: integer
required:
- cores
- nics
- ram
type: object
required:
Expand Down

0 comments on commit 33e507b

Please sign in to comment.