Skip to content

Commit 9cad9ca

Browse files
authored
Merge pull request #4 from Junsheng-Wu/eks
Add DisableFloatingIP to openstackCluster spec
2 parents 41d01d4 + 5edb8d4 commit 9cad9ca

File tree

5 files changed

+50
-26
lines changed

5 files changed

+50
-26
lines changed

api/v1alpha6/openstackcluster_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ type OpenStackClusterSpec struct {
6363
// +optional
6464
APIServerLoadBalancer APIServerLoadBalancer `json:"apiServerLoadBalancer,omitempty"`
6565

66+
// DisableFloatingIP determines whether or not to attempt to attach a floating
67+
// IP to the Instance.
68+
DisableFloatingIP bool `json:"disableFloatingIP"`
69+
6670
// DisableAPIServerFloatingIP determines whether or not to attempt to attach a floating
6771
// IP to the API server. This allows for the creation of clusters when attaching a floating
6872
// IP to the API server (and hence, in many cases, exposing the API server to the internet)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4771,6 +4771,10 @@ spec:
47714771
fail without additional configuration to manage the VIP on the control
47724772
plane machines, which falls outside of the scope of this controller.
47734773
type: boolean
4774+
disableFloatingIP:
4775+
description: DisableFloatingIP determines whether or not to attempt
4776+
to attach a floating IP to the Instance.
4777+
type: boolean
47744778
disablePortSecurity:
47754779
description: DisablePortSecurity disables the port security of the
47764780
network created for the Kubernetes cluster, which also disables
@@ -4932,6 +4936,8 @@ spec:
49324936
type: string
49334937
type: array
49344938
x-kubernetes-list-type: set
4939+
required:
4940+
- disableFloatingIP
49354941
type: object
49364942
status:
49374943
description: OpenStackClusterStatus defines the observed state of OpenStackCluster.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,10 @@ spec:
20112011
configuration to manage the VIP on the control plane machines,
20122012
which falls outside of the scope of this controller.
20132013
type: boolean
2014+
disableFloatingIP:
2015+
description: DisableFloatingIP determines whether or not to
2016+
attempt to attach a floating IP to the Instance.
2017+
type: boolean
20142018
disablePortSecurity:
20152019
description: DisablePortSecurity disables the port security
20162020
of the network created for the Kubernetes cluster, which
@@ -2177,6 +2181,8 @@ spec:
21772181
type: string
21782182
type: array
21792183
x-kubernetes-list-type: set
2184+
required:
2185+
- disableFloatingIP
21802186
type: object
21812187
required:
21822188
- spec

controllers/openstackcluster_controller.go

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -344,35 +344,37 @@ func reconcileBastion(scope *scope.Scope, cluster *clusterv1.Cluster, openStackC
344344
if err != nil {
345345
return errors.Errorf("failed to reconcile bastion: %v", err)
346346
}
347+
if !openStackCluster.Spec.DisableFloatingIP {
348+
networkingService, err := networking.NewService(scope)
349+
if err != nil {
350+
return err
351+
}
352+
clusterName := fmt.Sprintf("%s-%s", cluster.Namespace, cluster.Name)
353+
fp, err := networkingService.GetOrCreateFloatingIP(openStackCluster, openStackCluster, clusterName, openStackCluster.Spec.Bastion.Instance.FloatingIP)
354+
if err != nil {
355+
handleUpdateOSCError(openStackCluster, errors.Errorf("failed to get or create floating IP for bastion: %v", err))
356+
return errors.Errorf("failed to get or create floating IP for bastion: %v", err)
357+
}
358+
port, err := computeService.GetManagementPort(openStackCluster, instanceStatus)
359+
if err != nil {
360+
err = errors.Errorf("getting management port for bastion: %v", err)
361+
handleUpdateOSCError(openStackCluster, err)
362+
return err
363+
}
364+
err = networkingService.AssociateFloatingIP(openStackCluster, fp, port.ID)
365+
if err != nil {
366+
handleUpdateOSCError(openStackCluster, errors.Errorf("failed to associate floating IP with bastion: %v", err))
367+
return errors.Errorf("failed to associate floating IP with bastion: %v", err)
368+
}
347369

348-
networkingService, err := networking.NewService(scope)
349-
if err != nil {
350-
return err
351-
}
352-
clusterName := fmt.Sprintf("%s-%s", cluster.Namespace, cluster.Name)
353-
fp, err := networkingService.GetOrCreateFloatingIP(openStackCluster, openStackCluster, clusterName, openStackCluster.Spec.Bastion.Instance.FloatingIP)
354-
if err != nil {
355-
handleUpdateOSCError(openStackCluster, errors.Errorf("failed to get or create floating IP for bastion: %v", err))
356-
return errors.Errorf("failed to get or create floating IP for bastion: %v", err)
357-
}
358-
port, err := computeService.GetManagementPort(openStackCluster, instanceStatus)
359-
if err != nil {
360-
err = errors.Errorf("getting management port for bastion: %v", err)
361-
handleUpdateOSCError(openStackCluster, err)
362-
return err
363-
}
364-
err = networkingService.AssociateFloatingIP(openStackCluster, fp, port.ID)
365-
if err != nil {
366-
handleUpdateOSCError(openStackCluster, errors.Errorf("failed to associate floating IP with bastion: %v", err))
367-
return errors.Errorf("failed to associate floating IP with bastion: %v", err)
370+
bastion, err := instanceStatus.APIInstance(openStackCluster)
371+
if err != nil {
372+
return err
373+
}
374+
bastion.FloatingIP = fp.FloatingIP
375+
openStackCluster.Status.Bastion = bastion
368376
}
369377

370-
bastion, err := instanceStatus.APIInstance(openStackCluster)
371-
if err != nil {
372-
return err
373-
}
374-
bastion.FloatingIP = fp.FloatingIP
375-
openStackCluster.Status.Bastion = bastion
376378
annotations.AddAnnotations(openStackCluster, map[string]string{BastionInstanceHashAnnotation: bastionHash})
377379
return nil
378380
}

pkg/cloud/services/networking/network.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ func (c createOpts) ToNetworkCreateMap() (map[string]interface{}, error) {
4242
}
4343

4444
func (s *Service) ReconcileExternalNetwork(openStackCluster *infrav1.OpenStackCluster) error {
45+
if openStackCluster.Spec.DisableFloatingIP {
46+
openStackCluster.Status.ExternalNetwork = &infrav1.Network{}
47+
s.scope.Logger.Info("External network was disabled - proceeding with internal network only")
48+
return nil
49+
}
50+
4551
if openStackCluster.Spec.ExternalNetworkID != "" {
4652
externalNetwork, err := s.getNetworkByID(openStackCluster.Spec.ExternalNetworkID)
4753
if err != nil {

0 commit comments

Comments
 (0)