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

JSONPath wait-for condition #1872

Closed
cmwylie19 opened this issue Jul 1, 2023 · 0 comments · Fixed by #1873
Closed

JSONPath wait-for condition #1872

cmwylie19 opened this issue Jul 1, 2023 · 0 comments · Fixed by #1873
Assignees
Labels
enhancement ✨ New feature or request

Comments

@cmwylie19
Copy link
Contributor

Is your feature request related to a problem? Please describe.

As a Zarf practitioner, I want to have fine grained control over my wait command in times of automation, complex package deployments, tutorials, etc. I need to get extremely specific in terms of the things that I wait for. The given wait values do not work in certain cases, like for instance for StatefulSets. For these specific use-cases, I need to utilize a JSON path to point to a specific status in the object.

Describe the solution you'd like

  • Given that I issue a zarf tools wait-for
  • When the wait value has this pattern '{.x.y}'=z
  • Then I want zarf to interpret that is a JSONPath wait

Describe alternatives you've considered

Using kubectl

# --for=jsonpath='{}'=value
# Wait for the pod "busybox1" to contain the status phase to be "Running".
kubectl wait --for=jsonpath=“{.status.availableReplicas}”=2 sts/test-sts
kubectl wait --for=jsonpath='{.status.phase}'=Running po/busybox1
kubectl wait --for=jsonpath='{.status.containerStatuses[0].ready}'=true po/busybox1
kubectl wait --for=jsonpath='{.spec.containers[0].ports[0].containerPort}'=80 po/busybox1
kubectl wait --for=jsonpath='{.spec.nodeName}'=knode0 po/busybox1

Additional context

Add any other context or screenshots about the feature request here.

Pain Points:

kubectl create -f -<<EOF
apiVersion: apps/v1
kind: StatefulSet
metadata:
  creationTimestamp: null
  labels:
    app: test-sts
  name: test-sts
spec:
  replicas: 23
  selector:
    matchLabels:
      app: test-sts
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: test-sts
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}
EOF
zarf tools wait-for sts test-sts exists

# Need finer grain control -- I want to know when all the replicas are ready
# ./build/zarf-mac-apple tools wait-for sts test-sts '{.status.availableReplicas}'=23

In the examples/scraping-zarf-agent I am deploying an instance of Prometheus which makes the operator deploy a sts. I don't have a wait for the replicas to be ready and I don't want the user to continue until they are

kind: ZarfPackageConfig
metadata:
  name: scrape-zarf-agent
  yolo: false
  description: Scrape Zarf Agent with Prometheus Operator.

components:
  - name: prometheus-deps
    required: true
    manifests:
      - name: prometheus-deps
        namespace: monitoring
        files:
          - manifests/prometheus-deps/bundle.yaml
    images:
      - quay.io/prometheus-operator/prometheus-operator:v0.66.0
    actions:
      onDeploy:
        after:
          - wait:
              cluster:
                kind: deployment
                name: prometheus-operator
                namespace: monitoring
                condition: available
  - name: prometheus-operator
    required: true
    manifests:
      - name: prometheus-operator
        namespace: monitoring
        files:
        - manifests/prometheus-operator/prometheus.yaml
        - manifests/prometheus-operator/servicemonitor-agent.yaml
        - manifests/prometheus-operator/clusterrole.yaml
        - manifests/prometheus-operator/clusterrolebinding.yaml
    images:
      - quay.io/prometheus/prometheus:v2.45.0
      - quay.io/prometheus-operator/prometheus-config-reloader:v0.66.0
    # This is not gonna work 
    # actions:
    #   onDeploy:
    #     after:
    #       - wait:
    #           cluster:
    #             kind: statefulset
    #             name: forgot-the-name
    #             namespace: monitoring
    #             condition: available
@cmwylie19 cmwylie19 added the enhancement ✨ New feature or request label Jul 1, 2023
@cmwylie19 cmwylie19 self-assigned this Jul 1, 2023
Racer159 pushed a commit that referenced this issue Jul 6, 2023
## Description
Based on the condition in `src/cmd/tools/wait.go`, conditionally decide
betweb a jsonpath or conditon waitType.

## Related Issue

Fixes #1872
<!-- or -->
Relates to #

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

## Checklist before merging

- [x] Test, docs, adr added or updated as needed
- [x] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow)
followed

```bash
┌─[cmwylie19@Cases-MacBook-Pro] - [~/zarf] - [2023-07-01 10:26:32]
└─[0] <git:(1872 8bf6606) > kubectl create -f -<<EOF                                                                                                                                                      
apiVersion: apps/v1
kind: StatefulSet
metadata:
  creationTimestamp: null
  labels:
    app: test-sts
  name: test-sts
spec:
  replicas: 23
  selector:
    matchLabels:
      app: test-sts
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: test-sts
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}
EOF
./build/zarf-mac-apple tools wait-for sts test-sts '{.status.availableReplicas}'=23

statefulset.apps/test-sts created
  ✔  Waiting for sts/test-sts to be {.status.availableReplicas}=23.                                                                                                                              
┌─[cmwylie19@Cases-MacBook-Pro] - [~/zarf] - [2023-07-01 10:27:11]
└─[0] <git:(1872 8bf6606) > k get sts 
NAME       READY   AGE
test-sts   23/23   39s
```

Opens possibility for more complex waits:

```bash
# --for=jsonpath='{}'=value
# Wait for the pod "busybox1" to contain the status phase to be "Running".
kubectl wait --for=jsonpath=“{.status.availableReplicas}”=2 sts/test-sts
kubectl wait --for=jsonpath='{.status.phase}'=Running po/busybox1
kubectl wait --for=jsonpath='{.status.containerStatuses[0].ready}'=true po/busybox1
kubectl wait --for=jsonpath='{.spec.containers[0].ports[0].containerPort}'=80 po/busybox1
kubectl wait --for=jsonpath='{.spec.nodeName}'=knode0 po/busybox1
```

---------

Signed-off-by: Case Wylie <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant