Skip to content

Commit

Permalink
Fix assign IP not use spec.EgressIP
Browse files Browse the repository at this point in the history
Signed-off-by: lou-lan <[email protected]>
  • Loading branch information
lou-lan committed Jul 29, 2024
1 parent 6a1bc6a commit 999f73e
Show file tree
Hide file tree
Showing 22 changed files with 745 additions and 2,544 deletions.
18 changes: 13 additions & 5 deletions pkg/agent/eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/spidernet-io/egressgateway/pkg/config"
egressv1 "github.com/spidernet-io/egressgateway/pkg/k8s/apis/v1beta1"
Expand Down Expand Up @@ -149,14 +148,23 @@ func newEipCtrl(mgr manager.Manager, log logr.Logger, cfg *config.Config) error
return err
}

if err := c.Watch(source.Kind(mgr.GetCache(), &egressv1.EgressPolicy{}),
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressPolicy"))); err != nil {
sourceEgressPolicy := utils.SourceKind(
mgr.GetCache(),
&egressv1.EgressPolicy{},
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressPolicy")),
)
if err := c.Watch(sourceEgressPolicy); err != nil {
return fmt.Errorf("failed to watch EgressPolicy: %w", err)
}

if err := c.Watch(source.Kind(mgr.GetCache(), &egressv1.EgressClusterPolicy{}),
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressClusterPolicy"))); err != nil {
sourceEgressPolicy = utils.SourceKind(
mgr.GetCache(),
&egressv1.EgressClusterPolicy{},
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressClusterPolicy")),
)
if err := c.Watch(sourceEgressPolicy); err != nil {
return fmt.Errorf("failed to watch EgressClusterPolicy: %w", err)

}

return nil
Expand Down
58 changes: 34 additions & 24 deletions pkg/agent/police.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ import (
"time"

"github.com/go-logr/logr"
"github.com/spidernet-io/egressgateway/pkg/config"
"github.com/spidernet-io/egressgateway/pkg/ipset"
"github.com/spidernet-io/egressgateway/pkg/iptables"
egressv1 "github.com/spidernet-io/egressgateway/pkg/k8s/apis/v1beta1"
"github.com/spidernet-io/egressgateway/pkg/utils"
apierr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand All @@ -32,7 +27,12 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/spidernet-io/egressgateway/pkg/config"
"github.com/spidernet-io/egressgateway/pkg/ipset"
"github.com/spidernet-io/egressgateway/pkg/iptables"
egressv1 "github.com/spidernet-io/egressgateway/pkg/k8s/apis/v1beta1"
"github.com/spidernet-io/egressgateway/pkg/utils"
)

const (
Expand Down Expand Up @@ -1147,39 +1147,49 @@ func newPolicyController(mgr manager.Manager, log logr.Logger, cfg *config.Confi
return err
}

if err := c.Watch(source.Kind(mgr.GetCache(), &egressv1.EgressGateway{}),
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressGateway"))); err != nil {
sourceEgressGateway := utils.SourceKind(mgr.GetCache(),
&egressv1.EgressGateway{},
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressGateway")))
if err := c.Watch(sourceEgressGateway); err != nil {
return fmt.Errorf("failed to watch EgressGateway: %w", err)
}

if err := c.Watch(source.Kind(mgr.GetCache(), &egressv1.EgressPolicy{}),
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressPolicy")), policyPredicate{}); err != nil {
sourceEgressPolicy := utils.SourceKind(mgr.GetCache(),
&egressv1.EgressPolicy{},
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressPolicy")),
policyPredicate{})
if err := c.Watch(sourceEgressPolicy); err != nil {
return fmt.Errorf("failed to watch EgressPolicy: %w", err)
}

if err := c.Watch(source.Kind(mgr.GetCache(), &egressv1.EgressClusterPolicy{}),
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressClusterPolicy")), policyPredicate{}); err != nil {
sourceEgressClusterPolicy := utils.SourceKind(mgr.GetCache(),
&egressv1.EgressClusterPolicy{},
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressClusterPolicy")),
policyPredicate{})
if err := c.Watch(sourceEgressClusterPolicy); err != nil {
return fmt.Errorf("failed to watch EgressClusterPolicy: %w", err)
}

if err := c.Watch(
source.Kind(mgr.GetCache(), &egressv1.EgressEndpointSlice{}),
handler.EnqueueRequestsFromMapFunc(enqueueEndpointSlice()),
epSlicePredicate{},
); err != nil {
sourceEgressEndpointSlice := utils.SourceKind(mgr.GetCache(),
&egressv1.EgressEndpointSlice{},
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressEndpointSlice")),
epSlicePredicate{})
if err := c.Watch(sourceEgressEndpointSlice); err != nil {
return fmt.Errorf("failed to watch EgressEndpointSlice: %w", err)
}

if err := c.Watch(
source.Kind(mgr.GetCache(), &egressv1.EgressClusterEndpointSlice{}),
handler.EnqueueRequestsFromMapFunc(enqueueEndpointSlice()),
epSlicePredicate{},
); err != nil {
sourceEgressClusterEndpointSlice := utils.SourceKind(mgr.GetCache(),
&egressv1.EgressClusterEndpointSlice{},
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressClusterEndpointSlice")),
epSlicePredicate{})
if err := c.Watch(sourceEgressClusterEndpointSlice); err != nil {
return fmt.Errorf("failed to watch EgressClusterEndpointSlice: %w", err)
}

if err := c.Watch(source.Kind(mgr.GetCache(), &egressv1.EgressClusterInfo{}),
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressClusterInfo"))); err != nil {
sourceEgressClusterInfo := utils.SourceKind(mgr.GetCache(),
&egressv1.EgressClusterInfo{},
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressClusterInfo")))
if err := c.Watch(sourceEgressClusterInfo); err != nil {
return fmt.Errorf("failed to watch EgressClusterInfo: %w", err)
}

Expand Down
30 changes: 16 additions & 14 deletions pkg/agent/vxlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/spidernet-io/egressgateway/pkg/agent/route"
"github.com/spidernet-io/egressgateway/pkg/agent/vxlan"
Expand Down Expand Up @@ -918,31 +917,34 @@ func newEgressTunnelController(mgr manager.Manager, cfg *config.Config, log logr
return err
}

if err := c.Watch(source.Kind(mgr.GetCache(), &egressv1.EgressTunnel{}),
sourceEgressTunnel := utils.SourceKind(mgr.GetCache(),
&egressv1.EgressTunnel{},
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressTunnel")),
egressTunnelPredicate{},
); err != nil {
egressTunnelPredicate{})
if err := c.Watch(sourceEgressTunnel); err != nil {
return fmt.Errorf("failed to watch EgressTunnel: %w", err)
}

if err := c.Watch(source.Kind(mgr.GetCache(), &egressv1.EgressGateway{}),
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressGateway"))); err != nil {
sourceEgressGateway := utils.SourceKind(mgr.GetCache(),
&egressv1.EgressGateway{},
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressGateway")))
if err := c.Watch(sourceEgressGateway); err != nil {
return fmt.Errorf("failed to watch EgressGateway: %w", err)
}

if err := c.Watch(
source.Kind(mgr.GetCache(), &egressv1.EgressEndpointSlice{}),
sourceEgressEndpointSlice := utils.SourceKind(mgr.GetCache(),
&egressv1.EgressEndpointSlice{},
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressEndpointSlice")),
epSlicePredicate{},
); err != nil {
epSlicePredicate{})
if err := c.Watch(sourceEgressEndpointSlice); err != nil {
return fmt.Errorf("failed to watch EgressEndpointSlice: %w", err)
}

if err := c.Watch(
source.Kind(mgr.GetCache(), &egressv1.EgressClusterEndpointSlice{}),
sourceEgressClusterEndpointSlice := utils.SourceKind(mgr.GetCache(),
&egressv1.EgressClusterEndpointSlice{},
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressClusterEndpointSlice")),
epSlicePredicate{},
); err != nil {
epSlicePredicate{})
if err := c.Watch(sourceEgressClusterEndpointSlice); err != nil {
return fmt.Errorf("failed to watch EgressClusterEndpointSlice: %w", err)
}

Expand Down
Loading

0 comments on commit 999f73e

Please sign in to comment.