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

Add new Kanister function WaitV2 #1836

Merged
merged 9 commits into from
Jan 10, 2023
Merged

Add new Kanister function WaitV2 #1836

merged 9 commits into from
Jan 10, 2023

Conversation

PrasadG193
Copy link
Contributor

Change Overview

This PR adds new function WaitV2 improved version of existing Wait function which simplifies the condition definition.
Instead of Jsonpath to fetch K8s object value, we can use go-template syntax which can be validated with kubectl.

e.g To check if the deployment is ready, once can form following go-template which can be validated with kubectl -

$ kubectl get deploy -n kanisterwaittest-b58j2 test-deployment-tntfb -o go-template='{{ $available := false }}{{ range $condition := $.status.conditions }}{{ if and (eq .type "Available") (eq .status "True")  }}{{ $available = true }}{{ end }}{{ end }}{{ $available }}' 
true

The same go-template can be used in the WaitV2 function arg to define condition

apiVersion: cr.kanister.io/v1alpha1
kind: Blueprint
metadata:
  name: wait-blueprint
actions:
  backup:
    phases:
    - func: WaitV2
      name: waitForRestoreReady
      args:
        timeout: 5m
        conditions:
          anyOf:
          - condition: '{{ $available := false }}{{ range $condition := $.status.conditions }}{{ if and (eq .type "Available") (eq .status "True") }}{{ $available = true }}{{ end }}{{ end }}{{ $available }}'
            objectReference:
              apiVersion: "v1"
              group: "apps"
              name: "{{ .Object.metadata.name }}"
              namespace: "{{ .Object.metadata.namespace }}"
              resource: "deployments"

Pull request type

Please check the type of change your PR introduces:

  • 🚧 Work in Progress
  • 🌈 Refactoring (no functional changes, no api changes)
  • 🐹 Trivial/Minor
  • 🐛 Bugfix
  • 🌻 Feature
  • 🗺️ Documentation
  • 🤖 Test

Issues

Test Plan

  • 💪 Manual

  • ⚡ Unit test

  • 💚 E2E

  • Added unit tests

  • Manually validated the BP mentioned in the PR description on a deployment

@github-actions
Copy link
Contributor

github-actions bot commented Jan 3, 2023

Thanks for submitting this pull request 🎉. The team will review it soon and get back to you.

If you haven't already, please take a moment to review our project contributing guideline and Code of Conduct document.

@infraq infraq added this to In Progress in Kanister Jan 3, 2023
@PrasadG193
Copy link
Contributor Author

image

Copy link
Contributor

@michaelcourcy michaelcourcy left a comment

Choose a reason for hiding this comment

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

LGTM, I have a small question in the code but I think I auto answer it, otherwise thanks for asking me the review the unit test you wrote were very interesting, the documentation is also very good.

pkg/function/waitv2.go Show resolved Hide resolved
Kanister automation moved this from In Progress to Reviewer approved Jan 3, 2023
Base automatically changed from fix-go-template-jsonpath to master January 9, 2023 19:27
@PrasadG193
Copy link
Contributor Author

Rebased and fixed conflicts. @pavannd1 could you please take a look?

docs/functions.rst Outdated Show resolved Hide resolved
docs/functions.rst Outdated Show resolved Hide resolved
docs/functions.rst Outdated Show resolved Hide resolved
PrasadG193 and others added 8 commits January 10, 2023 19:01
* Switch to go template syntax for Wait conditions

Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>

* Update K8ssandra BP as per the new Wait func syntax

Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>

Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>
Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>
Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>
Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>
Co-authored-by: Pavan Navarathna <6504783+pavannd1@users.noreply.github.com>
Co-authored-by: Pavan Navarathna <6504783+pavannd1@users.noreply.github.com>
Co-authored-by: Pavan Navarathna <6504783+pavannd1@users.noreply.github.com>
@mergify mergify bot merged commit 214da0f into master Jan 10, 2023
Kanister automation moved this from Reviewer approved to Done Jan 10, 2023
@mergify mergify bot deleted the add-func-waitv2 branch January 10, 2023 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

Wait function condition arg should only use go-template an not a mix of jsonpath and go-template
3 participants