Skip to content

Commit

Permalink
service type lb support
Browse files Browse the repository at this point in the history
  • Loading branch information
charanm08 authored and arzzon committed Mar 10, 2024
1 parent 1dbddb3 commit e83468e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
1 change: 1 addition & 0 deletions pkg/controller/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const (
TLSNoInsecure = "none"

LBServiceIPAMLabelAnnotation = "cis.f5.com/ipamLabel"
LBServiceIPAnnotation = "cis.f5.com/ip"
LBServiceHostAnnotation = "cis.f5.com/host"
HealthMonitorAnnotation = "cis.f5.com/health"
LBServicePolicyNameAnnotation = "cis.f5.com/policyName"
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/informers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,7 @@ func (ctlr *Controller) enqueueUpdatedService(obj, cur interface{}, clusterName
}

if (svc.Spec.Type != curSvc.Spec.Type && svc.Spec.Type == corev1.ServiceTypeLoadBalancer) ||
(svc.Annotations[LBServiceIPAnnotation] != curSvc.Annotations[LBServiceIPAnnotation]) ||
(svc.Annotations[LBServiceIPAMLabelAnnotation] != curSvc.Annotations[LBServiceIPAMLabelAnnotation]) ||
!reflect.DeepEqual(svc.Labels, curSvc.Labels) || !reflect.DeepEqual(svc.Spec.Ports, curSvc.Spec.Ports) ||
!reflect.DeepEqual(svc.Spec.Selector, curSvc.Spec.Selector) {
Expand Down
61 changes: 32 additions & 29 deletions pkg/controller/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2551,43 +2551,46 @@ func (ctlr *Controller) processLBServices(
isSVCDeleted bool,
) error {

ipamLabel, ok := svc.Annotations[LBServiceIPAMLabelAnnotation]
if !ok {
log.Debugf("Service %v/%v does not have annotation %v, continuing.",
ip, ok1 := svc.Annotations[LBServiceIPAnnotation]
ipamLabel, ok2 := svc.Annotations[LBServiceIPAMLabelAnnotation]
if !ok1 && !ok2 {
log.Debugf("Service %v/%v does not have either of annotation: %v, annotation:%v, continuing.",
svc.Namespace,
svc.Name,
LBServiceIPAMLabelAnnotation,
LBServiceIPAnnotation,
)
return nil
}
if ctlr.ipamCli == nil {
warning := "[IPAM] IPAM is not enabled, Unable to process Services of Type LoadBalancer"
log.Warningf(warning)
prometheus.ConfigurationWarnings.WithLabelValues(Service, svc.ObjectMeta.Namespace, svc.ObjectMeta.Name, warning).Set(1)
return nil
}
prometheus.ConfigurationWarnings.WithLabelValues(Service, svc.ObjectMeta.Namespace, svc.ObjectMeta.Name, "").Set(0)
svcKey := svc.Namespace + "/" + svc.Name + "_svc"
var ip string
var status int
if isSVCDeleted {
ip = ctlr.releaseIP(ipamLabel, "", svcKey)
} else {
ip, status = ctlr.requestIP(ipamLabel, "", svcKey)

switch status {
case NotEnabled:
log.Debug("[IPAM] IPAM Custom Resource Not Available")
return nil
case InvalidInput:
log.Debugf("[IPAM] IPAM Invalid IPAM Label: %v for service: %s/%s", ipamLabel, svc.Namespace, svc.Name)
return nil
case NotRequested:
return fmt.Errorf("[IPAM] unable to make IPAM Request, will be re-requested soon")
case Requested:
log.Debugf("[IPAM] IP address requested for service: %s/%s", svc.Namespace, svc.Name)
if !ok1 {
if ctlr.ipamCli == nil {
warning := "[IPAM] IPAM is not enabled, Unable to process Services of Type LoadBalancer"
log.Warningf(warning)
prometheus.ConfigurationWarnings.WithLabelValues(Service, svc.ObjectMeta.Namespace, svc.ObjectMeta.Name, warning).Set(1)
return nil
}
prometheus.ConfigurationWarnings.WithLabelValues(Service, svc.ObjectMeta.Namespace, svc.ObjectMeta.Name, "").Set(0)
svcKey := svc.Namespace + "/" + svc.Name + "_svc"
var status int
if isSVCDeleted {
ip = ctlr.releaseIP(ipamLabel, "", svcKey)
} else {
ip, status = ctlr.requestIP(ipamLabel, "", svcKey)

switch status {
case NotEnabled:
log.Debug("[IPAM] IPAM Custom Resource Not Available")
return nil
case InvalidInput:
log.Debugf("[IPAM] IPAM Invalid IPAM Label: %v for service: %s/%s", ipamLabel, svc.Namespace, svc.Name)
return nil
case NotRequested:
return fmt.Errorf("[IPAM] unable to make IPAM Request, will be re-requested soon")
case Requested:
log.Debugf("[IPAM] IP address requested for service: %s/%s", svc.Namespace, svc.Name)
return nil
}
}
}

if !isSVCDeleted {
Expand Down

0 comments on commit e83468e

Please sign in to comment.