-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce amount of firewall status updates through monitor controller.
Currently updates happen as often as the firewall-controller updates the monitor. Most of the time this is completely irrelevant and just producing noise.
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package monitor | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
v2 "github.com/metal-stack/firewall-controller-manager/api/v2" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func Test_significantFirewallStatusChange(t *testing.T) { | ||
now := time.Now() | ||
|
||
tests := []struct { | ||
name string | ||
o v2.FirewallStatus | ||
n v2.FirewallStatus | ||
want bool | ||
}{ | ||
{ | ||
name: "controller registers", | ||
o: v2.FirewallStatus{ | ||
ControllerStatus: nil, | ||
}, | ||
n: v2.FirewallStatus{ | ||
ControllerStatus: &v2.ControllerConnection{ | ||
ActualVersion: "1.2.3", | ||
Updated: v1.NewTime(now), | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "conditions not really changed", | ||
o: v2.FirewallStatus{ | ||
Conditions: v2.Conditions{ | ||
v2.NewCondition(v2.FirewallControllerSeedConnected, v2.ConditionTrue, "Connected", fmt.Sprintf("Controller reconciled firewall at %s.", now.Add(-1*time.Minute))), | ||
}, | ||
}, | ||
n: v2.FirewallStatus{ | ||
Conditions: v2.Conditions{ | ||
v2.NewCondition(v2.FirewallControllerSeedConnected, v2.ConditionTrue, "Connected", fmt.Sprintf("Controller reconciled firewall at %s.", now.Add(1*time.Minute))), | ||
}, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "controller reconnects", | ||
o: v2.FirewallStatus{ | ||
Conditions: v2.Conditions{ | ||
v2.NewCondition(v2.FirewallControllerConnected, v2.ConditionFalse, "StoppedReconciling", fmt.Sprintf("Controller has stopped reconciling since %s to shoot.", now)), | ||
}, | ||
}, | ||
n: v2.FirewallStatus{ | ||
Conditions: v2.Conditions{ | ||
v2.NewCondition(v2.FirewallControllerConnected, v2.ConditionTrue, "Connected", fmt.Sprintf("Controller reconciled shoot at %s.", now)), | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := significantFirewallStatusChange(tt.o, tt.n) | ||
if diff := cmp.Diff(tt.want, got); diff != "" { | ||
t.Errorf("diff (+got -want):\n %s", diff) | ||
} | ||
}) | ||
} | ||
} |