Skip to content

Commit

Permalink
update integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Honigeintopf committed Nov 8, 2024
1 parent 4d9affd commit 0262546
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
19 changes: 9 additions & 10 deletions controllers/set/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,25 @@ func (c *controller) evaluateFirewallConditions(fw *v2.Firewall) firewallConditi
allConditionsMet = created && ready && connected && seedConnected && distanceConfigured
)

allocationTimestamp := pointer.SafeDeref(fw.Status.ControllerStatus).SeedUpdated.Time
timeSinceAllocation := time.Since(allocationTimestamp)
seedUpdatedTime := pointer.SafeDeref(fw.Status.ControllerStatus).SeedUpdated.Time
timeSinceReconcile := time.Since(seedUpdatedTime)

if allConditionsMet {
return firewallConditionStatus{IsReady: true}
}

if created && timeSinceAllocation > allocationTimeout {

// If the firewall is still creating, don't set a timeout
if fw.Status.Phase != v2.FirewallPhaseCreating {
return firewallConditionStatus{CreateTimeout: true}
}

// duration after which a firewall in the creation phase will be recreated, exceeded
if fw.Status.Phase == v2.FirewallPhaseCreating && timeSinceReconcile > allocationTimeout {
c.log.Info("create timeout reached")
return firewallConditionStatus{CreateTimeout: true}
}

if unhealthyTimeout != 0 && created && timeSinceAllocation > unhealthyTimeout {
if seedConnected && unhealthyTimeout != 0 && created && timeSinceReconcile > unhealthyTimeout {
c.log.Info("unhealthy timeout reached")
return firewallConditionStatus{HealthTimeout: true}
}

//if everything returns false, it is progressing
return firewallConditionStatus{
IsReady: allConditionsMet,
CreateTimeout: false,
Expand Down
34 changes: 29 additions & 5 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/util/retry"

testcommon "github.com/metal-stack/firewall-controller-manager/integration/common"

Expand Down Expand Up @@ -1936,6 +1937,7 @@ var _ = Context("integration test", Ordered, func() {
})

Expect(k8sClient.Create(ctx, deployment())).To(Succeed())

Eventually(func() error {
firewallSetList := &v2.FirewallSetList{}
err := k8sClient.List(ctx, firewallSetList, client.InNamespace(namespaceName))
Expand All @@ -1953,21 +1955,43 @@ var _ = Context("integration test", Ordered, func() {
It("should simulate unhealthiness and trigger deletion", func() {
firewallList := &v2.FirewallList{}
Eventually(func() int {

err := k8sClient.List(ctx, firewallList, client.InNamespace(firewallSet.Namespace))
if err != nil {
return 0
}
return len(firewallList.Items)
}, 15*time.Second, interval).Should(BeNumerically(">", 0), "Should have at least one firewall")

By("waiting for the firewall to be deleted")
Eventually(func() bool {
for _, fw := range firewallList.Items {
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(&fw), &v2.Firewall{})
if !apierrors.IsNotFound(err) {
for _, item := range firewallList.Items {
var fw v2.Firewall
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(&item), &fw)
if err != nil {
fmt.Printf("Failed to get firewall: %v\n", err)
return false
}

if fw.Status.ControllerStatus == nil {
fw.Status.ControllerStatus = &v2.ControllerConnection{}
}
//add a fake concile so the unhealty firewall gets deleted
fw.Status.ControllerStatus.SeedUpdated.Time = time.Now().Add(-20 * 24 * time.Hour)
err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
if err := k8sClient.Get(ctx, client.ObjectKeyFromObject(&fw), &fw); err != nil {
return err
}
if fw.Status.ControllerStatus == nil {
fw.Status.ControllerStatus = &v2.ControllerConnection{}
}
fw.Status.ControllerStatus.SeedUpdated.Time = time.Now().Add(-20 * 24 * time.Hour)
return k8sClient.Status().Update(ctx, &fw)
})

if err != nil {
fmt.Printf("Failed to update firewall status: %v\n", err)
return false
}

}
return true
}, 10*time.Second, interval).Should(BeTrue(), "All Firewalls should be deleted")
Expand Down

0 comments on commit 0262546

Please sign in to comment.