Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/provider/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2213,6 +2213,7 @@ func (r *gatewayAPIReconciler) processEnvoyExtensionPolicies(
// It will be recomputed by the gateway-api layer
envoyExtensionPolicy.Status = gwapiv1a2.PolicyStatus{}
if !resourceMap.allAssociatedEnvoyExtensionPolicies.Has(utils.NamespacedName(&envoyExtensionPolicy).String()) {
r.log.Info("processing EnvoyExtensionPolicy", "namespace", policy.Namespace, "name", policy.Name)
resourceMap.allAssociatedEnvoyExtensionPolicies.Insert(utils.NamespacedName(&envoyExtensionPolicy).String())
resourceTree.EnvoyExtensionPolicies = append(resourceTree.EnvoyExtensionPolicies, &envoyExtensionPolicy)
}
Expand Down
1 change: 1 addition & 0 deletions internal/provider/kubernetes/controller_offline.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func newOfflineGatewayAPIClient() client.Client {
WithIndex(&egv1a1.SecurityPolicy{}, configMapSecurityPolicyIndex, configMapSecurityPolicyIndexFunc).
WithIndex(&egv1a1.EnvoyExtensionPolicy{}, backendEnvoyExtensionPolicyIndex, backendEnvoyExtensionPolicyIndexFunc).
WithIndex(&egv1a1.EnvoyExtensionPolicy{}, secretEnvoyExtensionPolicyIndex, secretEnvoyExtensionPolicyIndexFunc).
WithIndex(&egv1a1.EnvoyExtensionPolicy{}, configMapEepIndex, configMapEepIndexFunc).
WithIndex(&gwapiv1a3.BackendTLSPolicy{}, configMapBtlsIndex, configMapBtlsIndexFunc).
WithIndex(&gwapiv1a3.BackendTLSPolicy{}, secretBtlsIndex, secretBtlsIndexFunc).
WithIndex(&egv1a1.HTTPRouteFilter{}, configMapHTTPRouteFilterIndex, configMapRouteFilterIndexFunc).
Expand Down
29 changes: 29 additions & 0 deletions internal/provider/kubernetes/indexers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
secretEnvoyExtensionPolicyIndex = "secretEnvoyExtensionPolicyIndex"
httpRouteFilterHTTPRouteIndex = "httpRouteFilterHTTPRouteIndex"
configMapBtpIndex = "configMapBtpIndex"
configMapEepIndex = "configMapEepIndex"
configMapHTTPRouteFilterIndex = "configMapHTTPRouteFilterIndex"
secretHTTPRouteFilterIndex = "secretHTTPRouteFilterIndex"
)
Expand Down Expand Up @@ -809,6 +810,28 @@
return configMapReferences
}

func configMapEepIndexFunc(rawObj client.Object) []string {
eep := rawObj.(*egv1a1.EnvoyExtensionPolicy)
var configMapReferences []string
if eep.Spec.Lua == nil {
return configMapReferences
}

Check warning on line 818 in internal/provider/kubernetes/indexers.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/indexers.go#L817-L818

Added lines #L817 - L818 were not covered by tests

for _, p := range eep.Spec.Lua {
if p.ValueRef != nil {
if string(p.ValueRef.Kind) == resource.KindConfigMap {
configMapReferences = append(configMapReferences,
types.NamespacedName{
Namespace: eep.Namespace,
Name: string(p.ValueRef.Name),
}.String(),
)
}
}
}
return configMapReferences
}

// addRouteFilterIndexers adds indexing on HTTPRouteFilter, for ConfigMap objects that are
// referenced in HTTPRouteFilter objects. This helps in querying for HTTPRouteFilters that are
// affected by a particular ConfigMap CRUD.
Expand Down Expand Up @@ -928,6 +951,12 @@
return err
}

if err = mgr.GetFieldIndexer().IndexField(
ctx, &egv1a1.EnvoyExtensionPolicy{}, configMapEepIndex,
configMapEepIndexFunc); err != nil {
return err
}

Check warning on line 958 in internal/provider/kubernetes/indexers.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/indexers.go#L957-L958

Added lines #L957 - L958 were not covered by tests

return nil
}

Expand Down
14 changes: 14 additions & 0 deletions internal/provider/kubernetes/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,20 @@
}
}

if r.eepCRDExists {
eepList := &egv1a1.EnvoyExtensionPolicyList{}
if err := r.client.List(context.Background(), eepList, &client.ListOptions{
FieldSelector: fields.OneTermEqualSelector(configMapEepIndex, utils.NamespacedName(configMap).String()),
}); err != nil {
r.log.Error(err, "unable to find associated EnvoyExtensionPolicy")
return false
}

Check warning on line 789 in internal/provider/kubernetes/predicates.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/predicates.go#L787-L789

Added lines #L787 - L789 were not covered by tests

if len(eepList.Items) > 0 {
return true
}
}

if r.hrfCRDExists {
routeFilterList := &egv1a1.HTTPRouteFilterList{}
if err := r.client.List(context.Background(), routeFilterList, &client.ListOptions{
Expand Down
109 changes: 109 additions & 0 deletions internal/provider/kubernetes/predicates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,115 @@ func TestValidateGatewayForReconcile(t *testing.T) {
}
}

// TestValidateConfigMapForReconcile tests the validateConfigMapForReconcile
// predicate function.
func TestValidateConfigMapForReconcile(t *testing.T) {
testCases := []struct {
name string
configs []client.Object
configMap client.Object
expect bool
}{
{
name: "references EnvoyExtensionPolicy Lua config map",
configs: []client.Object{
test.GetGatewayClass("test-gc", egv1a1.GatewayControllerName, nil),
test.GetGateway(types.NamespacedName{Name: "scheduled-status-test"}, "test-gc", 8080),
&egv1a1.EnvoyExtensionPolicy{
ObjectMeta: metav1.ObjectMeta{
Name: "lua-cm",
Namespace: "test",
},
Spec: egv1a1.EnvoyExtensionPolicySpec{
PolicyTargetReferences: egv1a1.PolicyTargetReferences{
TargetRefs: []gwapiv1a2.LocalPolicyTargetReferenceWithSectionName{
{
LocalPolicyTargetReference: gwapiv1a2.LocalPolicyTargetReference{
Kind: "Gateway",
Name: "scheduled-status-test",
},
},
},
},
Lua: []egv1a1.Lua{
{
Type: egv1a1.LuaValueTypeValueRef,
ValueRef: &gwapiv1.LocalObjectReference{
Kind: gwapiv1a2.Kind("ConfigMap"),
Name: gwapiv1a2.ObjectName("lua"),
Group: gwapiv1a2.Group("v1"),
},
},
},
},
},
},
configMap: test.GetConfigMap(types.NamespacedName{Name: "lua", Namespace: "test"}, make(map[string]string), make(map[string]string)),
expect: true,
},
{
name: "does not reference EnvoyExtensionPolicy Lua config map",
configs: []client.Object{
test.GetGatewayClass("test-gc", egv1a1.GatewayControllerName, nil),
test.GetGateway(types.NamespacedName{Name: "scheduled-status-test"}, "test-gc", 8080),
&egv1a1.EnvoyExtensionPolicy{
ObjectMeta: metav1.ObjectMeta{
Name: "lua-cm",
Namespace: "test",
},
Spec: egv1a1.EnvoyExtensionPolicySpec{
PolicyTargetReferences: egv1a1.PolicyTargetReferences{
TargetRefs: []gwapiv1a2.LocalPolicyTargetReferenceWithSectionName{
{
LocalPolicyTargetReference: gwapiv1a2.LocalPolicyTargetReference{
Kind: "Gateway",
Name: "scheduled-status-test",
},
},
},
},
Lua: []egv1a1.Lua{
{
Type: egv1a1.LuaValueTypeValueRef,
ValueRef: &gwapiv1.LocalObjectReference{
Kind: gwapiv1a2.Kind("ConfigMap"),
Name: gwapiv1a2.ObjectName("lua"),
Group: gwapiv1a2.Group("v1"),
},
},
},
},
},
},
configMap: test.GetConfigMap(types.NamespacedName{Name: "not-lua", Namespace: "test"}, make(map[string]string), make(map[string]string)),
expect: false,
},
}

// Create the reconciler.
logger := logging.DefaultLogger(os.Stdout, egv1a1.LogLevelInfo)

r := gatewayAPIReconciler{
classController: egv1a1.GatewayControllerName,
log: logger,
spCRDExists: true,
epCRDExists: true,
eepCRDExists: true,
}

for _, tc := range testCases {
r.client = fakeclient.NewClientBuilder().
WithScheme(envoygateway.GetScheme()).
WithObjects(tc.configs...).
WithIndex(&egv1a1.EnvoyExtensionPolicy{}, configMapEepIndex, configMapEepIndexFunc).
Build()
t.Run(tc.name, func(t *testing.T) {
res := r.validateConfigMapForReconcile(tc.configMap)
require.Equal(t, tc.expect, res)
})
}
}

// TestValidateSecretForReconcile tests the validateSecretForReconcile
// predicate function.
func TestValidateSecretForReconcile(t *testing.T) {
Expand Down
12 changes: 12 additions & 0 deletions internal/provider/kubernetes/test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,18 @@ func GetService(nsName types.NamespacedName, labels map[string]string, ports map
return service
}

// GetConfigMap returns a sample ConfigMap with labels and data
func GetConfigMap(nsName types.NamespacedName, labels, data map[string]string) *corev1.ConfigMap {
return &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: nsName.Name,
Namespace: nsName.Namespace,
Labels: labels,
},
Data: data,
}
}

// GetEndpointSlice returns a sample EndpointSlice.
func GetEndpointSlice(nsName types.NamespacedName, svcName string, isServiceImport bool) *discoveryv1.EndpointSlice {
var labels map[string]string
Expand Down
1 change: 1 addition & 0 deletions release-notes/current.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ bug fixes: |
Fixed bug in certificate SANs overlap detection in listeners.
Fixed issue where EnvoyExtensionPolicy ExtProc body processing mode is set to FullDuplexStreamed, but trailers were not sent.
Fixed validation issue where EnvoyExtensionPolicy ExtProc failOpen is true, and body processing mode FullDuplexStreamed is not rejected.
Add ConfigMap indexers for EnvoyExtensionPolicies to reconcile Lua changes


# Enhancements that improve performance.
Expand Down