Skip to content

Commit 47a418d

Browse files
Harvey Lowndesayushverma14
Harvey Lowndes
authored andcommitted
Allow load balancer functionality to be disabled (oracle#199)
1 parent 0e756fd commit 47a418d

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

pkg/oci/ccm.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func NewCloudProvider(config *Config) (cloudprovider.Interface, error) {
8787
config.CompartmentID = metadata.CompartmentOCID
8888
}
8989

90-
if config.VCNID == "" {
90+
if !config.LoadBalancer.Disabled && config.VCNID == "" {
9191
glog.Infof("No vcn provided in cloud provider config. Falling back to looking up VCN via LB subnet.")
9292
subnet, err := c.Networking().GetSubnet(context.Background(), config.LoadBalancer.Subnet1)
9393
if err != nil {
@@ -136,17 +136,19 @@ func (cp *CloudProvider) Initialize(clientBuilder controller.ControllerClientBui
136136
}
137137
cp.NodeLister = nodeInformer.Lister()
138138

139-
var serviceInformer informersv1.ServiceInformer
140-
if cp.config.LoadBalancer.SecurityListManagementMode != ManagementModeNone {
141-
serviceInformer = factory.Core().V1().Services()
142-
go serviceInformer.Informer().Run(wait.NeverStop)
143-
glog.Info("Waiting for service informer cache to sync")
144-
if !cache.WaitForCacheSync(wait.NeverStop, serviceInformer.Informer().HasSynced) {
145-
utilruntime.HandleError(fmt.Errorf("Timed out waiting for service informer to sync"))
146-
}
139+
if !cp.config.LoadBalancer.Disabled {
140+
var serviceInformer informersv1.ServiceInformer
141+
if cp.config.LoadBalancer.SecurityListManagementMode != ManagementModeNone {
142+
serviceInformer = factory.Core().V1().Services()
143+
go serviceInformer.Informer().Run(wait.NeverStop)
144+
glog.Info("Waiting for service informer cache to sync")
145+
if !cache.WaitForCacheSync(wait.NeverStop, serviceInformer.Informer().HasSynced) {
146+
utilruntime.HandleError(fmt.Errorf("Timed out waiting for service informer to sync"))
147+
}
147148

149+
}
150+
cp.securityListManager = newSecurityListManager(cp.client, serviceInformer.Lister(), cp.config.LoadBalancer.SecurityLists, cp.config.LoadBalancer.SecurityListManagementMode)
148151
}
149-
cp.securityListManager = newSecurityListManager(cp.client, serviceInformer.Lister(), cp.config.LoadBalancer.SecurityLists, cp.config.LoadBalancer.SecurityListManagementMode)
150152
}
151153

152154
// ProviderName returns the cloud-provider ID.
@@ -158,7 +160,7 @@ func (cp *CloudProvider) ProviderName() string {
158160
// is supported, false otherwise.
159161
func (cp *CloudProvider) LoadBalancer() (cloudprovider.LoadBalancer, bool) {
160162
glog.V(6).Info("Claiming to support Load Balancers")
161-
return cp, true
163+
return cp, !cp.config.LoadBalancer.Disabled
162164
}
163165

164166
// Instances returns an instances interface. Also returns true if the interface

pkg/oci/config.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ type AuthConfig struct {
4242

4343
// LoadBalancerConfig holds the configuration options for OCI load balancers.
4444
type LoadBalancerConfig struct {
45+
// Disabled disables the creation of a load balancer.
46+
Disabled bool `yaml:"disabled"`
47+
4548
// DisableSecurityListManagement disables the automatic creation of ingress
4649
// rules for the node subnets and egress rules for the load balancers to the node subnets.
4750
//
@@ -80,7 +83,7 @@ type Config struct {
8083

8184
// Complete the config applying defaults / overrides.
8285
func (c *Config) Complete() {
83-
if c.LoadBalancer.SecurityListManagementMode == "" {
86+
if !c.LoadBalancer.Disabled && c.LoadBalancer.SecurityListManagementMode == "" {
8487
c.LoadBalancer.SecurityListManagementMode = ManagementModeAll // default
8588
if c.LoadBalancer.DisableSecurityListManagement {
8689
glog.Warningf("cloud-provider config: \"loadBalancer.disableSecurityListManagement\" is DEPRECIATED and will be removed in a later release. Please set \"loadBalancer.SecurityListManagementMode: %s\".", ManagementModeNone)

pkg/oci/config_validate.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ func validateLoadBalancerConfig(c *Config, fldPath *field.Path) field.ErrorList
8383
func ValidateConfig(c *Config) field.ErrorList {
8484
allErrs := field.ErrorList{}
8585
allErrs = append(allErrs, validateAuthConfig(&c.Auth, field.NewPath("auth"))...)
86-
allErrs = append(allErrs, validateLoadBalancerConfig(c, field.NewPath("loadBalancer"))...)
86+
if !c.LoadBalancer.Disabled {
87+
allErrs = append(allErrs, validateLoadBalancerConfig(c, field.NewPath("loadBalancer"))...)
88+
}
8789
return allErrs
8890
}

0 commit comments

Comments
 (0)