Skip to content

Commit

Permalink
[refactor] Using PolicyTargetReference instead of Selector
Browse files Browse the repository at this point in the history
to target gateway resource
  • Loading branch information
didierofrivia committed May 3, 2024
1 parent 4211185 commit 653fb27
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion controllers/rate_limiting_wasmplugin_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (r *RateLimitingWASMPluginReconciler) desiredRateLimitingWASMPlugin(ctx con
Namespace: gw.Namespace,
},
Spec: istioextensionsv1alpha1.WasmPlugin{
Selector: kuadrantistioutils.WorkloadSelectorFromGateway(ctx, r.Client(), gw),
TargetRef: kuadrantistioutils.PolicyTargetRefFromGateway(gw),

Check warning on line 116 in controllers/rate_limiting_wasmplugin_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/rate_limiting_wasmplugin_controller.go#L116

Added line #L116 was not covered by tests
Url: rlptools.WASMFilterImageURL,
PluginConfig: nil,
// Insert plugin before Istio stats filters and after Istio authorization filters.
Expand Down
8 changes: 8 additions & 0 deletions pkg/istio/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ func WorkloadSelectorFromGateway(ctx context.Context, k8sClient client.Client, g
MatchLabels: gatewayWorkloadSelector,
}
}

func PolicyTargetRefFromGateway(gateway *gatewayapiv1.Gateway) *istiocommon.PolicyTargetReference {
return &istiocommon.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Kind: "Gateway",
Name: gateway.Name,
}
}
14 changes: 14 additions & 0 deletions pkg/istio/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,17 @@ func TestWorkloadSelectorFromGatewayMissingHostnameAddress(t *testing.T) {
t.Error("should have built the istio workload selector from the gateway labels")
}
}

func TestPolicyTargetRefFromGateway(t *testing.T) {
gateway := &gatewayapiv1.Gateway{
ObjectMeta: metav1.ObjectMeta{
Namespace: "my-ns",
Name: "my-gw",
},
}

ref := PolicyTargetRefFromGateway(gateway)
if ref == nil || ref.Group != "gateway.networking.k8s.io" || ref.Kind != "Gateway" || ref.Name != "my-gw" {
t.Error("should have built the istio policy target reference from the gateway")
}
}

0 comments on commit 653fb27

Please sign in to comment.