Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: target status -> discoverability reconciler #958

Merged
merged 9 commits into from
Nov 5, 2024

Conversation

KevFan
Copy link
Contributor

@KevFan KevFan commented Oct 25, 2024

Description

Closes: #830 #829 #828 #827

  • Refactors target status controller to seperate gateway and http route discoverability reconcilers
  • Adds xPolicyAffected condition to Listeners status, listing accepted policies targeting the gateway and the listener (if any)
  • Refactors xPolicyAffected condtions to list accepted policies in path that may affect the targetablle
    • Eg. Gateway condition will list only gateway policies, Listener status condition will list both gateway and listener policies, Route condition will list Gateway, Listener and route policies

Verification

  • Create cluster
make local-setup
  • Create gateway RLP
kubectl apply -n gateway-system -f - <<EOF                                                                                                                     
apiVersion: kuadrant.io/v1beta3
kind: RateLimitPolicy
metadata:      
  name: gw-rlp           
spec:        
  targetRef:       
    group: gateway.networking.k8s.io
    kind: Gateway    
    name: kuadrant-ingressgateway
  overrides:      
    limits:         
      "global":   
        rates:   
        - limit: 5
          duration: 10
          unit: second        
        when:      
        - selector: source.address
          operator: neq  
          value: 127.0.0.1
    strategy: merge
EOF
  • Verify Gateway kuadrant.io/RateLimitPolicyAffected condition is Object affected by RateLimitPolicy [gateway-system/gw-rlp] for Gateway.Status.Condtions and Gateway.Status.Listener[].Condition
kubectl get gateway kuadrant-ingressgateway -n gateway-system -o yaml | yq '.status'
  • Create HTTP Route
kubectl apply -f - <<EOF
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute 
metadata:
  name: toystore
spec:                               
  parentRefs:      
  - name: kuadrant-ingressgateway
    namespace: gateway-system
  hostnames:       
  - api.toystore.com  
  rules:       
  - matches:          
    - method: GET     
      path:                   
        type: PathPrefix  
        value: "/cars"            
    - method: GET      
      path:               
        type: PathPrefix
        value: "/dolls"                                                                                         
    backendRefs:                           
    - name: toystore
      port: 80
  - matches:
    - path:
        type: PathPrefix
        value: "/admin"
    backendRefs:
    - name: toystore
      port: 80
EOF
  • Verify HTTP Route kuadrant.io/RateLimitPolicyAffected condition is Object affected by RateLimitPolicy [gateway-system/gw-rlp] for Route.Status.Condtions
 kubectl get httproute toystore -o yaml | yq '.status'
  • Creation section name rlp
kubectl apply -n gateway-system -f - <<EOF              
apiVersion: kuadrant.io/v1beta3
kind: RateLimitPolicy
metadata:
  name: section-rlp
spec:
  targetRef:
    group: gateway.networking.k8s.io
    kind: Gateway
    name: kuadrant-ingressgateway
    sectionName: http
  limits:
    "specific":
      rates:
      - limit: 3
        duration: 5
        unit: second
      - limit: 20
        duration: 1
        unit: minute
EOF
  • Verify the gw-rlp is listed along with section-rlp for the targeted listener. All other listener status and the parent gatway condition should only list gw-rlp
kubectl get gateway kuadrant-ingressgateway -n gateway-system -o yaml | yq '.status'
  • Verify http route condition also lists gw-rlp and section-rlp in the affection condition
 kubectl get httproute toystore -o yaml | yq '.status' 
  • Create Route RLP
kubectl apply -f - <<EOF                 
apiVersion: kuadrant.io/v1beta3
kind: RateLimitPolicy
metadata:
  name: route-rlp
spec:
  targetRef:
    group: gateway.networking.k8s.io
    kind: HTTPRoute
    name: toystore
  limits:
    "specific":
      rates:
      - limit: 3
        duration: 5
        unit: second
      - limit: 20
        duration: 1
        unit: minute
EOF
  • Verify http route condition also lists route-rlp, section-rlp and gw-rlp and in the affection condition
  • Verify route-rlp is not listed in the gateway or gateway listener status

conditions := gw.Status.DeepCopy().Conditions

// TODO: What happens for multiple policies of the same kind -
// TODO: Should it be conditions per listener?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say so. TLSPolicy and DNSPolicy still don't support targeting individual listeners (#891), but the AuthPolicy and RateLimitPolicy do.

Copy link
Contributor Author

@KevFan KevFan Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I've something working where the Gateway.Status.Conditions[XPolicyAffected] lists xPolicies that just specifically targets the gateway. The listener status in Gateway.Status.ListenersStatus will list inherited gateway policies and policies targetting specifically the listener. I think this is nicer and more informative to at least know which policies affect which sections of the gateway 🤔

Example:

conditions:
  - lastTransitionTime: "2024-10-29T09:30:44Z"
    message: Resource accepted
    observedGeneration: 1
    reason: Accepted
    status: "True"
    type: Accepted
  - lastTransitionTime: "2024-10-29T09:30:49Z"
    message: Resource programmed, assigned to service(s) kuadrant-ingressgateway-istio.gateway-system.svc.cluster.local:80
    observedGeneration: 1
    reason: Programmed
    status: "True"
    type: Programmed
  - lastTransitionTime: "2024-10-29T09:37:57Z"
    message: Object affected by RateLimitPolicy [gateway-system/gw-rlp]
    observedGeneration: 1
    reason: Accepted
    status: "True"
    type: kuadrant.io/RateLimitPolicyAffected
listeners:
  - attachedRoutes: 0
    conditions:
      - lastTransitionTime: "2024-10-29T09:30:44Z"
        message: No errors found
        observedGeneration: 1
        reason: Accepted
        status: "True"
        type: Accepted
      - lastTransitionTime: "2024-10-29T09:30:44Z"
        message: No errors found
        observedGeneration: 1
        reason: NoConflicts
        status: "False"
        type: Conflicted
      - lastTransitionTime: "2024-10-29T09:30:44Z"
        message: No errors found
        observedGeneration: 1
        reason: Programmed
        status: "True"
        type: Programmed
      - lastTransitionTime: "2024-10-29T09:30:44Z"
        message: No errors found
        observedGeneration: 1
        reason: ResolvedRefs
        status: "True"
        type: ResolvedRefs
      - lastTransitionTime: "2024-10-29T09:37:39Z"
        message: Object affected by RateLimitPolicy [gateway-system/gw-rlp gateway-system/section-rlp]
        observedGeneration: 1
        reason: Accepted
        status: "True"
        type: kuadrant.io/RateLimitPolicyAffected
    name: http
    supportedKinds:
      - group: gateway.networking.k8s.io
        kind: HTTPRoute
      - group: gateway.networking.k8s.io
        kind: GRPCRoute

What do you think? 🤔

for _, policyKind := range policyKinds {
// Policies targeting gateway and listeners
path := []machinery.Targetable{gw}
path = append(path, topology.Targetables().Children(gw)...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this will not work on Gateways with 2+ listeners. It would yield a path Gateway → Listener 1 → Listener 2 → … → Listener N

@KevFan KevFan force-pushed the discoverability branch 3 times, most recently from b6680c5 to ade9318 Compare November 1, 2024 20:59
@KevFan KevFan marked this pull request as ready for review November 4, 2024 09:30
@KevFan KevFan self-assigned this Nov 4, 2024
Copy link
Contributor

@Boomatang Boomatang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionally it seems better than before. I compared the status of the gateways and httproutes on the this branch and off main. The setup I used has bad tls configurations which cause errors. In this work those error were reported better. This work also show what DNS policies affected a httproute in the httproute status. I am assuming this was an improvement and not an error in the implementation.

The only comments I have is on the structure of the code its self. It is stuff that I feel we should address but at the same time I am okay if we address it after GA.

@KevFan
Copy link
Contributor Author

KevFan commented Nov 4, 2024

@Boomatang Thanks for the review 👍

On:

This work also show what DNS policies affected a httproute in the httproute status. I am assuming this was an improvement and not an error in the implementation.

This was an unintentional improvement from the refactor from simply including the DNSPolicy and TLSPolicy in the http route discoverability reconciler loop:

  • func policyGroupKinds() []*schema.GroupKind {
    return []*schema.GroupKind{
    &kuadrantv1beta3.AuthPolicyGroupKind,
    &kuadrantv1beta3.RateLimitPolicyGroupKind,
    &kuadrantv1alpha1.TLSPolicyGroupKind,
    &kuadrantv1alpha1.DNSPolicyGroupKind,
    }

I think it's a nice addition, but not sure do we want this in general to have the xPoilcyAffection for DNSPolicy and TLSPolicy for Routes like RateLimitPolicy and AuthPolicy previous to this refactor 🤔

Maybe @mikenairn @guicassolato or @maleck13 can comment if we want this for DNSPolicy and TLSPolicy

@maleck13
Copy link
Collaborator

maleck13 commented Nov 5, 2024

Well for me it comes down to is this useful for the end user. I think it is useful to know your HTTPRoute is covered by TLSPolicy or DNSPolicy. Do you have an example of the status message? I only would have a concern if we were leaking additional info but I doubt we are so +1 from me

Copy link
Contributor

@Boomatang Boomatang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me.

@mikenairn
Copy link
Member

I think it's a nice addition, but not sure do we want this in general to have the xPoilcyAffection for DNSPolicy and TLSPolicy for Routes like RateLimitPolicy and AuthPolicy previous to this refactor 🤔

I see no issue with it, makes sense to show that it is affected by these policies also.

@KevFan
Copy link
Contributor Author

KevFan commented Nov 5, 2024

Do you have an example of the status message?

@maleck13 This would be an example status condition for TLSPolicy on a HTTPRoute (DNSPolicy will look similar):

    status:
      parents:
        - conditions:
            - lastTransitionTime: "2024-11-05T09:47:22Z"
              message: Object affected by TLSPolicy [istio-system/gw-tls]
              observedGeneration: 1
              reason: Accepted
              status: "True"
              type: kuadrant.io/TLSPolicyAffected
          controllerName: kuadrant.io/policy-controller
          parentRef:
            group: gateway.networking.k8s.io
            kind: Gateway
            name: istio-ingressgateway
            namespace: istio-system

A more complicated one for say RateLimitPolicy with multiple policies on different targets along the path would look like this for a HTTPRoute:

  - conditions:
      - lastTransitionTime: "2024-11-05T09:51:35Z"
        message: Object affected by RateLimitPolicy [default/route-rlp gateway-system/section-rlp gateway-system/gw-rlp]
        observedGeneration: 1
        reason: Accepted
        status: "True"
        type: kuadrant.io/RateLimitPolicyAffected
    controllerName: kuadrant.io/policy-controller
    parentRef:
      group: gateway.networking.k8s.io
      kind: Gateway
      name: kuadrant-ingressgateway
      namespace: gateway-system

@maleck13
Copy link
Collaborator

maleck13 commented Nov 5, 2024

Thanks @KevFan looks good. I say merge it

Signed-off-by: KevFan <[email protected]>
@KevFan KevFan requested a review from Boomatang November 5, 2024 12:02
@KevFan KevFan merged commit 87a5613 into Kuadrant:main Nov 5, 2024
26 checks passed
maleck13 pushed a commit that referenced this pull request Nov 13, 2024
* refactor: initial target status -> gateway policy discoverability reconciler

Signed-off-by: KevFan <[email protected]>

* refactor: initial target status -> http route policy discoverability reconciler

Signed-off-by: KevFan <[email protected]>

* feat: policyAffectedBy condition is ListenerStatus

Signed-off-by: KevFan <[email protected]>

* refactor: list all policies in httproute affected by condition

Signed-off-by: KevFan <[email protected]>

* refactor: smaller function for gateway discoverability

Signed-off-by: KevFan <[email protected]>

* refactor: breakdown to methods/functions + integration tests

Signed-off-by: KevFan <[email protected]>

* refactor: methods/functions

Signed-off-by: KevFan <[email protected]>

* tests: additional tests for auth, dns and tls

Signed-off-by: KevFan <[email protected]>

* gomod: tidy

Signed-off-by: KevFan <[email protected]>

---------

Signed-off-by: KevFan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[state-of-the-world reconciler] RateLimitPolicy discoverability
5 participants