Skip to content

Commit

Permalink
Merge pull request #28 from thebsdbox/global
Browse files Browse the repository at this point in the history
A global cidr config can transend all namespaces
  • Loading branch information
thebsdbox authored Nov 9, 2020
2 parents a615e86 + ecec3dc commit 4ccb07a
Showing 1 changed file with 33 additions and 29 deletions.
62 changes: 33 additions & 29 deletions pkg/plndrcp/loadBalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,48 +117,26 @@ func (plb *plndrLoadBalancerManager) syncLoadBalancer(service *v1.Service) (*v1.
// Get the clound controller configuration map
cm, err := plb.GetConfigMap(PlunderCloudConfig, "kube-system")
if err != nil {
klog.Errorf("Unable to retrieve services from configMap [%s] in kube-system", PlunderClientConfig)
// TODO - determine best course of action, create one if it doesn't exist
cm, err = plb.CreateConfigMap(PlunderCloudConfig, "kube-system")
if err != nil {
return nil, err
}
}

// This function reconciles the load balancer state
klog.Infof("syncing service '%s' (%s) with", service.Name, service.UID)

// Find the services configuraiton in the configMap
svc, err := plb.GetServices(cm)
if err != nil {
klog.Errorf("Unable to retrieve services from configMap [%s]", PlunderClientConfig)

// TODO best course of action, currently we create a new services config
svc = &plndrServices{}
}

// Check for existing configuration

existing := svc.findService(string(service.UID))
if existing != nil {
klog.Infof("found existing service '%s' (%s) with vip %s", service.Name, service.UID, existing.Vip)
return &v1.LoadBalancerStatus{
Ingress: []v1.LoadBalancerIngress{
{
IP: existing.Vip,
},
},
}, nil
}

var vip, cidrRange string
var ok bool
// Build cidr key for this service
cidrKey := fmt.Sprintf("cidr-%s", service.Namespace)
if cidrRange, ok = cm.Data[cidrKey]; !ok {
return nil, fmt.Errorf("No cidr configuration for namespace [%s] exists in key [%s] configmap [%s]", service.Namespace, cidrKey, plb.cloudConfigMap)

if cidrRange, ok = cm.Data["cidr-global"]; !ok {
return nil, fmt.Errorf("No cidr configuration for namespace [%s] exists in key [%s] configmap [%s]", service.Namespace, cidrKey, plb.cloudConfigMap)
}
klog.Infof("Taking address from [cidr-global] pool")
} else {
klog.Infof("Taking address from [%s] pool", cidrKey)
}

// Check if we're not explicitly specifying an address to use, if not then use iPAM to find an address
if service.Spec.LoadBalancerIP == "" {
vip, err = ipam.FindAvailableHost(service.Namespace, cidrRange)
Expand All @@ -180,6 +158,32 @@ func (plb *plndrLoadBalancerManager) syncLoadBalancer(service *v1.Service) (*v1.
}
}

// This function reconciles the load balancer state
klog.Infof("syncing service '%s' (%s)", service.Name, service.UID)

// Find the services configuraiton in the configMap
svc, err := plb.GetServices(cm)
if err != nil {
klog.Errorf("Unable to retrieve services from configMap [%s], [%s]", PlunderClientConfig, err.Error())

// TODO best course of action, currently we create a new services config
svc = &plndrServices{}
}

// Check for existing configuration

existing := svc.findService(string(service.UID))
if existing != nil {
klog.Infof("found existing service '%s' (%s) with vip %s", service.Name, service.UID, existing.Vip)
return &v1.LoadBalancerStatus{
Ingress: []v1.LoadBalancerIngress{
{
IP: existing.Vip,
},
},
}, nil
}

// TODO - manage more than one set of ports
newSvc := services{
ServiceName: service.Name,
Expand Down

0 comments on commit 4ccb07a

Please sign in to comment.