Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
7ca8165
First stab at changing dnscach datastructure and cache update handling
mreiger Aug 29, 2024
478a990
Fix linter errors
mreiger Aug 29, 2024
bafef1a
Fix remaining linter error
mreiger Aug 29, 2024
2d8f679
Forgot to initialize map
mreiger Aug 29, 2024
8df351c
Another uninitialized map
mreiger Aug 29, 2024
c05d4f1
Fix nftables generation: Only add IP port of RR to cache
mreiger Aug 29, 2024
42d089e
Try to fix expiration date
mreiger Aug 29, 2024
7b87dc0
Second attempt to fix expiration time
mreiger Aug 29, 2024
a814da6
Try keep the CRD stable
mreiger Aug 30, 2024
4c406fd
Add forgotten error handling
mreiger Aug 30, 2024
dddc7af
Try and fix bug where only one rule's FQDNState would be shown
mreiger Aug 30, 2024
c67aa1c
Fix forgotten initialisation of map
mreiger Aug 30, 2024
49f25e5
Merge master
majst01 Sep 2, 2024
53ecc4b
get shoot client to dns cache for handling state configmap
mreiger Sep 3, 2024
15578a5
Merge branch 'master' of github.com:metal-stack/firewall-controller i…
mreiger Feb 26, 2025
fabc726
Implement writing to state configmap
mreiger Feb 27, 2025
8215f60
pacify linter
mreiger Feb 27, 2025
559f37d
update setup-gcloud
mreiger Feb 27, 2025
9b36afb
Try and initialize the configmap correctly
mreiger Feb 28, 2025
ea9bfb2
Try different approach for initialising dns cache from configmap
mreiger Feb 28, 2025
2064bfa
properly check for existing configmap
mreiger Feb 28, 2025
e14c8de
Actually try to write dns cache to configmap
mreiger Feb 28, 2025
e65d682
Do not try to write nil cache to configmap; debug output
mreiger Feb 28, 2025
febbaf6
Try and turn on debug logging
mreiger Feb 28, 2025
6069a05
remove accidental package definition
mreiger Feb 28, 2025
70ac71c
Try to fix JSON marshaling
mreiger Mar 3, 2025
bffdffb
Export fields so the json library can read them
mreiger Mar 3, 2025
9f16a98
Try to fix configmap creation
mreiger Mar 3, 2025
c9ebc62
Avoid writing to nil map
mreiger Mar 3, 2025
f1ab16c
Trying to fix configmap creation
mreiger Mar 3, 2025
7302691
Try pointers; more debug
mreiger Mar 4, 2025
72714f1
more pointer fixes?
mreiger Mar 4, 2025
20ba22b
try for better configmap initialisation
mreiger Mar 4, 2025
3cce33a
Try and debug configmap handling with a simple static configmap
mreiger Mar 5, 2025
4f069cc
forgot to initialize context
mreiger Mar 5, 2025
65374b5
Marshal state to yaml for better readability
mreiger Mar 6, 2025
ffe200c
Discard unparseable state configmap
mreiger Mar 6, 2025
f80ae66
Use UTC timezone for expiration times
mreiger Mar 7, 2025
23ffccb
sanitize logging
mreiger Mar 7, 2025
9948b4b
Debug output to figure out error messages when writing cwnp stati
mreiger Mar 10, 2025
90c8a2c
add more debug logging
iljarotar Jun 23, 2025
8073a9c
remove logs
iljarotar Jun 24, 2025
633501b
use map to represent ips with expiration time
iljarotar Jun 24, 2025
2abc897
linter hints and warnings
iljarotar Jun 24, 2025
06428b6
add restoreSets func
iljarotar Jun 24, 2025
4563806
make
iljarotar Jun 24, 2025
42f4be1
Revert "use map to represent ips with expiration time"
iljarotar Jun 24, 2025
c4ea25c
go back to []string instead of map for ip set expiration
iljarotar Jun 24, 2025
dce28bc
revert condition in add and update ips
iljarotar Jun 24, 2025
e04373f
remove restore sets
iljarotar Jun 24, 2025
ad23be3
no reconcile trigger on status update
iljarotar Jun 25, 2025
b50bbd9
sort ips for fqdn state alphabetically to avoid unnecessary resourceV…
iljarotar Jul 1, 2025
45cea8e
remove debug logs
iljarotar Jul 1, 2025
19a10aa
remove unused
iljarotar Jul 1, 2025
be1f7b6
Merge branch 'master' into 186-dns-based-cwnps-not-reliable-on-hostna…
iljarotar Jul 1, 2025
66c7c3e
Update main.go
iljarotar Aug 12, 2025
b3ab138
style
iljarotar Aug 12, 2025
1dd88ba
sort ip sets by name
iljarotar Aug 12, 2025
c26d5b7
also sort nftables ingress and egress rules
iljarotar Aug 12, 2025
3b38b23
sort render ip set ips as well
iljarotar Aug 13, 2025
86a79a2
Try splitting multi-line accept log rules only after assembling all t…
mreiger Aug 13, 2025
d4d9c71
adjust tests
iljarotar Aug 13, 2025
bac53b1
Fixes to tests
mreiger Aug 13, 2025
f515c90
Merge branch 'master' of github.com:metal-stack/firewall-controller i…
iljarotar Aug 22, 2025
64ad532
linter
iljarotar Aug 22, 2025
34aeedd
review findings
iljarotar Aug 25, 2025
594308d
fix test
iljarotar Aug 25, 2025
e16d7ea
crd
iljarotar Aug 25, 2025
7bacada
crd
iljarotar Aug 25, 2025
2224341
add old ips too
iljarotar Aug 26, 2025
cfc494a
revert
iljarotar Aug 26, 2025
206e5aa
add comments to type definition
iljarotar Sep 4, 2025
f351f12
review findings
iljarotar Sep 5, 2025
32bf8a6
fix context stuff
iljarotar Sep 12, 2025
72d0471
use ctx with timeout
iljarotar Sep 12, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
credentials_json: '${{ secrets.GCP_SA_KEY }}'

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0
uses: google-github-actions/setup-gcloud@v2

- name: Set up Go 1.25
uses: actions/setup-go@v5
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ vet:

# Generate code
generate: controller-gen mockgen manifests
go generate ./...
$(CONTROLLER_GEN) object paths="./..."
go generate ./...

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN)
Expand Down
15 changes: 11 additions & 4 deletions api/v1/clusterwidenetworkpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,18 @@ type FQDNSelector struct {

// IPSet stores set name association to IP addresses
type IPSet struct {
FQDN string `json:"fqdn,omitempty"`
SetName string `json:"setName,omitempty"`
IPs []string `json:"ips,omitempty"`
// FQDN which this IP set is for.
FQDN string `json:"fqdn,omitempty"`
// A hash value merely used for reference.
SetName string `json:"setName,omitempty"`
// Deprecated: use `IPExpirationTimes` instead.
IPs []string `json:"ips,omitempty"`
// Deprecated: use `IPExpirationTimes` instead.
ExpirationTime metav1.Time `json:"expirationTime,omitempty"`
Version IPVersion `json:"version,omitempty"`
// Maps IP addresses to their expiration times.
IPExpirationTimes map[string]metav1.Time `json:"ipExpirationTimes,omitempty"`
// Whether this is a IPv4 or a IPv6 set.
Version IPVersion `json:"version,omitempty"`
}

func (l *ClusterwideNetworkPolicyList) GetFQDNs() []FQDNSelector {
Expand Down
8 changes: 8 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions config/crd/bases/metal-stack.io_clusterwidenetworkpolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,28 @@ spec:
description: IPSet stores set name association to IP addresses
properties:
expirationTime:
description: 'Deprecated: use `IPExpirationTimes` instead.'
format: date-time
type: string
fqdn:
description: FQDN which this IP set is for.
type: string
ipExpirationTimes:
additionalProperties:
format: date-time
type: string
description: Maps IP addresses to their expiration times.
type: object
ips:
description: 'Deprecated: use `IPExpirationTimes` instead.'
items:
type: string
type: array
setName:
description: ' A hash value merely used for reference.'
type: string
version:
description: Whether this is a IPv4 or a IPv6 set.
type: string
type: object
type: array
Expand Down
14 changes: 8 additions & 6 deletions controllers/clusterwidenetworkpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import (
"k8s.io/client-go/tools/record"

ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/source"

firewallv2 "github.com/metal-stack/firewall-controller-manager/api/v2"
Expand All @@ -38,6 +40,7 @@ type ClusterwideNetworkPolicyReconciler struct {
SeedNamespace string

Log logr.Logger
Ctx context.Context
Recorder record.EventRecorder

Interval time.Duration
Expand All @@ -57,7 +60,7 @@ func (r *ClusterwideNetworkPolicyReconciler) SetupWithManager(mgr ctrl.Manager)
}

return ctrl.NewControllerManagedBy(mgr).
For(&firewallv1.ClusterwideNetworkPolicy{}).
For(&firewallv1.ClusterwideNetworkPolicy{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Watches(&corev1.Service{}, &handler.EnqueueRequestForObject{}).
WatchesRawSource(&source.Channel{Source: scheduleChan}, &handler.EnqueueRequestForObject{}).
Complete(r)
Expand Down Expand Up @@ -104,7 +107,7 @@ func (r *ClusterwideNetworkPolicyReconciler) Reconcile(ctx context.Context, _ ct
cwnps.Items = validCwnps

nftablesFirewall := nftables.NewFirewall(f, &cwnps, &services, r.DnsProxy, r.Log, r.Recorder)
if err := r.manageDNSProxy(ctx, f, cwnps, nftablesFirewall); err != nil {
if err := r.manageDNSProxy(f, cwnps, nftablesFirewall); err != nil {
return ctrl.Result{}, err
}
updated, err := nftablesFirewall.Reconcile()
Expand All @@ -127,7 +130,7 @@ func (r *ClusterwideNetworkPolicyReconciler) Reconcile(ctx context.Context, _ ct
// manageDNSProxy start DNS proxy if toFQDN rules are present
// if rules were deleted it will stop running DNS proxy
func (r *ClusterwideNetworkPolicyReconciler) manageDNSProxy(
ctx context.Context, f *firewallv2.Firewall, cwnps firewallv1.ClusterwideNetworkPolicyList, nftablesFirewall *nftables.Firewall,
f *firewallv2.Firewall, cwnps firewallv1.ClusterwideNetworkPolicyList, nftablesFirewall *nftables.Firewall,
) (err error) {
// Skipping is needed for testing
if r.SkipDNS {
Expand All @@ -142,10 +145,10 @@ func (r *ClusterwideNetworkPolicyReconciler) manageDNSProxy(

if enableDNS && r.DnsProxy == nil {
r.Log.Info("DNS Proxy is initialized")
if r.DnsProxy, err = dns.NewDNSProxy(f.Spec.DNSServerAddress, f.Spec.DNSPort, ctrl.Log.WithName("DNS proxy")); err != nil {
if r.DnsProxy, err = dns.NewDNSProxy(r.Ctx, f.Spec.DNSServerAddress, f.Spec.DNSPort, r.ShootClient, ctrl.Log.WithName("DNS proxy")); err != nil {
return fmt.Errorf("failed to init DNS proxy: %w", err)
}
go r.DnsProxy.Run(ctx)
go r.DnsProxy.Run()
} else if !enableDNS && r.DnsProxy != nil {
r.Log.Info("DNS Proxy is stopped")
r.DnsProxy.Stop()
Expand Down Expand Up @@ -217,7 +220,6 @@ func (r *ClusterwideNetworkPolicyReconciler) allowedCWNPs(ctx context.Context, c
}

for _, cwnp := range cwnps {
cwnp := cwnp
oke, err := r.validateCWNPEgressTargetPrefix(cwnp, egressSet)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions controllers/firewall_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type FirewallReconciler struct {

Recorder record.EventRecorder
Log logr.Logger
Ctx context.Context
Scheme *runtime.Scheme

Updater *updater.Updater
Expand Down
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ func main() {
return
}

jsonHandler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{})
var sll slog.Level
err := sll.UnmarshalText([]byte(logLevel))
if err != nil {
setupLog.Error(err, "failed to unmarshal log level")
os.Exit(1)
}
jsonHandler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: sll})
l := slog.New(jsonHandler)

ctrl.SetLogger(logr.FromSlogHandler(jsonHandler))
Expand All @@ -105,7 +111,6 @@ func main() {

// FIXME validation and controller start should be refactored into own func which returns error
// instead Fatalw or Error and panic here.
var err error
if firewallName == "" {
firewallName, err = os.Hostname()
if err != nil {
Expand Down Expand Up @@ -263,6 +268,7 @@ func main() {
SeedClient: seedMgr.GetClient(),
ShootClient: shootMgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("ClusterwideNetworkPolicy"),
Ctx: ctx,
Recorder: shootMgr.GetEventRecorderFor("FirewallController"),
FirewallName: firewallName,
SeedNamespace: seedNamespace,
Expand Down
Loading