Skip to content

Commit

Permalink
Adds capability to specify a subnet for the VIP
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Finneran <[email protected]>
  • Loading branch information
thebsdbox committed Nov 7, 2022
1 parent f052777 commit 5e38c81
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pkg/kubevip/config_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ func ParseEnvironment(c *Config) error {
c.VIPCIDR = env
}

// Find vip address subnet
env = os.Getenv(vipSubnet)
if env != "" {
c.VIPSubnet = env
}

// Find Single Node
env = os.Getenv(vipSingleNode)
if env != "" {
Expand Down
5 changes: 4 additions & 1 deletion pkg/kubevip/config_envvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ const (
//vipServicesInterface - defines the interface that the service vips should bind too
vipServicesInterface = "vip_servicesinterface"

//vipCidr - defines the cidr that the vip will use
//vipCidr - defines the cidr that the vip will use (for BGP)
vipCidr = "vip_cidr"

//vipSubnet - defines the subnet that the vip will use
vipSubnet = "vip_subnet"

//egressPodCidr - defines the cidr that egress will ignore
egressPodCidr = "egress_podcidr"

Expand Down
11 changes: 11 additions & 0 deletions pkg/kubevip/config_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,18 @@ func generatePodSpec(c *Config, imageVersion string, inCluster bool) *corev1.Pod
},
}
newEnvironment = append(newEnvironment, cidr...)
}

// If a subnet is required for the VIP
if c.VIPSubnet != "" {
// build environment variables
cidr := []corev1.EnvVar{
{
Name: vipSubnet,
Value: c.VIPSubnet,
},
}
newEnvironment = append(newEnvironment, cidr...)
}

// If we're doing the hybrid mode
Expand Down
7 changes: 6 additions & 1 deletion pkg/manager/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"strings"
"sync"
"time"

log "github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
Expand Down Expand Up @@ -86,6 +87,7 @@ func (sm *Manager) syncServices(ctx context.Context, service *v1.Service, wg *sy
defer wg.Done()

log.Debugf("[STARTING] Service Sync")

// Iterate through the synchronising services
foundInstance := false
newServiceAddress := service.Spec.LoadBalancerIP
Expand Down Expand Up @@ -119,6 +121,8 @@ func (sm *Manager) syncServices(ctx context.Context, service *v1.Service, wg *sy
}

func (sm *Manager) addService(service *v1.Service) error {
startTime := time.Now()

newService, err := NewInstance(service, sm.config)
if err != nil {
return err
Expand Down Expand Up @@ -157,7 +161,8 @@ func (sm *Manager) addService(service *v1.Service) error {
}
}
}
log.Debugf("[COMPLETE] Service Sync")
finishTime := time.Since(startTime)
log.Infof("[service] synchronised in %dms", finishTime.Milliseconds())

return nil
}
Expand Down

0 comments on commit 5e38c81

Please sign in to comment.