Skip to content

ci(testing): modularise cluster management scripts - #9281

Merged
mnencia merged 26 commits into
mainfrom
dev/testing-tools
Jan 20, 2026
Merged

mnencia merged 26 commits into
mainfrom
dev/testing-tools

Conversation

@gbartolini

@gbartolini gbartolini commented Nov 21, 2025 •

Copy link
Copy Markdown
Contributor

Refactors the monolithic hack/setup-cluster.sh script into a modular framework with clear separation between reusable utilities and vendor-specific provisioning logic.

The new structure introduces hack/testing-tools/k8s-engines/ for infrastructure-specific implementations and hack/testing-tools/common/ for shared utilities. A central manage.sh dispatcher acts as the single entry point, replacing the command-handling logic of the original script by delegating actions (create, teardown, load, etc.) based on the CLUSTER_ENGINE variable.

The kind implementation moves cluster lifecycle operations into dedicated scripts (kind/setup.sh and kind/teardown.sh) alongside add-on deployments for CSI driver and FluentD. All version constants and configuration are consolidated into common/10-config.sh.

Each vendor directory must provide three required scripts: setup.sh for cluster creation, teardown.sh for destruction, and export-logs.sh for debugging. Optional scripts (load.sh and load-helper-images.sh) can provide vendor-specific optimizations with fallbacks to common implementations.

The original hack/setup-cluster.sh becomes a backward compatibility wrapper ensuring existing CI jobs and user workflows continue functioning without changes. It preserves user-specified CLUSTER_NAME values while supporting the same command-line interface.

Wait loops ensure CSI and FluentD deployments reach ready state before proceeding. Conditional deployment flags (ENABLE_CSI_DRIVER, ENABLE_FLUENTD) allow selective feature enablement. Error handling properly exits on missing required vendor scripts rather than silently continuing.

This refactoring significantly improves maintainability and makes it straightforward to add support for additional Kubernetes distributions beyond kind.

Related to #9220

@gbartolini
gbartolini requested a review from a team November 21, 2025 15:01
@dosubot dosubot Bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Nov 21, 2025
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.25 labels Nov 21, 2025
@github-actions

Copy link
Copy Markdown
Contributor

❗ By default, the pull request is configured to backport to all release branches.

  • To stop backporting this pr, remove the label: backport-requested ◀️ or add the label 'do not backport'
  • To stop backporting this pr to a certain release branch, remove the specific branch label: release-x.y

@dosubot dosubot Bot added the chore Intangible work to reduce technical debt label Nov 21, 2025
@gbartolini

Copy link
Copy Markdown
Contributor Author

/test

@github-actions

Copy link
Copy Markdown
Contributor

@gbartolini

Copy link
Copy Markdown
Contributor Author

/test

@github-actions

Copy link
Copy Markdown
Contributor

@gbartolini

Copy link
Copy Markdown
Contributor Author

E2E tests are failing, and I cannot figure out why. The first time I had to add the executable permissions to some kind specific scripts - as it was failing also locally. But now it works locally and I cannot find where the script fails. Will keep investigating, but would not mind a new fresh pair of eyes.

@gbartolini

Copy link
Copy Markdown
Contributor Author

/test

@github-actions

Copy link
Copy Markdown
Contributor

Comment thread hack/testing-tools/common/00-paths.sh Resolved
Comment thread hack/testing-tools/common/10-config.sh Resolved
@gbartolini

Copy link
Copy Markdown
Contributor Author

/test

@github-actions

Copy link
Copy Markdown
Contributor

mnencia and others added 23 commits January 20, 2026 15:38
Signed-off-by: Gabriele Bartolini <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Co-authored-by: danishedb <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Thanks @danishedb

Co-authored-by: danishedb <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Adds multiple improvements to the testing cluster setup scripts:

- Add validation for extracted image variables (POSTGRES_IMG,
  PGBOUNCER_IMG, MINIO_IMG) to fail fast if extraction from source
  files fails
- Fix registry state check to properly verify container is running,
  not just whether inspect command succeeds
- Add URL validation for DOCKER_REGISTRY_MIRROR to prevent potential
  TOML injection vulnerabilities
- Add validate_required_tools function to check for required tools
  (kind, docker, kubectl, helm) before setup begins
- Replace word-splitting prone 'for node in $(kind get nodes)' loops
  with safer 'while read' pattern to handle edge cases

These changes improve error messages, security, and robustness of the
testing infrastructure.

Signed-off-by: Marco Nenciarini <[email protected]>
Move ensure_registry call from low-level function and wrapper to the
central dispatcher for a single check per command.

Before: registry checked twice (wrapper + build function)
After: registry checked once (dispatcher only)

This minimal change consolidates registry setup in manage.sh before
dispatching to action handlers.

Signed-off-by: Marco Nenciarini <[email protected]>
The registry container always listens on port 5000 internally. When Kind
nodes access the registry via docker network (registry.dev), they connect
to the internal port, not the host-exposed port (registry_port variable).

This partially reverts commit d0fe950 which changed hardcoded :5000 to
use ${registry_port} variable. That change was incorrect for Kind node
access via docker network, though it was correct for the intent to make
the host port configurable.

Signed-off-by: Marco Nenciarini <[email protected]>
Distinguish between non-existent container (create with 'docker run')
and stopped container (start with 'docker start') to avoid name
conflict errors when registry is manually stopped.

Signed-off-by: Marco Nenciarini <[email protected]>
@mnencia
mnencia merged commit 381b8fb into main Jan 20, 2026
23 checks passed
@mnencia
mnencia deleted the dev/testing-tools branch January 20, 2026 14:59
cnpg-bot pushed a commit that referenced this pull request Jan 20, 2026
Refactors the monolithic `hack/setup-cluster.sh` script into a modular
framework with clear separation between reusable utilities and
vendor-specific provisioning logic.

The new structure introduces `hack/testing-tools/k8s-engines/` for
infrastructure-specific implementations and `hack/testing-tools/common/`
for shared utilities. A central `manage.sh` dispatcher acts as the
single entry point, replacing the command-handling logic of the original
script by delegating actions (`create`, `teardown`, `load`, etc.) based
on the `CLUSTER_ENGINE` variable.

The kind implementation moves cluster lifecycle operations into
dedicated scripts (`kind/setup.sh` and `kind/teardown.sh`) alongside
add-on deployments for CSI driver and FluentD. All version constants and
configuration are consolidated into `common/10-config.sh`.

Each vendor directory must provide three required scripts: `setup.sh`
for cluster creation, `teardown.sh` for destruction, and
`export-logs.sh` for debugging. Optional scripts (`load.sh` and
`load-helper-images.sh`) can provide vendor-specific optimizations with
fallbacks to common implementations.

The original `hack/setup-cluster.sh` becomes a backward compatibility
wrapper ensuring existing CI jobs and user workflows continue
functioning without changes. It preserves user-specified `CLUSTER_NAME`
values while supporting the same command-line interface.

Wait loops ensure CSI and FluentD deployments reach ready state before
proceeding. Conditional deployment flags (`ENABLE_CSI_DRIVER`,
`ENABLE_FLUENTD`) allow selective feature enablement. Error handling
properly exits on missing required vendor scripts rather than silently
continuing.

This refactoring significantly improves maintainability and makes it
straightforward to add support for additional Kubernetes distributions
beyond kind.

Related to #9220

---------

Signed-off-by: Gabriele Bartolini <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Signed-off-by: Niccolò Fei <[email protected]>
Co-authored-by: Marco Nenciarini <[email protected]>
Co-authored-by: danishedb <[email protected]>
Co-authored-by: Niccolò Fei <[email protected]>
(cherry picked from commit 381b8fb)
cnpg-bot pushed a commit that referenced this pull request Jan 20, 2026
Refactors the monolithic `hack/setup-cluster.sh` script into a modular
framework with clear separation between reusable utilities and
vendor-specific provisioning logic.

The new structure introduces `hack/testing-tools/k8s-engines/` for
infrastructure-specific implementations and `hack/testing-tools/common/`
for shared utilities. A central `manage.sh` dispatcher acts as the
single entry point, replacing the command-handling logic of the original
script by delegating actions (`create`, `teardown`, `load`, etc.) based
on the `CLUSTER_ENGINE` variable.

The kind implementation moves cluster lifecycle operations into
dedicated scripts (`kind/setup.sh` and `kind/teardown.sh`) alongside
add-on deployments for CSI driver and FluentD. All version constants and
configuration are consolidated into `common/10-config.sh`.

Each vendor directory must provide three required scripts: `setup.sh`
for cluster creation, `teardown.sh` for destruction, and
`export-logs.sh` for debugging. Optional scripts (`load.sh` and
`load-helper-images.sh`) can provide vendor-specific optimizations with
fallbacks to common implementations.

The original `hack/setup-cluster.sh` becomes a backward compatibility
wrapper ensuring existing CI jobs and user workflows continue
functioning without changes. It preserves user-specified `CLUSTER_NAME`
values while supporting the same command-line interface.

Wait loops ensure CSI and FluentD deployments reach ready state before
proceeding. Conditional deployment flags (`ENABLE_CSI_DRIVER`,
`ENABLE_FLUENTD`) allow selective feature enablement. Error handling
properly exits on missing required vendor scripts rather than silently
continuing.

This refactoring significantly improves maintainability and makes it
straightforward to add support for additional Kubernetes distributions
beyond kind.

Related to #9220

---------

Signed-off-by: Gabriele Bartolini <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Signed-off-by: Niccolò Fei <[email protected]>
Co-authored-by: Marco Nenciarini <[email protected]>
Co-authored-by: danishedb <[email protected]>
Co-authored-by: Niccolò Fei <[email protected]>
(cherry picked from commit 381b8fb)
mnencia added a commit that referenced this pull request Jan 20, 2026
Refactors the monolithic `hack/setup-cluster.sh` script into a modular
framework with clear separation between reusable utilities and
vendor-specific provisioning logic.

The new structure introduces `hack/testing-tools/k8s-engines/` for
infrastructure-specific implementations and `hack/testing-tools/common/`
for shared utilities. A central `manage.sh` dispatcher acts as the
single entry point, replacing the command-handling logic of the original
script by delegating actions (`create`, `teardown`, `load`, etc.) based
on the `CLUSTER_ENGINE` variable.

The kind implementation moves cluster lifecycle operations into
dedicated scripts (`kind/setup.sh` and `kind/teardown.sh`) alongside
add-on deployments for CSI driver and FluentD. All version constants and
configuration are consolidated into `common/10-config.sh`.

Each vendor directory must provide three required scripts: `setup.sh`
for cluster creation, `teardown.sh` for destruction, and
`export-logs.sh` for debugging. Optional scripts (`load.sh` and
`load-helper-images.sh`) can provide vendor-specific optimizations with
fallbacks to common implementations.

The original `hack/setup-cluster.sh` becomes a backward compatibility
wrapper ensuring existing CI jobs and user workflows continue
functioning without changes. It preserves user-specified `CLUSTER_NAME`
values while supporting the same command-line interface.

Wait loops ensure CSI and FluentD deployments reach ready state before
proceeding. Conditional deployment flags (`ENABLE_CSI_DRIVER`,
`ENABLE_FLUENTD`) allow selective feature enablement. Error handling
properly exits on missing required vendor scripts rather than silently
continuing.

This refactoring significantly improves maintainability and makes it
straightforward to add support for additional Kubernetes distributions
beyond kind.

Related to #9220

---------

Signed-off-by: Gabriele Bartolini <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Signed-off-by: Niccolò Fei <[email protected]>
Co-authored-by: Marco Nenciarini <[email protected]>
Co-authored-by: danishedb <[email protected]>
Co-authored-by: Niccolò Fei <[email protected]>
(cherry picked from commit 381b8fb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-requested ◀️ This pull request should be backported to all supported releases chore Intangible work to reduce technical debt lgtm This PR has been approved by a maintainer ok to merge 👌 This PR can be merged release-1.28 size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants