Skip to content

Commit

Permalink
Allow configuration of the subnet the LB is placed in
Browse files Browse the repository at this point in the history
This is an optional parameter that can either be left uninitialized to
keep the old behavior or be set as a helm value or per LB.
  • Loading branch information
malt3 committed Feb 14, 2024
1 parent 69cbb54 commit 6212876
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ yawolFloatingID: <floating-id>
# Placed in LoadBalancer.spec.infrastructure.networkID
yawolNetworkID: <network-id>

# OpenStack subnetwork ID in which the Load Balancer is placed.
# If not set, the subnetwork is chosen automatically.
#
# Placed in LoadBalancer.spec.infrastructure.subnetworkID
yawolSubnetworkID: <subnetwork-id>

# default value for flavor that yawol Load Balancer instances should use
# can be overridden by annotation
#
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/loadbalancer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const (
// If this is set to a different network ID than defined as default in the yawol-cloud-controller
// the default from the yawol-cloud-controller will be added to the additionalNetworks
ServiceDefaultNetworkID = "yawol.stackit.cloud/defaultNetworkID"
// ServiceDefaultSubnetworkID overwrites the default openstack subnetwork for the loadbalancer
ServiceDefaultSubnetworkID = "yawol.stackit.cloud/defaultSubnetworkID"
// ServiceSkipCloudControllerDefaultNetworkID if set to true it do not add the default network ID from
// the yawol-cloud-controller to the additionalNetworks
ServiceSkipCloudControllerDefaultNetworkID = "yawol.stackit.cloud/skipCloudControllerDefaultNetworkID"
Expand Down Expand Up @@ -236,6 +238,9 @@ type LoadBalancerDefaultNetwork struct {
FloatingNetID *string `json:"floatingNetID,omitempty"`
// NetworkID defines an openstack ID for the network.
NetworkID string `json:"networkID"`
// SubnetworkID defines an openstack ID for the subnetwork.
// +optional
SubnetworkID *string `json:"subnetworkID,omitempty"`
}

// OpenstackImageRef defines a reference to a Openstack image.
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

1 change: 1 addition & 0 deletions charts/yawol-controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ Helm chart for yawol-controller
| yawolFloatingID | string | `nil` | |
| yawolImageID | string | `nil` | |
| yawolNetworkID | string | `nil` | |
| yawolSubnetworkID | string | `nil` | |
| yawolOSSecretName | string | `nil` | |

Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ spec:
networkID:
description: NetworkID defines an openstack ID for the network.
type: string
subnetworkID:
description: SubnetworkID defines an openstack ID for the
subnetwork.
type: string
required:
- networkID
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ spec:
networkID:
description: NetworkID defines an openstack ID for the network.
type: string
subnetworkID:
description: SubnetworkID defines an openstack ID for the
subnetwork.
type: string
required:
- networkID
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ spec:
description: NetworkID defines an openstack ID for
the network.
type: string
subnetworkID:
description: SubnetworkID defines an openstack ID
for the subnetwork.
type: string
required:
- networkID
type: object
Expand Down
4 changes: 4 additions & 0 deletions charts/yawol-controller/templates/yawol-cloud-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ spec:
- name: NETWORK_ID
value: {{ .Values.yawolNetworkID }}
{{- end }}
{{- if .Values.yawolSubnetworkID }}
- name: SUBNETWORK_ID
value: {{ .Values.yawolSubnetworkID }}
{{- end }}
{{- if .Values.yawolFlavorID }}
- name: FLAVOR_ID
value: {{ .Values.yawolFlavorID }}
Expand Down
6 changes: 6 additions & 0 deletions charts/yawol-controller/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ yawolFloatingID:
# Placed in LoadBalancer.spec.infrastructure.networkID
yawolNetworkID:

# OpenStack subnetwork ID in which the Load Balancer is placed.
# If not set, the subnetwork is chosen automatically.
#
# Placed in LoadBalancer.spec.infrastructure.subnetworkID
yawolSubnetworkID: <subnetwork-id>

# default value for flavor that yawol Load Balancer instances should use
# can be overridden by annotation
#
Expand Down
4 changes: 4 additions & 0 deletions cmd/yawol-cloud-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const (
EnvFloatingNetID = "FLOATING_NET_ID"
// Openstack NetworkID for LB
EnvNetworkID = "NETWORK_ID"
// OpenStack SubnetworkID for LB
EnvSubnetworkID = "SUBNETWORK_ID"
// Flavor Information
// one must be set
EnvFlavorID = "FLAVOR_ID"
Expand Down Expand Up @@ -300,6 +302,7 @@ func getInfrastructureDefaultsFromEnvOrDie() targetcontroller.InfrastructureDefa
if networkID = os.Getenv(EnvNetworkID); networkID == "" {
panic("could not read env " + EnvNetworkID)
}
subnetworkID := os.Getenv(EnvSubnetworkID)

var clusterNamespace string
if clusterNamespace = os.Getenv(EnvClusterNamespace); clusterNamespace == "" {
Expand Down Expand Up @@ -358,6 +361,7 @@ func getInfrastructureDefaultsFromEnvOrDie() targetcontroller.InfrastructureDefa
AuthSecretName: ptr.To(authSecretName),
FloatingNetworkID: ptr.To(floatingNetworkID),
NetworkID: ptr.To(networkID),
SubnetworkID: ptr.To(subnetworkID),
Namespace: ptr.To(clusterNamespace),
FlavorRef: &yawolv1beta1.OpenstackFlavorRef{
FlavorID: flavorID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type InfrastructureDefaults struct {
AuthSecretName *string
FloatingNetworkID *string
NetworkID *string
SubnetworkID *string
Namespace *string
FlavorRef *yawolv1beta1.OpenstackFlavorRef
ImageRef *yawolv1beta1.OpenstackImageRef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ func getDefaultNetwork(
defaultNetwork := yawolv1beta1.LoadBalancerDefaultNetwork{
FloatingNetID: infraConfig.FloatingNetworkID,
NetworkID: *infraConfig.NetworkID,
SubnetworkID: infraConfig.SubnetworkID,
}

if networkID, ok := svc.Annotations[yawolv1beta1.ServiceDefaultNetworkID]; ok {
Expand All @@ -643,6 +644,10 @@ func getDefaultNetwork(
if floatingID, ok := svc.Annotations[yawolv1beta1.ServiceFloatingNetworkID]; ok {
defaultNetwork.FloatingNetID = &floatingID
}

if subnetworkID, ok := svc.Annotations[yawolv1beta1.ServiceDefaultSubnetworkID]; ok {
defaultNetwork.SubnetworkID = &subnetworkID
}
return defaultNetwork
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,17 @@ func (r *Reconciler) reconcilePort( //nolint: gocyclo // TODO reduce complexity
networkID = lb.Spec.Infrastructure.DefaultNetwork.NetworkID
}

var subnetworkID string
if lb.Spec.Infrastructure.DefaultNetwork.SubnetworkID != nil {
subnetworkID = *lb.Spec.Infrastructure.DefaultNetwork.SubnetworkID
}

port, err = openstackhelper.CreatePort(
ctx,
portClient,
*lb.Status.PortName,
networkID,
subnetworkID,
)
if err != nil {
r.Log.Info("unexpected error occurred claiming a port", "lb", req.NamespacedName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,11 @@ func (r *LoadBalancerMachineReconciler) reconcilePort( //nolint: gocyclo // TODO
return helper.ErrNoNetworkID
}

var subnetworkID string
if lbm.Spec.Infrastructure.DefaultNetwork.SubnetworkID != nil {
subnetworkID = *lbm.Spec.Infrastructure.DefaultNetwork.SubnetworkID
}

var portClient os.PortClient
portClient, err = osClient.PortClient(ctx)
if err != nil {
Expand Down Expand Up @@ -509,7 +514,8 @@ func (r *LoadBalancerMachineReconciler) reconcilePort( //nolint: gocyclo // TODO
ctx,
portClient,
*lbm.Status.DefaultPortName,
networkID)
networkID,
subnetworkID)
if err != nil {
r.Log.Info("unexpected error occurred claiming a port", "lbm", lbm.Name)
return kubernetes.SendErrorAsEvent(r.RecorderLB, err, lbm)
Expand Down
6 changes: 6 additions & 0 deletions internal/helper/openstack/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,17 @@ func CreatePort(
portClient openstack.PortClient,
portName string,
networkID string,
subnetworkID string,
) (*ports.Port, error) {
opts := ports.CreateOpts{
Name: portName,
NetworkID: networkID,
}
if subnetworkID != "" {
opts.FixedIPs = []ports.IP{
{SubnetID: subnetworkID},
}
}
port, err := portClient.Create(ctx, opts)
if err != nil {
return nil, err
Expand Down

0 comments on commit 6212876

Please sign in to comment.