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

Pass through Pod Affinity Rules #86

Merged
merged 1 commit into from
Sep 5, 2023

Conversation

Boomatang
Copy link
Contributor

Allow Pod Affinity Rules to be defined in the Limitador CR which will be past to the Limitador deployment CR and place in spec.template.spec.affinity.

This change address #76

Validation

  • Run make local-setup
  • Create the Limitador CR with out Pod Affinity Rules
echo "
   apiVersion: limitador.kuadrant.io/v1alpha1
   kind: Limitador
   metadata:
     name: limitador-sample
   spec:
     replicas: 3
     limits:
       - conditions: ["get_toy == 'yes'"]
         max_value: 2
         namespace: toystore-app
         seconds: 30
         variables: []
   " | kubectl apply -f -
  • Expected: deployment has no Affinity Rules
kubectl get deployment limitador-sample -o jsonpath='{.spec.template.spec.affinity}' -n default | jq
  • update the Limitador CR to contain Pod Affinity Rules.
echo "
apiVersion: limitador.kuadrant.io/v1alpha1
kind: Limitador
metadata:
  name: limitador-sample
spec:
  replicas: 3
  affinity:
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
        - weight: 100
          podAffinityTerm:
            labelSelector:
              matchLabels:
                app.kubernetes.io/name: limitador
            topologyKey: kubernetes.io/hostname
        - weight: 99
          podAffinityTerm:
            labelSelector:
              matchLabels:
                app.kubernetes.io/name: limitador
            topologyKey: topology.kubernetes.io/zone
  limits:
    - conditions: ["get_toy == 'yes'"]
      max_value: 2
      namespace: toystore-app
      seconds: 30
      variables: []
   " | kubectl apply -f -
  • Expected: deployment contains Affinity Rules
kubectl get deployment limitador-sample -o jsonpath='{.spec.template.spec.affinity}' -n default | jq
  • Update the Affinity Rules
echo "
apiVersion: limitador.kuadrant.io/v1alpha1
kind: Limitador
metadata:
  name: limitador-sample
spec:
  replicas: 3
  affinity:
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
        - weight: 50
          podAffinityTerm:
            labelSelector:
              matchLabels:
                app.kubernetes.io/name: limitador
            topologyKey: kubernetes.io/hostname
        - weight: 50
          podAffinityTerm:
            labelSelector:
              matchLabels:
                app.kubernetes.io/name: limitador
            topologyKey: topology.kubernetes.io/zone
  limits:
    - conditions: ["get_toy == 'yes'"]
      max_value: 2
      namespace: toystore-app
      seconds: 30
      variables: []
   " | kubectl apply -f -
  • Expected: deployment Affinity weights to be modified.
kubectl get deployment limitador-sample -o jsonpath='{.spec.template.spec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution[*].weight}' -n default | jq
  • Removing Affinity Rules from Limitador CR removes rules from deployment CR
echo "
   apiVersion: limitador.kuadrant.io/v1alpha1
   kind: Limitador
   metadata:
     name: limitador-sample
   spec:
     replicas: 3
     limits:
       - conditions: ["get_toy == 'yes'"]
         max_value: 2
         namespace: toystore-app
         seconds: 30
         variables: []
   " | kubectl apply -f -
  • Expected: deployment has no Affinity Rules
kubectl get deployment limitador-sample -o jsonpath='{.spec.template.spec.affinity}' -n default | jq

@Boomatang Boomatang linked an issue Aug 9, 2023 that may be closed by this pull request
@Boomatang Boomatang self-assigned this Aug 10, 2023
@Boomatang Boomatang added kind/enhancement New feature or request participation/good first issue Good for newcomers target/current size/small area/api CRD or other public API related labels Aug 10, 2023
@Boomatang Boomatang requested a review from a team August 10, 2023 09:41
@Boomatang Boomatang removed their assignment Aug 15, 2023
Copy link
Contributor

@KevFan KevFan left a comment

Choose a reason for hiding this comment

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

Changes looks good 👍

Just have a minor nit 🧑‍💻

pkg/limitador/k8s_objects.go Outdated Show resolved Hide resolved
@Boomatang Boomatang force-pushed the 76-production-ready-configure-pod-affinity branch 2 times, most recently from 03ba93e to 36d82db Compare August 16, 2023 10:24
Allow Pod Affinity Rules to be defined in the Limitador CR which will be past to the Limitador deployment CR and place in `spec.template.spec.affinity`.
@Boomatang Boomatang force-pushed the 76-production-ready-configure-pod-affinity branch from 36d82db to bda6f3d Compare September 4, 2023 09:35
@codecov-commenter
Copy link

Codecov Report

Merging #86 (bda6f3d) into main (beaa93e) will decrease coverage by 2.40%.
The diff coverage is 22.22%.

@@            Coverage Diff             @@
##             main      #86      +/-   ##
==========================================
- Coverage   51.83%   49.44%   -2.40%     
==========================================
  Files          13       13              
  Lines         897      906       +9     
==========================================
- Hits          465      448      -17     
- Misses        394      415      +21     
- Partials       38       43       +5     
Flag Coverage Δ
unit 49.44% <22.22%> (-2.40%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
api/v1alpha1/limitador_types.go 100.00% <ø> (ø)
pkg/reconcilers/deployment.go 21.91% <0.00%> (-2.33%) ⬇️
controllers/limitador_controller.go 42.85% <100.00%> (-3.91%) ⬇️
pkg/limitador/k8s_objects.go 71.72% <100.00%> (+0.14%) ⬆️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@KevFan KevFan left a comment

Choose a reason for hiding this comment

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

Looks good to me ! 👍

@Boomatang Boomatang merged commit 3037c95 into main Sep 5, 2023
13 checks passed
@Boomatang Boomatang deleted the 76-production-ready-configure-pod-affinity branch September 5, 2023 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api CRD or other public API related kind/enhancement New feature or request participation/good first issue Good for newcomers size/small target/current
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Production-ready: Configure Pod Affinity
3 participants