Skip to content

feat: support watch in runs #1343

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

Merged
merged 5 commits into from
Dec 19, 2024

Conversation

ffforest
Copy link
Contributor

@ffforest ffforest commented Dec 17, 2024

What type of PR is this?

What this PR does / why we need it:

Which issue(s) this PR fixes:

Support watching Kubernetes resources during apply:

  • Apply will finish when reconcile is done
  • You can specify custom health policy for each individual resources in workspace configuration
  • You can specify watch timeout (in seconds) in case the synchronous apply takes forever to return
  • When the specified timeout is reached, this watch operation is considered completed and apply will return

Example customized health policy:
workspace.yaml:

context:
  KUBECONFIG_PATH: /Users/forest/.minikube.kubeconfig
modules:
  network:
    path: oci://ghcr.io/kusionstack/network
    version: 0.2.0
    configs:
      default:
        healthPolicy:
          apiVersion: v1
          kind: Service
          health.kcl: |
            # service simple example
            import regex
            watchAnnotationKey = "network.beta.kubernetes.io/watch"
            assert any k in res.metadata.annotations {
              regex.match(k, watchAnnotationKey)
            } if res, "no annotation found"
            if regex.match(res.metadata.annotations[watchAnnotationKey], r"comp.*"):
              assert regex.match(res.metadata.annotations[watchAnnotationKey], r"completed.*")

Example apply curl:
Synchronous apply:

curl --location 'http://localhost:8080/api/v1/stacks/18/apply?workspace=dev&output=json&force=true&unlock=true&watch=true&watchTimeout=20' \
--header 'Content-Type: application/json'

Asynchronous apply:

curl --location 'http://localhost:8080/api/v1/stacks/18/apply/async?workspace=dev&output=json&force=true&unlock=true&watch=true&watchTimeout=20' \
--header 'Content-Type: application/json' \
--data '{
    "stackID": 18,
    "workspace": "dev",
    "type": "apply"
}'

Special notes for your reviewer:

Does this PR introduce a user-facing change?


Additional documentation e.g., design docs, usage docs, etc.:


@ffforest ffforest force-pushed the feat-support-watch-in-runs branch from e86766e to b388708 Compare December 17, 2024 11:02
@ffforest ffforest changed the title Feat support watch in runs Feat: support watch in runs Dec 17, 2024
@ffforest ffforest changed the title Feat: support watch in runs feat: support watch in runs Dec 17, 2024
@ffforest ffforest force-pushed the feat-support-watch-in-runs branch 2 times, most recently from f0364ed to 22a9b85 Compare December 17, 2024 14:30
@ffforest ffforest force-pushed the feat-support-watch-in-runs branch from 4e37426 to 6fe4855 Compare December 19, 2024 06:48
@coveralls
Copy link

coveralls commented Dec 19, 2024

Pull Request Test Coverage Report for Build 12408827065

Details

  • 80 of 422 (18.96%) changed or added relevant lines in 7 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.5%) to 48.453%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/server/handler/stack/utils.go 16 18 88.89%
pkg/engine/runtime/kubernetes/kubernetes_runtime.go 0 3 0.0%
pkg/server/util/logging/logger.go 5 16 31.25%
pkg/server/manager/stack/execute.go 0 21 0.0%
pkg/generators/appconfiguration/app_configurations_generator.go 3 28 10.71%
pkg/engine/api/apply.go 54 334 16.17%
Totals Coverage Status
Change from base Build 12391028413: -0.5%
Covered Lines: 10474
Relevant Lines: 21617

💛 - Coveralls

Copy link
Contributor

@Yangyang96 Yangyang96 left a comment

Choose a reason for hiding this comment

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

LGTM

@ffforest ffforest merged commit 0dec213 into KusionStack:main Dec 19, 2024
8 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 19, 2024
@ffforest ffforest linked an issue Dec 24, 2024 that may be closed by this pull request
@ffforest ffforest added this to the v0.14.0 milestone Dec 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat: Support customized health check in kusion apply API
3 participants