Skip to content

Commit

Permalink
NET-5818 Gateway Policy Status (#3046)
Browse files Browse the repository at this point in the history
* Fix gw policy status to mimic routes when referenced gateway cannot be
found

* Added test for binding when gateway is deleted
  • Loading branch information
jm96441n authored Oct 6, 2023
1 parent 4d87352 commit b9318cb
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 23 deletions.
11 changes: 0 additions & 11 deletions charts/consul/templates/crd-gatewaypolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,6 @@ spec:
description: GatewayPolicyStatus defines the observed state of the gateway.
properties:
conditions:
default:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: Waiting for controller
reason: Pending
status: Unknown
type: Accepted
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: Waiting for controller
reason: Pending
status: Unknown
type: ResolvedRefs
description: "Conditions describe the current conditions of the Policy.
\n Known condition types are: \n * \"Accepted\" * \"ResolvedRefs\""
items:
Expand Down
6 changes: 6 additions & 0 deletions control-plane/api-gateway/binding/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,14 @@ func (b *Binder) Snapshot() *Snapshot {
Namespace: service.Namespace,
})
}

if common.RemoveFinalizer(&b.config.Gateway) {
snapshot.Kubernetes.Updates.Add(&b.config.Gateway)
for _, policy := range b.config.Policies {
policy := policy
policy.Status = v1alpha1.GatewayPolicyStatus{}
snapshot.Kubernetes.StatusUpdates.Add(&policy)
}
}
}

Expand Down
148 changes: 148 additions & 0 deletions control-plane/api-gateway/binding/binder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,154 @@ func TestBinder_Lifecycle(t *testing.T) {
{Kind: api.APIGateway, Name: "gateway-deleted"},
},
},
"gateway deletion policies": {
config: controlledBinder(BinderConfig{
Gateway: gwv1beta1.Gateway{
ObjectMeta: metav1.ObjectMeta{
Name: "gateway-deleted",
DeletionTimestamp: deletionTimestamp,
Finalizers: []string{common.GatewayFinalizer},
},
Spec: gwv1beta1.GatewaySpec{
GatewayClassName: testGatewayClassName,
Listeners: []gwv1beta1.Listener{
{
Name: gwv1beta1.SectionName("l1"),
},
{
Name: gwv1beta1.SectionName("l2"),
},
},
},
},
Policies: []v1alpha1.GatewayPolicy{
{
ObjectMeta: metav1.ObjectMeta{
Name: "p1",
},
Spec: v1alpha1.GatewayPolicySpec{
TargetRef: v1alpha1.PolicyTargetReference{
Kind: "Gateway",
Name: "gateway-deleted",
SectionName: common.PointerTo(gwv1beta1.SectionName("l1")),
},
},
Status: v1alpha1.GatewayPolicyStatus{
Conditions: []metav1.Condition{
{
Type: "Accepted",
Status: metav1.ConditionTrue,
Reason: "Accepted",
ObservedGeneration: 5,
Message: "gateway policy accepted",
},
{
Type: "ResolvedRefs",
Status: metav1.ConditionTrue,
Reason: "ResolvedRefs",
ObservedGeneration: 5,
Message: "resolved references",
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "p2",
},
Spec: v1alpha1.GatewayPolicySpec{
TargetRef: v1alpha1.PolicyTargetReference{
Kind: "Gateway",
Name: "gateway-deleted",
SectionName: common.PointerTo(gwv1beta1.SectionName("l2")),
},
},
Status: v1alpha1.GatewayPolicyStatus{
Conditions: []metav1.Condition{
{
Type: "Accepted",
Status: metav1.ConditionTrue,
Reason: "Accepted",
ObservedGeneration: 5,
Message: "gateway policy accepted",
},
{
Type: "ResolvedRefs",
Status: metav1.ConditionTrue,
Reason: "ResolvedRefs",
ObservedGeneration: 5,
Message: "resolved references",
},
},
},
},
},
}),
resources: resourceMapResources{
gateways: []gwv1beta1.Gateway{
gatewayWithFinalizer(gwv1beta1.GatewaySpec{
Listeners: []gwv1beta1.Listener{
{
Name: "l1",
},
{
Name: "l2",
},
},
}),
},
},
expectedStatusUpdates: []client.Object{
&v1alpha1.GatewayPolicy{
ObjectMeta: metav1.ObjectMeta{
Name: "p1",
},
Spec: v1alpha1.GatewayPolicySpec{
TargetRef: v1alpha1.PolicyTargetReference{
Kind: "Gateway",
Name: "gateway-deleted",
SectionName: common.PointerTo(gwv1beta1.SectionName("l1")),
},
},
},
&v1alpha1.GatewayPolicy{
ObjectMeta: metav1.ObjectMeta{
Name: "p2",
},
Spec: v1alpha1.GatewayPolicySpec{
TargetRef: v1alpha1.PolicyTargetReference{
Kind: "Gateway",
Name: "gateway-deleted",
SectionName: common.PointerTo(gwv1beta1.SectionName("l2")),
},
},
},
},
expectedUpdates: []client.Object{
addClassConfig(gwv1beta1.Gateway{
ObjectMeta: metav1.ObjectMeta{
Name: "gateway-deleted",
DeletionTimestamp: deletionTimestamp,
Finalizers: []string{},
},
Spec: gwv1beta1.GatewaySpec{
GatewayClassName: testGatewayClassName,
Listeners: []gwv1beta1.Listener{
{
Name: "l1",
},
{
Name: "l2",
},
},
},
}),
},
expectedConsulUpdates: []api.ConfigEntry{},
expectedConsulDeletions: []api.ResourceReference{
{Kind: api.APIGateway, Name: "gateway-deleted"},
},
},
} {
t.Run(name, func(t *testing.T) {
tt.resources.gateways = append(tt.resources.gateways, tt.config.Gateway)
Expand Down
1 change: 0 additions & 1 deletion control-plane/api/v1alpha1/gatewaypolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,5 @@ type GatewayPolicyStatus struct {
// +listType=map
// +listMapKey=type
// +kubebuilder:validation:MaxItems=8
// +kubebuilder:default={{type: "Accepted", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"},{type: "ResolvedRefs", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"}}
Conditions []metav1.Condition `json:"conditions,omitempty"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,6 @@ spec:
description: GatewayPolicyStatus defines the observed state of the gateway.
properties:
conditions:
default:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: Waiting for controller
reason: Pending
status: Unknown
type: Accepted
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: Waiting for controller
reason: Pending
status: Unknown
type: ResolvedRefs
description: "Conditions describe the current conditions of the Policy.
\n Known condition types are: \n * \"Accepted\" * \"ResolvedRefs\""
items:
Expand Down

0 comments on commit b9318cb

Please sign in to comment.