Skip to content

Commit

Permalink
fix: write backend status (envoyproxy#4219)
Browse files Browse the repository at this point in the history
Signed-off-by: Guy Daich <guy.daich@sap.com>
  • Loading branch information
guydc authored Sep 11, 2024
1 parent e26c162 commit 7cddd95
Show file tree
Hide file tree
Showing 26 changed files with 151 additions and 45 deletions.
21 changes: 21 additions & 0 deletions internal/gatewayapi/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@ func (r *Runner) subscribeAndTranslate(ctx context.Context) {
}
delete(statusesToDelete.EnvoyExtensionPolicyStatusKeys, key)
}
for _, backend := range result.Backends {
key := utils.NamespacedName(backend)
if !(reflect.ValueOf(backend.Status).IsZero()) {
r.ProviderResources.BackendStatuses.Store(key, &backend.Status)
}
delete(statusesToDelete.BackendStatusKeys, key)
}
for _, extServerPolicy := range result.ExtensionServerPolicies {
key := message.NamespacedNameAndGVK{
NamespacedName: utils.NamespacedName(&extServerPolicy),
Expand Down Expand Up @@ -323,6 +330,8 @@ type StatusesToDelete struct {
SecurityPolicyStatusKeys map[types.NamespacedName]bool
EnvoyExtensionPolicyStatusKeys map[types.NamespacedName]bool
ExtensionServerPolicyStatusKeys map[message.NamespacedNameAndGVK]bool

BackendStatusKeys map[types.NamespacedName]bool
}

func (r *Runner) getAllStatuses() *StatusesToDelete {
Expand All @@ -341,6 +350,8 @@ func (r *Runner) getAllStatuses() *StatusesToDelete {
BackendTLSPolicyStatusKeys: make(map[types.NamespacedName]bool),
EnvoyExtensionPolicyStatusKeys: make(map[types.NamespacedName]bool),
ExtensionServerPolicyStatusKeys: make(map[message.NamespacedNameAndGVK]bool),

BackendStatusKeys: make(map[types.NamespacedName]bool),
}

// Get current status keys
Expand Down Expand Up @@ -378,6 +389,9 @@ func (r *Runner) getAllStatuses() *StatusesToDelete {
for key := range r.ProviderResources.EnvoyExtensionPolicyStatuses.LoadAll() {
ds.EnvoyExtensionPolicyStatusKeys[key] = true
}
for key := range r.ProviderResources.BackendStatuses.LoadAll() {
ds.BackendStatusKeys[key] = true
}
return ds
}

Expand Down Expand Up @@ -431,6 +445,10 @@ func (r *Runner) deleteStatusKeys(ds *StatusesToDelete) {
r.ProviderResources.ExtensionPolicyStatuses.Delete(key)
delete(ds.ExtensionServerPolicyStatusKeys, key)
}
for key := range ds.BackendStatusKeys {
r.ProviderResources.BackendStatuses.Delete(key)
delete(ds.BackendStatusKeys, key)
}
}

// deleteAllStatusKeys deletes all status keys stored by the subscriber.
Expand Down Expand Up @@ -474,6 +492,9 @@ func (r *Runner) deleteAllStatusKeys() {
for key := range r.ProviderResources.ExtensionPolicyStatuses.LoadAll() {
r.ProviderResources.ExtensionPolicyStatuses.Delete(key)
}
for key := range r.ProviderResources.BackendStatuses.LoadAll() {
r.ProviderResources.BackendStatuses.Delete(key)
}
}

// getIRKeysToDelete returns the list of IR keys to delete
Expand Down
16 changes: 16 additions & 0 deletions internal/gatewayapi/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ func TestDeleteStatusKeys(t *testing.T) {
Name: "test7",
Namespace: "test-namespace",
},
{
Name: "test8",
Namespace: "test-namespace",
},
}

r.ProviderResources.GatewayStatuses.Store(keys[0], &gwapiv1.GatewayStatus{})
Expand All @@ -173,6 +177,7 @@ func TestDeleteStatusKeys(t *testing.T) {
r.ProviderResources.TCPRouteStatuses.Store(keys[4], &gwapiv1a2.TCPRouteStatus{})
r.ProviderResources.UDPRouteStatuses.Store(keys[5], &gwapiv1a2.UDPRouteStatus{})
r.ProviderResources.UDPRouteStatuses.Store(keys[6], &gwapiv1a2.UDPRouteStatus{})
r.ProviderResources.BackendStatuses.Store(keys[7], &egv1a1.BackendStatus{})

// Checks that the keys are successfully stored to DeletableStatus and watchable maps
ds := r.getAllStatuses()
Expand All @@ -184,13 +189,15 @@ func TestDeleteStatusKeys(t *testing.T) {
require.True(t, ds.TCPRouteStatusKeys[keys[4]])
require.True(t, ds.UDPRouteStatusKeys[keys[5]])
require.True(t, ds.UDPRouteStatusKeys[keys[6]])
require.True(t, ds.BackendStatusKeys[keys[7]])

require.Equal(t, 1, r.ProviderResources.GatewayStatuses.Len())
require.Equal(t, 1, r.ProviderResources.HTTPRouteStatuses.Len())
require.Equal(t, 1, r.ProviderResources.GRPCRouteStatuses.Len())
require.Equal(t, 1, r.ProviderResources.TLSRouteStatuses.Len())
require.Equal(t, 1, r.ProviderResources.TCPRouteStatuses.Len())
require.Equal(t, 2, r.ProviderResources.UDPRouteStatuses.Len())
require.Equal(t, 1, r.ProviderResources.BackendStatuses.Len())

// Delete all keys except the last UDPRouteStatus key
delete(ds.UDPRouteStatusKeys, keys[6])
Expand All @@ -202,6 +209,7 @@ func TestDeleteStatusKeys(t *testing.T) {
require.Equal(t, 0, r.ProviderResources.TLSRouteStatuses.Len())
require.Equal(t, 0, r.ProviderResources.TCPRouteStatuses.Len())
require.Equal(t, 1, r.ProviderResources.UDPRouteStatuses.Len())
require.Equal(t, 0, r.ProviderResources.BackendStatuses.Len())
}

func TestDeleteAllStatusKeys(t *testing.T) {
Expand Down Expand Up @@ -253,6 +261,10 @@ func TestDeleteAllStatusKeys(t *testing.T) {
Name: "test6",
Namespace: "test-namespace",
},
{
Name: "test7",
Namespace: "test-namespace",
},
}

r.ProviderResources.GatewayStatuses.Store(keys[0], &gwapiv1.GatewayStatus{})
Expand All @@ -261,6 +273,7 @@ func TestDeleteAllStatusKeys(t *testing.T) {
r.ProviderResources.TLSRouteStatuses.Store(keys[3], &gwapiv1a2.TLSRouteStatus{})
r.ProviderResources.TCPRouteStatuses.Store(keys[4], &gwapiv1a2.TCPRouteStatus{})
r.ProviderResources.UDPRouteStatuses.Store(keys[5], &gwapiv1a2.UDPRouteStatus{})
r.ProviderResources.BackendStatuses.Store(keys[6], &egv1a1.BackendStatus{})

// Checks that the keys are successfully stored to DeletableStatus and watchable maps
ds := r.getAllStatuses()
Expand All @@ -271,13 +284,15 @@ func TestDeleteAllStatusKeys(t *testing.T) {
require.True(t, ds.TLSRouteStatusKeys[keys[3]])
require.True(t, ds.TCPRouteStatusKeys[keys[4]])
require.True(t, ds.UDPRouteStatusKeys[keys[5]])
require.True(t, ds.BackendStatusKeys[keys[6]])

require.Equal(t, 1, r.ProviderResources.GatewayStatuses.Len())
require.Equal(t, 1, r.ProviderResources.HTTPRouteStatuses.Len())
require.Equal(t, 1, r.ProviderResources.GRPCRouteStatuses.Len())
require.Equal(t, 1, r.ProviderResources.TLSRouteStatuses.Len())
require.Equal(t, 1, r.ProviderResources.TCPRouteStatuses.Len())
require.Equal(t, 1, r.ProviderResources.UDPRouteStatuses.Len())
require.Equal(t, 1, r.ProviderResources.BackendStatuses.Len())

// Delete all keys
r.deleteAllStatusKeys()
Expand All @@ -287,4 +302,5 @@ func TestDeleteAllStatusKeys(t *testing.T) {
require.Equal(t, 0, r.ProviderResources.TLSRouteStatuses.Len())
require.Equal(t, 0, r.ProviderResources.TCPRouteStatuses.Len())
require.Equal(t, 0, r.ProviderResources.UDPRouteStatuses.Len())
require.Equal(t, 0, r.ProviderResources.BackendStatuses.Len())
}
4 changes: 2 additions & 2 deletions internal/gatewayapi/status/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ func UpdateBackendStatusAcceptedCondition(be *egv1a1.Backend, accepted bool, msg
func computeBackendAcceptedCondition(be *egv1a1.Backend, accepted bool, msg string) metav1.Condition {
switch accepted {
case true:
return newCondition(string(egv1a1.BackendReasonInvalid), metav1.ConditionTrue,
return newCondition(string(egv1a1.BackendReasonAccepted), metav1.ConditionTrue,
string(egv1a1.BackendConditionAccepted),
"The Backend was accepted", time.Now(), be.Generation)
default:
return newCondition(string(egv1a1.BackendReasonAccepted), metav1.ConditionFalse,
return newCondition(string(egv1a1.BackendReasonInvalid), metav1.ConditionFalse,
string(egv1a1.BackendConditionAccepted),
msg, time.Now(), be.Generation)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ backends:
Gateway Config
reason: Accepted
status: "False"
type: Accepted
type: Invalid
envoyExtensionPolicies:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyExtensionPolicy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ backends:
message: 'The Backend was not accepted: hostname *.foo.com is not a valid FQDN'
reason: Accepted
status: "False"
type: Accepted
type: Invalid
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
Expand All @@ -35,7 +35,7 @@ backends:
with at least two segments separated by dots'
reason: Accepted
status: "False"
type: Accepted
type: Invalid
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
Expand All @@ -54,7 +54,7 @@ backends:
range is not supported'
reason: Accepted
status: "False"
type: Accepted
type: Invalid
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
Expand All @@ -72,6 +72,6 @@ backends:
message: 'The Backend was not accepted: IP address example.com is invalid'
reason: Accepted
status: "False"
type: Accepted
type: Invalid
infraIR: {}
xdsIR: {}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ backends:
message: The Backend was accepted
reason: Accepted
status: "True"
type: Invalid
type: Accepted
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ backends:
message: The Backend was accepted
reason: Accepted
status: "True"
type: Invalid
type: Accepted
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ backends:
message: The Backend was accepted
reason: Accepted
status: "True"
type: Invalid
type: Accepted
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
Expand All @@ -98,7 +98,7 @@ backends:
message: The Backend was accepted
reason: Accepted
status: "True"
type: Invalid
type: Accepted
envoyExtensionPolicies:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyExtensionPolicy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ backends:
message: The Backend was accepted
reason: Accepted
status: "True"
type: Invalid
type: Accepted
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
Expand All @@ -98,7 +98,7 @@ backends:
message: The Backend was accepted
reason: Accepted
status: "True"
type: Invalid
type: Accepted
envoyExtensionPolicies:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyExtensionPolicy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ backends:
message: The Backend was accepted
reason: Accepted
status: "True"
type: Invalid
type: Accepted
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
Expand All @@ -98,7 +98,7 @@ backends:
message: The Backend was accepted
reason: Accepted
status: "True"
type: Invalid
type: Accepted
envoyExtensionPolicies:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyExtensionPolicy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ backends:
message: The Backend was accepted
reason: Accepted
status: "True"
type: Invalid
type: Accepted
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ backends:
message: The Backend was accepted
reason: Accepted
status: "True"
type: Invalid
type: Accepted
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
Expand All @@ -33,7 +33,7 @@ backends:
message: The Backend was accepted
reason: Accepted
status: "True"
type: Invalid
type: Accepted
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
Expand All @@ -51,7 +51,7 @@ backends:
message: The Backend was accepted
reason: Accepted
status: "True"
type: Invalid
type: Accepted
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ backends:
message: The Backend was accepted
reason: Accepted
status: "True"
type: Invalid
type: Accepted
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
Expand All @@ -38,7 +38,7 @@ backends:
message: The Backend was accepted
reason: Accepted
status: "True"
type: Invalid
type: Accepted
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
Expand All @@ -59,7 +59,7 @@ backends:
message: The Backend was accepted
reason: Accepted
status: "True"
type: Invalid
type: Accepted
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
Expand All @@ -80,7 +80,7 @@ backends:
message: The Backend was accepted
reason: Accepted
status: "True"
type: Invalid
type: Accepted
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ backends:
message: The Backend was accepted
reason: Accepted
status: "True"
type: Invalid
type: Accepted
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
Expand All @@ -33,7 +33,7 @@ backends:
message: The Backend was accepted
reason: Accepted
status: "True"
type: Invalid
type: Accepted
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
Expand All @@ -51,7 +51,7 @@ backends:
message: The Backend was accepted
reason: Accepted
status: "True"
type: Invalid
type: Accepted
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
Expand All @@ -70,7 +70,7 @@ backends:
range is not supported'
reason: Accepted
status: "False"
type: Accepted
type: Invalid
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
Expand All @@ -89,7 +89,7 @@ backends:
with at least two segments separated by dots'
reason: Accepted
status: "False"
type: Accepted
type: Invalid
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
Expand Down
Loading

0 comments on commit 7cddd95

Please sign in to comment.