Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loxilb-io/loxilb#877 egress support - wait for egress crd until created #222

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading