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

WIP: Reconcile multiple namespaces #66

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
12 changes: 8 additions & 4 deletions controllers/deployment/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func SetupWithManager(log logr.Logger, recorder record.EventRecorder, mgr ctrl.M
lastSetCreation: map[string]time.Time{},
})

return ctrl.NewControllerManagedBy(mgr).
controller := ctrl.NewControllerManagedBy(mgr).
For(
&v2.FirewallDeployment{},
builder.WithPredicates(
Expand All @@ -57,9 +57,13 @@ func SetupWithManager(log logr.Logger, recorder record.EventRecorder, mgr ctrl.M
),
),
),
).
WithEventFilter(predicate.NewPredicateFuncs(controllers.SkipOtherNamespace(c.GetSeedNamespace()))).
Complete(g)
)

if c.GetSeedNamespace() != "" {
controller = controller.WithEventFilter(predicate.NewPredicateFuncs(controllers.SkipOtherNamespace(c.GetSeedNamespace())))
}

return controller.Complete(g)
}

func SetupWebhookWithManager(log logr.Logger, mgr ctrl.Manager, c *config.ControllerConfig) error {
Expand Down
5 changes: 3 additions & 2 deletions controllers/deployment/infrastructure_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (c *controller) updateInfrastructureStatus(r *controllers.Ctx[*v2.FirewallD
})

err := c.c.GetSeedClient().Get(r.Ctx, client.ObjectKey{
Namespace: c.c.GetSeedNamespace(),
Namespace: r.Target.Namespace,
Name: infrastructureName,
}, infraObj)
if err != nil {
Expand Down Expand Up @@ -129,7 +129,7 @@ func (c *controller) updateInfrastructureStatus(r *controllers.Ctx[*v2.FirewallD
})

err = c.c.GetSeedClient().Get(r.Ctx, client.ObjectKey{
Namespace: c.c.GetSeedNamespace(),
Namespace: r.Target.Namespace,
Name: "acl",
}, aclObj)
if err != nil {
Expand All @@ -150,6 +150,7 @@ func (c *controller) updateInfrastructureStatus(r *controllers.Ctx[*v2.FirewallD
}

func extractInfrastructureNameFromSeedNamespace(namespace string) (string, bool) {
// TODO: is this safe to not skip in the future?
if !strings.HasPrefix(namespace, "shoot--") {
return "", false
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/deployment/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (c *controller) Reconcile(r *controllers.Ctx[*v2.FirewallDeployment]) error
r.Log.Info("swapped latest set to shortest distance", "distance", v2.FirewallShortestDistance)
}

infrastructureName, ok := extractInfrastructureNameFromSeedNamespace(c.c.GetSeedNamespace())
infrastructureName, ok := extractInfrastructureNameFromSeedNamespace(r.Target.Namespace)
if ok {
var ownedFirewalls []*v2.Firewall
for _, set := range ownedSets {
Expand Down
12 changes: 8 additions & 4 deletions controllers/firewall/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func SetupWithManager(log logr.Logger, recorder record.EventRecorder, mgr ctrl.M
}),
})

return ctrl.NewControllerManagedBy(mgr).
controller := ctrl.NewControllerManagedBy(mgr).
For(
&v2.Firewall{},
builder.WithPredicates(
Expand All @@ -99,9 +99,13 @@ func SetupWithManager(log logr.Logger, recorder record.EventRecorder, mgr ctrl.M
),
).
// don't think about owning the firewall monitor here, it's in the shoot cluster, we cannot watch two clusters with controller-runtime
Named("Firewall").
WithEventFilter(predicate.NewPredicateFuncs(controllers.SkipOtherNamespace(c.GetSeedNamespace()))).
Complete(g)
Named("Firewall")

if c.GetSeedNamespace() != "" {
controller = controller.WithEventFilter(predicate.NewPredicateFuncs(controllers.SkipOtherNamespace(c.GetSeedNamespace())))
}

return controller.Complete(g)
}

func SetupWebhookWithManager(log logr.Logger, mgr ctrl.Manager, c *config.ControllerConfig) error {
Expand Down
2 changes: 1 addition & 1 deletion controllers/generic_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (g *GenericController[O]) logger(req ctrl.Request) logr.Logger {
}

func (g GenericController[O]) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
if req.Namespace != g.namespace { // should already be filtered out through predicate, but we will check anyway
if g.namespace != "" && req.Namespace != g.namespace { // should already be filtered out through predicate, but we will check anyway
return ctrl.Result{}, nil
}

Expand Down
12 changes: 8 additions & 4 deletions controllers/monitor/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@ func SetupWithManager(log logr.Logger, mgr ctrl.Manager, c *config.ControllerCon
c: c,
}).WithoutStatus()

return ctrl.NewControllerManagedBy(mgr).
controller := ctrl.NewControllerManagedBy(mgr).
For(&v2.FirewallMonitor{},
builder.WithPredicates(
predicate.Not(
v2.AnnotationRemovedPredicate(v2.RollSetAnnotation),
),
),
).
Named("FirewallMonitor").
WithEventFilter(predicate.NewPredicateFuncs(controllers.SkipOtherNamespace(c.GetShootNamespace()))).
Complete(g)
Named("FirewallMonitor")

if c.GetSeedNamespace() != "" {
controller = controller.WithEventFilter(predicate.NewPredicateFuncs(controllers.SkipOtherNamespace(c.GetSeedNamespace())))
}

return controller.Complete(g)
}

func (c *controller) New() *v2.FirewallMonitor {
Expand Down
4 changes: 2 additions & 2 deletions controllers/monitor/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (c *controller) updateFirewallStatus(r *controllers.Ctx[*v2.FirewallMonitor
fw := &v2.Firewall{
ObjectMeta: metav1.ObjectMeta{
Name: r.Target.Name,
Namespace: c.c.GetSeedNamespace(),
Namespace: r.Target.Namespace,
},
}
err := c.c.GetSeedClient().Get(r.Ctx, client.ObjectKeyFromObject(fw), fw)
Expand Down Expand Up @@ -72,7 +72,7 @@ func (c *controller) rollSetAnnotation(r *controllers.Ctx[*v2.FirewallMonitor])
fw := &v2.Firewall{
ObjectMeta: metav1.ObjectMeta{
Name: r.Target.Name,
Namespace: c.c.GetSeedNamespace(),
Namespace: r.Target.Namespace,
},
}

Expand Down
12 changes: 8 additions & 4 deletions controllers/set/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func SetupWithManager(log logr.Logger, recorder record.EventRecorder, mgr ctrl.M
c: c,
})

return ctrl.NewControllerManagedBy(mgr).
controller := ctrl.NewControllerManagedBy(mgr).
For(
&v2.FirewallSet{},
builder.WithPredicates(
Expand All @@ -47,9 +47,13 @@ func SetupWithManager(log logr.Logger, recorder record.EventRecorder, mgr ctrl.M
),
),
),
).
WithEventFilter(predicate.NewPredicateFuncs(controllers.SkipOtherNamespace(c.GetSeedNamespace()))).
Complete(g)
)

if c.GetSeedNamespace() != "" {
controller = controller.WithEventFilter(predicate.NewPredicateFuncs(controllers.SkipOtherNamespace(c.GetSeedNamespace())))
}

return controller.Complete(g)
}

func SetupWebhookWithManager(log logr.Logger, mgr ctrl.Manager, c *config.ControllerConfig) error {
Expand Down
12 changes: 8 additions & 4 deletions controllers/update/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,20 @@ func SetupWithManager(log logr.Logger, recorder record.EventRecorder, mgr ctrl.M
imageCache: newImageCache(c.GetMetal()),
}).WithoutStatus()

return ctrl.NewControllerManagedBy(mgr).
controller := ctrl.NewControllerManagedBy(mgr).
For(
&v2.FirewallDeployment{},
builder.WithPredicates(
v2.AnnotationAddedPredicate(v2.MaintenanceAnnotation),
),
).
Named("FirewallDeployment").
WithEventFilter(predicate.NewPredicateFuncs(controllers.SkipOtherNamespace(c.GetSeedNamespace()))).
Complete(g)
Named("FirewallDeployment")

if c.GetSeedNamespace() != "" {
controller = controller.WithEventFilter(predicate.NewPredicateFuncs(controllers.SkipOtherNamespace(c.GetSeedNamespace())))
}

return controller.Complete(g)
}

func (c *controller) New() *v2.FirewallDeployment {
Expand Down
Loading