Skip to content

Implement config validation - #210

Merged
nirs merged 6 commits into
RamenDR:mainfrom
nirs:validate-config
Jul 7, 2025
Merged

Implement config validation#210
nirs merged 6 commits into
RamenDR:mainfrom
nirs:validate-config

Conversation

@nirs

@nirs nirs commented Jul 1, 2025

Copy link
Copy Markdown
Member

Add validation package for decoupling the command from the actual validation code. The package provides a Validation interface and a Backend implementing the interface.

The validate.Command uses now the backend to implement config validation.

Fixes #203

@nirs
nirs requested a review from parikshithb July 1, 2025 17:53
@nirs

nirs commented Jul 1, 2025

Copy link
Copy Markdown
Member Author

Example run

% ramenctl validate clusters -o validate
⭐ Using config "config.yaml"
⭐ Using report "validate"

🔎 Validate config ...
   ✅ Config validated

🔎 Validate clusters ...
   ✅ Cluster "hub" validated
   ✅ Cluster "dr1" validated
   ✅ Cluster "dr2" validated

✅ Validation completed

Log

2025-07-01T21:23:19.176+0300    INFO    env/env.go:118  Using "hub" cluster name: "hub"
2025-07-01T21:23:19.187+0300    INFO    env/env.go:130  Detected "c1" managed cluster name: "dr1"
2025-07-01T21:23:19.193+0300    INFO    env/env.go:130  Detected "c2" managed cluster name: "dr2"
2025-07-01T21:23:19.193+0300    INFO    validate/command.go:144 Step "validate config" started
2025-07-01T21:23:19.198+0300    INFO    validation/distro.go:51 Detected kubernetes distribution: "k8s"
2025-07-01T21:23:19.198+0300    INFO    validation/distro.go:52 Using namespaces: {RamenHubNamespace:ramen-system RamenDRClusterNamespace:ramen-system RamenOpsNamespace:ramen-ops ArgocdNamespace:argocd}
2025-07-01T21:23:19.204+0300    INFO    validation/ocm.go:39    Validated clusters ["dr1", "dr2"] in clusterSet "default"
2025-07-01T21:23:19.204+0300    INFO    validate/command.go:150 Step "validate config" passed
2025-07-01T21:23:19.204+0300    INFO    validate/command.go:144 Step "validate clusters" started
2025-07-01T21:23:19.204+0300    INFO    validate/command.go:173 Step "validate clusters" finished

Report

build:
  commit: 122fe048fdec8917ada9156ce1847bf9611edd5a
  version: v0.7.0-34-g122fe04
config:
  clusterSet: default
  clusters:
    c1:
      kubeconfig: /Users/nir/.config/drenv/rdr/kubeconfigs/dr1
    c2:
      kubeconfig: /Users/nir/.config/drenv/rdr/kubeconfigs/dr2
    hub:
      kubeconfig: /Users/nir/.config/drenv/rdr/kubeconfigs/hub
  distro: k8s
  namespaces:
    argocdNamespace: argocd
    ramenDRClusterNamespace: ramen-system
    ramenHubNamespace: ramen-system
    ramenOpsNamespace: ramen-ops
created: "2025-07-01T21:23:19.193189+03:00"
duration: 0.010914209
host:
  arch: arm64
  cpus: 12
  os: darwin
name: validate-clusters
status: passed
steps:
- duration: 0.010905584
  name: validate config
  status: passed
- duration: 8.625e-06
  items:
  - name: hub
    status: passed
  - name: dr1
    status: passed
  - name: dr2
    status: passed
  name: validate clusters
  status: passed

nirs added 4 commits July 6, 2025 17:16
Preparing for adding validation package for decoupling command
management and accessing actual clusters.

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
Setting the distro must update the namespaces. It is nice when this is
done internally by the config.

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
This package is similar to the testing package, decoupling the command
and code accessing real clusters. Unlike the testing package delegating
the work to ramen/e2e, this package implement the actual validation.

The first interface, Validate() is like testing.Testing.Validate(), but
works with validation.Context instead of ramen/e2e/types.Context.

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
Like test.Command, validate.Command is accepting a backend for
performing the actual work. This allows testing the command with a mock
backend without access to real clusters. Testing the actual validation
must be done manually and will be tested by end to end tests later.

Like test.Command we implement the Context interface to decouple the
command from the validation package.

Like test.Command we limit the time we wait for validating the config.

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
@nirs
nirs force-pushed the validate-config branch from 122fe04 to c9b0f9a Compare July 6, 2025 14:16
This is a mock backend that can simulate errors and cancellation for any
operation.

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
@nirs
nirs marked this pull request as ready for review July 6, 2025 15:42
@nirs nirs mentioned this pull request Jul 6, 2025

@parikshithb parikshithb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor comment, otherwise looks great!!

Comment thread pkg/validate/command_test.go Outdated
@nirs
nirs force-pushed the validate-config branch from d6e9661 to dc67936 Compare July 7, 2025 09:25
Add fast tests using a mock backend, validating that the report
represent the command result.

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
@nirs
nirs force-pushed the validate-config branch from dc67936 to 7261cb0 Compare July 7, 2025 09:29
@nirs
nirs merged commit c8cdf8a into RamenDR:main Jul 7, 2025
12 checks passed
@nirs
nirs deleted the validate-config branch July 7, 2025 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Basic validate clusters command

2 participants