Skip to content

Commit

Permalink
loxilb-io/loxilb#877 egress support - wait for egress crd until created
Browse files Browse the repository at this point in the history
  • Loading branch information
TrekkieCoder committed Jan 3, 2025
1 parent 4b05824 commit 9838f91
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cmd/loxilb-agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ func run(o *Options) error {

egressMgr := egress.NewEgressManager(
k8sClient,
k8sExtClient,
egressClient,
networkConfig,
egressInformer,
Expand Down Expand Up @@ -294,8 +295,7 @@ func run(o *Options) error {
}

go loxilbURLMgr.Start(loxilbURLInformerFactory, stopCh, loxiLBLiveCh, loxiLBDeadCh, loxiLBPurgeCh)
egressInformerFactory.Start(stopCh)
go egressMgr.Run(stopCh)
go egressMgr.Start(egressInformerFactory, stopCh)

// Run gateway API managers
if o.config.EnableGatewayAPI {
Expand Down
28 changes: 28 additions & 0 deletions pkg/agent/manager/egress/egress.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ import (
"github.com/loxilb-io/kube-loxilb/pkg/api"
crdv1 "github.com/loxilb-io/kube-loxilb/pkg/crds/egress/v1"
"github.com/loxilb-io/kube-loxilb/pkg/egress-client/clientset/versioned"
egressCRDinformers "github.com/loxilb-io/kube-loxilb/pkg/egress-client/informers/externalversions"
crdInformer "github.com/loxilb-io/kube-loxilb/pkg/egress-client/informers/externalversions/egress/v1"
crdLister "github.com/loxilb-io/kube-loxilb/pkg/egress-client/listers/egress/v1"
apiextensionclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
Expand All @@ -45,6 +48,7 @@ const (

type Manager struct {
kubeClient kubernetes.Interface
kubeExtClient apiextensionclientset.Interface
crdClient versioned.Interface
EgressInformer crdInformer.EgressInformer
EgressLister crdLister.EgressLister
Expand All @@ -57,6 +61,7 @@ type Manager struct {
// Manager is called by kube-loxilb when k8s service is created & updated.
func NewEgressManager(
kubeClient kubernetes.Interface,
kubeExtClient apiextensionclientset.Interface,
crdClient versioned.Interface,
networkConfig *config.NetworkConfig,
EgressInformer crdInformer.EgressInformer,
Expand All @@ -65,6 +70,7 @@ func NewEgressManager(

manager := &Manager{
kubeClient: kubeClient,
kubeExtClient: kubeExtClient,
crdClient: crdClient,
EgressInformer: EgressInformer,
EgressLister: EgressInformer.Lister(),
Expand Down Expand Up @@ -126,6 +132,28 @@ func (m *Manager) Run(stopCh <-chan struct{}) {
<-stopCh
}

func (m *Manager) WaitForLoxiEgressCRDCreation(stopCh <-chan struct{}) {

wait.PollImmediateUntil(time.Second*5,
func() (bool, error) {
_, err := m.kubeExtClient.ApiextensionsV1().CustomResourceDefinitions().
Get(context.TODO(), "egresses.egress.loxilb.io", metav1.GetOptions{})
if err != nil {
return false, nil
}
klog.Infof("loxilb-egress crd created")
return true, nil
},
stopCh)
}

func (m *Manager) Start(informer egressCRDinformers.SharedInformerFactory, stopCh <-chan struct{}) {

m.WaitForLoxiEgressCRDCreation(stopCh)
informer.Start(stopCh)
m.Run(stopCh)
}

func (m *Manager) worker() {
for m.processNextWorkItem() {
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/manager/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ type LbArgs struct {
useExternalEndpoint bool
inst string
ppv2En bool
egress bool
egress bool
}

type LbModelEnt struct {
Expand Down Expand Up @@ -1019,7 +1019,7 @@ func (m *Manager) addLoadBalancer(svc *corev1.Service) error {
sel: m.lbCache[cacheKey].EpSelect,
inst: m.lbCache[cacheKey].Inst,
ppv2En: m.lbCache[cacheKey].ppv2En,
egress: m.lbCache[cacheKey].egress,
egress: m.lbCache[cacheKey].egress,
needMultusEP: needMultusEP,
usePodNetwork: usePodNet,
useExternalEndpoint: useExternalEndpoint,
Expand Down

0 comments on commit 9838f91

Please sign in to comment.