Skip to content

Add MeshSync spec validation to reconciliation loop#743

Open
ahmedmadbouly186 wants to merge 2 commits into
meshery:masterfrom
ahmedmadbouly186:feat/ahmed_madbouly/375
Open

Add MeshSync spec validation to reconciliation loop#743
ahmedmadbouly186 wants to merge 2 commits into
meshery:masterfrom
ahmedmadbouly186:feat/ahmed_madbouly/375

Conversation

@ahmedmadbouly186

Copy link
Copy Markdown

Description

This PR fixes #375

Notes for Reviewers
This issue opened in MeshSync, but I see it needs to be implemented here for the following reasons

Why this belongs in meshery-operator, not meshsync

The MeshSync CRD is defined and owned by meshery-operator. Its controller (MeshSyncReconciler)
is the first process to handle a MeshSync resource — running before the MeshSync pod is ever scheduled. This means:

  • Validation here prevents a bad spec from ever reaching deployment
  • The controller can write a ValidationFailed status condition back to the CR, visible via kubectl describe meshsync
  • The meshsync app only runs after the operator has already deployed it — by then it's too late to prevent a broken Deployment from being created

meshsync already has its own config validation in crd_config.go (validateLists), but that validates
watch-list content at runtime, not the CR spec at admission time. These are complementary layers, not duplicates.

This issue tracks the operator-side gap. The meshsync-side validation (crd_config.go) is complete as-is.

Signed commits

  • Yes, I signed my commits.

Signed-off-by: ahmedmadbouly186 <66012617+ahmedmadbouly186@users.noreply.github.com>

@miacycle miacycle 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.

@ahmedmadbouly186, positive progress so far.

It would be helpful to users if these validation errors aren't just logged to stdout, but are also sent to Meshery Server for users to be aware of.

// validateSpec validates the MeshSync spec before reconciliation
func (r *MeshSyncReconciler) validateSpec(_ context.Context, log logr.Logger, baseResource *mesheryv1alpha1.MeshSync) error {
spec := baseResource.Spec
nullNative := mesheryv1alpha1.NativeMeshsyncBroker{}

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.

Why the name "nullNative"?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

to represent that the native broker is empty and doesn't have either Name or Namespace

hasCustom := spec.Broker.Custom.URL != ""

// 1. Broker: at least one must be configured
if !hasNative && !hasCustom {

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.

What does "Native" mean in this context?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This refers to a broker that Meshery itself deployed and manages inside the cluster, and Meshery Operator manages the lifecycle of the broker that Meshery uses for data streaming across the cluster and the outside world.

Comment thread controllers/meshsync_controller.go Outdated

// Validate spec before any side effects
if err := r.validateSpec(ctx, log, baseResource); err != nil {
log.Error(err, "MeshSync spec validation failed")

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.

"MeshSync spec validation failed"

It would be a little more accurate and informative to operators of Meshery if:

  1. The name of the MeshSync custom resource was included.
  2. The message is changed to something like "MeshSync resource '' configuration invalid."

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

acknowledged

Signed-off-by: ahmedmadbouly186 <66012617+ahmedmadbouly186@users.noreply.github.com>
Complete(r)
}

func (r *MeshSyncReconciler) validateBrokerConfig(Broker mesheryv1alpha1.MeshsyncBroker) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is different from reconcileBrokerConfig func, as it is fine with one of them set the custom url or the native, also the checks are embeded later for safety checks, you might want to adjust the funcs

}

// Get broker configuration
if err := r.reconcileBrokerConfig(ctx, baseResource); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

refactore this func to remove the validaiton inline

@leecalcote

Copy link
Copy Markdown
Member

Strong direction here, and your reasoning for why validation belongs in the operator rather than in meshsync is correct.

We are keeping this and iterating it inside Workstreams 2 and 3, which introduce the v1alpha2 API, server-side-apply reconciliation, and proper status conditions. Two pieces of earlier review feedback should land as part of that: include the CR name in the message (something like MeshSync resource "<name>" configuration invalid) per the earlier note, and surface validation failures to the CR status and onward to Meshery Server rather than only logging to stdout, per miacycle's note. The nullNative naming and the inline-validation refactor that Amr-Shams flagged are also worth folding in.

We will rebase this onto the modernized reconciler rather than supersede it, and the new errors will be declared as MeshKit structured errors so they carry a stable code and remediation.

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.

Improve CRD validation and configuration initialization logic in the controller

4 participants