-
Notifications
You must be signed in to change notification settings - Fork 591
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: treat status conditions of gateway and gatewayclass as snapshots (…
- Loading branch information
1 parent
7947eb0
commit 1123b86
Showing
6 changed files
with
259 additions
and
8 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
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
113 changes: 113 additions & 0 deletions
113
internal/controllers/gateway/gatewayclass_controller_test.go
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,113 @@ | ||
package gateway | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" | ||
) | ||
|
||
func Test_setGatewayClassCondtion(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
gwc *gatewayv1alpha2.GatewayClass | ||
condition metav1.Condition | ||
conditionLength int | ||
}{ | ||
{ | ||
name: "no_such_condition_should_append_one", | ||
gwc: &gatewayv1alpha2.GatewayClass{}, | ||
condition: metav1.Condition{ | ||
Type: "fake1", | ||
Status: metav1.ConditionTrue, | ||
Reason: "fake1", | ||
ObservedGeneration: 1, | ||
LastTransitionTime: metav1.Now(), | ||
}, | ||
conditionLength: 1, | ||
}, | ||
{ | ||
name: "have_condition_with_type_should_replace", | ||
gwc: &gatewayv1alpha2.GatewayClass{ | ||
Status: gatewayv1alpha2.GatewayClassStatus{ | ||
Conditions: []metav1.Condition{ | ||
{ | ||
Type: "fake1", | ||
Status: metav1.ConditionFalse, | ||
Reason: "fake1", | ||
ObservedGeneration: 1, | ||
LastTransitionTime: metav1.Now(), | ||
}, | ||
}, | ||
}, | ||
}, | ||
condition: metav1.Condition{ | ||
Type: "fake1", | ||
Status: metav1.ConditionTrue, | ||
Reason: "fake1", | ||
ObservedGeneration: 2, | ||
LastTransitionTime: metav1.Now(), | ||
}, | ||
conditionLength: 1, | ||
}, | ||
{ | ||
name: "multiple_conditions_with_type_should_preserve_one", | ||
gwc: &gatewayv1alpha2.GatewayClass{ | ||
Status: gatewayv1alpha2.GatewayClassStatus{ | ||
Conditions: []metav1.Condition{ | ||
{ | ||
Type: "fake1", | ||
Status: metav1.ConditionFalse, | ||
Reason: "fake1", | ||
ObservedGeneration: 1, | ||
LastTransitionTime: metav1.Now(), | ||
}, | ||
{ | ||
Type: "fake1", | ||
Status: metav1.ConditionTrue, | ||
Reason: "fake2", | ||
ObservedGeneration: 2, | ||
LastTransitionTime: metav1.Now(), | ||
}, | ||
{ | ||
Type: "fake2", | ||
Status: metav1.ConditionTrue, | ||
Reason: "fake2", | ||
ObservedGeneration: 2, | ||
LastTransitionTime: metav1.Now(), | ||
}, | ||
}, | ||
}, | ||
}, | ||
condition: metav1.Condition{ | ||
Type: "fake1", | ||
Status: metav1.ConditionTrue, | ||
Reason: "fake1", | ||
ObservedGeneration: 3, | ||
LastTransitionTime: metav1.Now(), | ||
}, | ||
conditionLength: 2, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
t.Run(tc.name, func(t *testing.T) { | ||
setGatewayClassCondition(tc.gwc, tc.condition) | ||
t.Logf("checking conditions of gateway after setting") | ||
assert.Len(t, tc.gwc.Status.Conditions, tc.conditionLength) | ||
|
||
conditionNum := 0 | ||
var observedCondition metav1.Condition | ||
for _, condition := range tc.gwc.Status.Conditions { | ||
if condition.Type == tc.condition.Type { | ||
conditionNum++ | ||
observedCondition = condition | ||
} | ||
} | ||
assert.Equal(t, 1, conditionNum) | ||
assert.EqualValues(t, tc.condition, observedCondition) | ||
}) | ||
} | ||
} |
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