Skip to content

Commit dbaca3c

Browse files
committed
WIP - move ports out of instance
1 parent a873934 commit dbaca3c

19 files changed

+1064
-488
lines changed

api/v1alpha5/conversion.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,3 +437,14 @@ func Convert_v1alpha5_OpenStackClusterStatus_To_v1alpha7_OpenStackClusterStatus(
437437
func Convert_v1alpha7_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in *infrav1.OpenStackMachineSpec, out *OpenStackMachineSpec, s conversion.Scope) error {
438438
return autoConvert_v1alpha7_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in, out, s)
439439
}
440+
441+
func Convert_v1alpha7_OpenStackMachineStatus_To_v1alpha5_OpenStackMachineStatus(in *infrav1.OpenStackMachineStatus, out *OpenStackMachineStatus, s conversion.Scope) error {
442+
err := autoConvert_v1alpha7_OpenStackMachineStatus_To_v1alpha5_OpenStackMachineStatus(in, out, s)
443+
if err != nil {
444+
return err
445+
}
446+
447+
in.PortsStatus = nil
448+
449+
return nil
450+
}

api/v1alpha5/zz_generated.conversion.go

Lines changed: 6 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha6/conversion.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,14 @@ func Convert_v1alpha6_OpenStackClusterStatus_To_v1alpha7_OpenStackClusterStatus(
659659
func Convert_v1alpha7_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in *infrav1.OpenStackMachineSpec, out *OpenStackMachineSpec, s apiconversion.Scope) error {
660660
return autoConvert_v1alpha7_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in, out, s)
661661
}
662+
663+
func Convert_v1alpha7_OpenStackMachineStatus_To_v1alpha6_OpenStackMachineStatus(in *infrav1.OpenStackMachineStatus, out *OpenStackMachineStatus, s apiconversion.Scope) error {
664+
err := autoConvert_v1alpha7_OpenStackMachineStatus_To_v1alpha6_OpenStackMachineStatus(in, out, s)
665+
if err != nil {
666+
return err
667+
}
668+
669+
in.PortsStatus = nil
670+
671+
return nil
672+
}

api/v1alpha6/zz_generated.conversion.go

Lines changed: 6 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha7/conditions_consts.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ const (
2222
// InstanceReadyCondition reports on current status of the OpenStack instance. Ready indicates the instance is in a Running state.
2323
InstanceReadyCondition clusterv1.ConditionType = "InstanceReady"
2424

25+
// PortsReadyCondition reports on the current status of the ports. Ready indicates that all ports have been created
26+
// successfully and ready to be attached to the instance.
27+
PortsReadyCondition clusterv1.ConditionType = "PortsReady"
28+
2529
// WaitingForClusterInfrastructureReason used when machine is waiting for cluster infrastructure to be ready before proceeding.
2630
WaitingForClusterInfrastructureReason = "WaitingForClusterInfrastructure"
2731
// WaitingForBootstrapDataReason used when machine is waiting for bootstrap data to be ready before proceeding.
@@ -42,6 +46,10 @@ const (
4246
InstanceDeleteFailedReason = "InstanceDeleteFailed"
4347
// OpenstackErrorReason used when there is an error communicating with OpenStack.
4448
OpenStackErrorReason = "OpenStackError"
49+
// PortsCreateFailedReason used when creating the ports failed.
50+
PortsCreateFailedReason = "PortsCreateFailed"
51+
// PortsDeleteFailedReason used when deleting the ports failed.
52+
PortsDeleteFailedReason = "PortsDeleteFailed"
4553
)
4654

4755
const (

api/v1alpha7/openstackmachine_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ type OpenStackMachineStatus struct {
113113

114114
FailureReason *errors.MachineStatusError `json:"failureReason,omitempty"`
115115

116+
// PortsStatus is the status of the ports associated with the machine.
117+
// +optional
118+
PortsStatus []PortStatus `json:"portsStatus,omitempty"`
119+
116120
// FailureMessage will be set in the event that there is a terminal problem
117121
// reconciling the Machine and will contain a more verbose string suitable
118122
// for logging and human consumption.

api/v1alpha7/types.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ type PortOpts struct {
128128
ValueSpecs []ValueSpec `json:"valueSpecs,omitempty"`
129129
}
130130

131+
type PortStatus struct {
132+
// ID is the unique identifier of the port.
133+
// +optional
134+
ID string `json:"id,omitempty"`
135+
}
136+
131137
type BindingProfile struct {
132138
// OVSHWOffload enables or disables the OVS hardware offload feature.
133139
OVSHWOffload bool `json:"ovsHWOffload,omitempty"`
@@ -149,12 +155,13 @@ type AddressPair struct {
149155
}
150156

151157
type BastionStatus struct {
152-
ID string `json:"id,omitempty"`
153-
Name string `json:"name,omitempty"`
154-
SSHKeyName string `json:"sshKeyName,omitempty"`
155-
State InstanceState `json:"state,omitempty"`
156-
IP string `json:"ip,omitempty"`
157-
FloatingIP string `json:"floatingIP,omitempty"`
158+
ID string `json:"id,omitempty"`
159+
Name string `json:"name,omitempty"`
160+
SSHKeyName string `json:"sshKeyName,omitempty"`
161+
State InstanceState `json:"state,omitempty"`
162+
PortsStatus PortStatus `json:"portsStatus,omitempty"`
163+
IP string `json:"ip,omitempty"`
164+
FloatingIP string `json:"floatingIP,omitempty"`
158165
}
159166

160167
type RootVolume struct {

api/v1alpha7/zz_generated.deepcopy.go

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4404,6 +4404,12 @@ spec:
44044404
type: string
44054405
name:
44064406
type: string
4407+
portsStatus:
4408+
properties:
4409+
id:
4410+
description: ID is the unique identifier of the port.
4411+
type: string
4412+
type: object
44074413
sshKeyName:
44084414
type: string
44094415
state:

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,16 @@ spec:
16031603
description: InstanceState is the state of the OpenStack instance
16041604
for this machine.
16051605
type: string
1606+
portsStatus:
1607+
description: PortsStatus is the status of the ports associated with
1608+
the machine.
1609+
items:
1610+
properties:
1611+
id:
1612+
description: ID is the unique identifier of the port.
1613+
type: string
1614+
type: object
1615+
type: array
16061616
ready:
16071617
description: Ready is true when the provider resource is ready.
16081618
type: boolean

controllers/openstackcluster_controller.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (r *OpenStackClusterReconciler) reconcileDelete(ctx context.Context, scope
179179
return ctrl.Result{}, fmt.Errorf("failed to delete router: %w", err)
180180
}
181181

182-
if err = networkingService.DeletePorts(openStackCluster); err != nil {
182+
if err = networkingService.DeleteClusterPorts(openStackCluster); err != nil {
183183
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to delete ports: %w", err))
184184
return reconcile.Result{}, fmt.Errorf("failed to delete ports: %w", err)
185185
}
@@ -239,7 +239,7 @@ func deleteBastion(scope scope.Scope, cluster *clusterv1.Cluster, openStackClust
239239

240240
instanceSpec := bastionToInstanceSpec(openStackCluster, cluster.Name)
241241

242-
if err = computeService.DeleteInstance(openStackCluster, openStackCluster, instanceStatus, instanceSpec); err != nil {
242+
if err = computeService.DeleteInstance(openStackCluster, instanceStatus, instanceSpec); err != nil {
243243
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to delete bastion: %w", err))
244244
return fmt.Errorf("failed to delete bastion: %w", err)
245245
}
@@ -320,6 +320,8 @@ func reconcileBastion(scope scope.Scope, cluster *clusterv1.Cluster, openStackCl
320320
return err
321321
}
322322

323+
// TODO(emilien) Create ports for bastion host
324+
323325
instanceSpec := bastionToInstanceSpec(openStackCluster, cluster.Name)
324326
bastionHash, err := compute.HashInstanceSpec(instanceSpec)
325327
if err != nil {
@@ -349,7 +351,7 @@ func reconcileBastion(scope scope.Scope, cluster *clusterv1.Cluster, openStackCl
349351
}
350352
}
351353

352-
instanceStatus, err = computeService.CreateInstance(openStackCluster, openStackCluster, instanceSpec, cluster.Name)
354+
instanceStatus, err = computeService.CreateInstance(openStackCluster, openStackCluster, instanceSpec, cluster.Name, []string{})
353355
if err != nil {
354356
return fmt.Errorf("failed to reconcile bastion: %w", err)
355357
}
@@ -398,18 +400,30 @@ func bastionToInstanceSpec(openStackCluster *infrav1.OpenStackCluster, clusterNa
398400
RootVolume: openStackCluster.Spec.Bastion.Instance.RootVolume,
399401
}
400402

401-
instanceSpec.SecurityGroups = openStackCluster.Spec.Bastion.Instance.SecurityGroups
403+
instanceSpec.SecurityGroups = getBastionSecurityGroups(openStackCluster)
404+
405+
instanceSpec.Ports = openStackCluster.Spec.Bastion.Instance.Ports
406+
407+
return instanceSpec
408+
}
409+
410+
// getBastionSecurityGroups returns a combination of openStackCluster.Spec.Bastion.Instance.SecurityGroups
411+
// and the security group managed by the OpenStackCluster.
412+
func getBastionSecurityGroups(openStackCluster *infrav1.OpenStackCluster) []infrav1.SecurityGroupFilter {
413+
instanceSpecSecurityGroups := openStackCluster.Spec.Bastion.Instance.SecurityGroups
414+
var managedSecurityGroup string
402415
if openStackCluster.Spec.ManagedSecurityGroups {
403416
if openStackCluster.Status.BastionSecurityGroup != nil {
404-
instanceSpec.SecurityGroups = append(instanceSpec.SecurityGroups, infrav1.SecurityGroupFilter{
405-
ID: openStackCluster.Status.BastionSecurityGroup.ID,
406-
})
417+
managedSecurityGroup = openStackCluster.Status.BastionSecurityGroup.ID
407418
}
408419
}
409420

410-
instanceSpec.Ports = openStackCluster.Spec.Bastion.Instance.Ports
411-
412-
return instanceSpec
421+
if managedSecurityGroup != "" {
422+
instanceSpecSecurityGroups = append(instanceSpecSecurityGroups, infrav1.SecurityGroupFilter{
423+
ID: managedSecurityGroup,
424+
})
425+
}
426+
return instanceSpecSecurityGroups
413427
}
414428

415429
// bastionHashHasChanged returns a boolean whether if the latest bastion hash, built from the instance spec, has changed or not.

0 commit comments

Comments
 (0)