Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gthiemonge committed Sep 19, 2024
1 parent 406840f commit b6a0040
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 32 deletions.
1 change: 0 additions & 1 deletion api/bases/octavia.openstack.org_octavias.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ spec:
Attachment Definition
type: string
manageLbMgmtNetworks:
default: true
type: boolean
type: object
nodeSelector:
Expand Down
5 changes: 2 additions & 3 deletions api/v1beta1/octavia_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,11 @@ type PasswordSelector struct {
// OctaviaLbMgmtNetworks Settings for Octavia management networks
type OctaviaLbMgmtNetworks struct {
// +kubebuilder:validation:Optional
// +kubebuilder:default=true
ManageLbMgmtNetworks bool `json:"manageLbMgmtNetworks,omitempty"`
ManageLbMgmtNetworks bool `json:"manageLbMgmtNetworks"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=true
CreateDefaultLbMgmtNetwork bool `json:"createDefaultLbMgmtNetwork,omitempty"`
CreateDefaultLbMgmtNetwork bool `json:"createDefaultLbMgmtNetwork"`

// +kubebuilder:validation:Optional
// LbMgmtRouterGateway is the IP address of the Octavia router on the
Expand Down
1 change: 0 additions & 1 deletion config/crd/bases/octavia.openstack.org_octavias.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ spec:
Attachment Definition
type: string
manageLbMgmtNetworks:
default: true
type: boolean
type: object
nodeSelector:
Expand Down
61 changes: 42 additions & 19 deletions controllers/octavia_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,25 +660,48 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav
return ctrl.Result{}, err
}

// Create load balancer management network and get its Id (networkInfo is actually a struct and contains
// multiple details.
networkInfo, err := octavia.EnsureAmphoraManagementNetwork(
ctx,
instance.Namespace,
instance.Spec.TenantName,
&instance.Spec.LbMgmtNetworks,
networkParameters,
&Log,
helper,
)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
octaviav1.OctaviaManagementNetworkReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
octaviav1.OctaviaManagementNetworkReadyErrorMessage,
err.Error()))
return ctrl.Result{}, err
var networkInfo octavia.NetworkProvisioningSummary

if instance.Spec.LbMgmtNetworks.ManageLbMgmtNetworks == true {
// Create load balancer management network and get its Id (networkInfo is actually a struct and contains
// multiple details.
networkInfo, err = octavia.EnsureAmphoraManagementNetwork(
ctx,
instance.Namespace,
instance.Spec.TenantName,
&instance.Spec.LbMgmtNetworks,
networkParameters,
&Log,
helper,
)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
octaviav1.OctaviaManagementNetworkReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
octaviav1.OctaviaManagementNetworkReadyErrorMessage,
err.Error()))
return ctrl.Result{}, err
}
} else {
networkInfo, err = octavia.HandleUnmanagedAmphoraManagementNetwork(
ctx,
instance.Namespace,
instance.Spec.TenantName,
&instance.Spec.LbMgmtNetworks,
networkParameters,
&Log,
helper,
)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
octaviav1.OctaviaManagementNetworkReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
octaviav1.OctaviaManagementNetworkReadyErrorMessage,
err.Error()))
return ctrl.Result{}, err
}
}
instance.Status.Conditions.MarkTrue(octaviav1.OctaviaManagementNetworkReadyCondition, octaviav1.OctaviaManagementNetworkReadyCompleteMessage)
Log.Info(fmt.Sprintf("Using management network \"%s\"", networkInfo.TenantNetworkID))
Expand Down
39 changes: 31 additions & 8 deletions pkg/octavia/lb_mgmt_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ import (
// Type for conveying the results of the EnsureAmphoraManagementNetwork call.
type NetworkProvisioningSummary struct {
TenantNetworkID string
TenantSubnetID string
ProviderNetworkID string
RouterID string
SecurityGroupID string
ManagementSubnetCIDR string
ManagementSubnetGateway string
Expand Down Expand Up @@ -805,6 +802,37 @@ func ensureSecurityGroup(
return secGroup.ID, nil
}

func HandleUnmanagedAmphoraManagementNetwork(
ctx context.Context,
ns string,
tenantName string,
netDetails *octaviav1.OctaviaLbMgmtNetworks,
networkParameters *NetworkParameters,
log *logr.Logger,
helper *helper.Helper,
) (NetworkProvisioningSummary, error) {
// o, err := GetOpenstackClient(ctx, ns, helper)
// if err != nil {
// return NetworkProvisioningSummary{}, err
// }
// client, err := GetNetworkClient(o)
// if err != nil {
// return NetworkProvisioningSummary{}, err
// }
// serviceTenant, err := GetProject(o, tenantName)
// if err != nil {
// return NetworkProvisioningSummary{}, err
// }

return NetworkProvisioningSummary{
TenantNetworkID: "",
SecurityGroupID: "",
ManagementSubnetCIDR: "",
ManagementSubnetGateway: "",
ManagementSubnetExtraCIDRs: []string{},
}, nil
}

// EnsureAmphoraManagementNetwork - retrieve, create and reconcile the Octavia management network for the in cluster link to the
// management tenant network.
func EnsureAmphoraManagementNetwork(
Expand Down Expand Up @@ -844,7 +872,6 @@ func EnsureAmphoraManagementNetwork(
var tenantSubnet *subnets.Subnet
var tenantRouterPort *ports.Port
tenantNetworkID := ""
tenantSubnetID := ""

if netDetails.CreateDefaultLbMgmtNetwork {
tenantNetwork, err = ensureLbMgmtNetwork(client, nil, netDetails, serviceTenant.ID, log)
Expand All @@ -857,7 +884,6 @@ func EnsureAmphoraManagementNetwork(
if err != nil {
return NetworkProvisioningSummary{}, err
}
tenantSubnetID = tenantSubnet.ID

tenantRouterPort, _, err = ensurePort(client, nil, tenantNetwork, &securityGroups, log)
if err != nil {
Expand Down Expand Up @@ -997,9 +1023,6 @@ func EnsureAmphoraManagementNetwork(

return NetworkProvisioningSummary{
TenantNetworkID: tenantNetworkID,
TenantSubnetID: tenantSubnetID,
ProviderNetworkID: providerNetwork.ID,
RouterID: router.ID,
SecurityGroupID: lbMgmtSecurityGroupID,
ManagementSubnetCIDR: managementSubnetCIDR,
ManagementSubnetGateway: networkParameters.ProviderGateway.String(),
Expand Down

0 comments on commit b6a0040

Please sign in to comment.