Skip to content

Commit

Permalink
update dns policy to have immutable strategy field (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
maleck13 authored Mar 20, 2024
1 parent 615e2f3 commit bdb99cd
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions api/v1alpha1/dnspolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type DNSPolicySpec struct {

// +required
// +kubebuilder:validation:Enum=simple;loadbalanced
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="RoutingStrategy is immutable"
// +kubebuilder:default=loadbalanced
RoutingStrategy RoutingStrategy `json:"routingStrategy"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ metadata:
capabilities: Basic Install
categories: Integration & Delivery
containerImage: quay.io/kuadrant/kuadrant-operator:latest
createdAt: "2024-03-12T12:20:22Z"
createdAt: "2024-03-20T12:29:04Z"
operators.operatorframework.io/builder: operator-sdk-v1.32.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: https://github.com/Kuadrant/kuadrant-operator
Expand Down
3 changes: 3 additions & 0 deletions bundle/manifests/kuadrant.io_dnspolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ spec:
- simple
- loadbalanced
type: string
x-kubernetes-validations:
- message: RoutingStrategy is immutable
rule: self == oldSelf
targetRef:
description: |-
PolicyTargetReference identifies an API object to apply a direct or
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/kuadrant.io_dnspolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ spec:
- simple
- loadbalanced
type: string
x-kubernetes-validations:
- message: RoutingStrategy is immutable
rule: self == oldSelf
targetRef:
description: |-
PolicyTargetReference identifies an API object to apply a direct or
Expand Down
11 changes: 11 additions & 0 deletions controllers/dnspolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ var _ = Describe("DNSPolicy controller", func() {
}, TestTimeoutMedium, time.Second).Should(Succeed())
})

It("should not allow changing routing strategy", func() {
Eventually(func(g Gomega) {
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(dnsPolicy), dnsPolicy)
g.Expect(err).NotTo(HaveOccurred())
dnsPolicy.Spec.RoutingStrategy = v1alpha1.LoadBalancedRoutingStrategy
err = k8sClient.Update(ctx, dnsPolicy)
g.Expect(err).To(HaveOccurred())
g.Expect(err).To(MatchError(ContainSubstring("RoutingStrategy is immutable")))
}, TestTimeoutMedium, time.Second).Should(Succeed())
})

It("should not have any health check records created", func() {
// create a health check with the labels for the dnspolicy and the gateway name and namespace that would be expected in a valid target scenario
// this one should get deleted if the gateway is invalid policy ref
Expand Down
2 changes: 1 addition & 1 deletion doc/reference/dnspolicy.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
| `targetRef` | [Gateway API PolicyTargetReference](https://gateway-api.sigs.k8s.io/geps/gep-713/?h=policytargetreference#policy-targetref-api) | Yes | Reference to a Kuberentes resource that the policy attaches to |
| `healthCheck` | [HealthCheckSpec](#healthcheckspec) | No | HealthCheck spec |
| `loadBalancing` | [LoadBalancingSpec](#loadbalancingspec) | No | LoadBancking Spec |
| `routingStrategy` | String | Yes | Routing Strategy to use, one of "simple" or "loadbalacned" |
| `routingStrategy` | String (immutable) | Yes | **Immutable!** Routing Strategy to use, one of "simple" or "loadbalacned" |

## HealthCheckSpec

Expand Down

0 comments on commit bdb99cd

Please sign in to comment.