Skip to content

Conversation

@jessejlt
Copy link
Member

Summary

  • add shared criteria/owner condition helpers for CRDs
  • enrich ManagementCommand status with criteria and execution conditions
  • update ingestor task and tests to validate new condition flow

Testing

  • go test ./api/v1 ./ingestor/adx
  • go test ./...

@mkeesey mkeesey requested a review from Copilot October 28, 2025 22:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request enhances ManagementCommand status tracking by introducing granular condition types for criteria evaluation and execution states. The changes align ManagementCommand status handling with existing patterns used for Functions.

Key changes include:

  • New condition types (ManagementCommandCriteriaMatch, ManagementCommandExecuted) for tracking different lifecycle stages
  • Extracted shared criteria evaluation logic into reusable helpers (NewCriteriaCondition, FormatClusterLabels)
  • Updated status reporting to persist conditions even when commands are skipped due to criteria mismatches
  • Enhanced error messages with cluster context for better debugging

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
api/v1/managementcommand_types.go Adds new condition constants and helper methods (SetCriteriaMatchCondition, SetExecutionCondition) for granular status tracking
api/v1/managementcommand_types_test.go Tests for new condition setting methods on ManagementCommand
api/v1/criteria_conditions.go Extracts shared criteria condition logic (NewCriteriaCondition, FormatClusterLabels) into reusable functions
api/v1/criteria_conditions_test.go Tests for shared criteria condition helpers
api/v1/function_types.go Refactors to use shared NewCriteriaCondition helper, removes duplicate FormatClusterLabels
api/v1/conditions.go Adds ReasonProgressing constant for in-progress state
ingestor/adx/tasks.go Updates ManagementCommand task execution to set granular conditions for criteria matching and execution states
ingestor/adx/tasks_test.go Updates tests to verify new condition behavior including criteria match and execution conditions

parsed := kustoutil.ParseError(err)
logger.Errorf("Failed to execute management command %s/%s: %v", command.Namespace, command.Name, err)
command.SetExecutionCondition(metav1.ConditionFalse, v1.ReasonManagementCommandExecutionFailed, parsed)
if updErr := t.store.UpdateStatus(ctx, command, fmt.Errorf("%s", parsed)); updErr != nil {
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

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

Wrapping a string error message with fmt.Errorf(\"%s\", parsed) is redundant. Since parsed is already a string from kustoutil.ParseError(err), consider creating the error once and reusing it, or passing the original err to maintain the error chain.

Copilot uses AI. Check for mistakes.
logger.Infof("Successfully executed management command %s.%s", command.Spec.Database, command.Name)
if err := t.store.UpdateStatus(ctx, &command, nil); err != nil {
message := "Management command executed successfully"
if endpoint := strings.TrimSpace(t.kustoCli.Endpoint()); endpoint != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about this conditional. I think the kustoCli instance will pretty much always have an endpoint set on it if we're using it, and that's not really the criteria to know if we're executing against a specific db or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

StatementExecutor does not guarantee that the Endpoint is set, so the check is valid. We could short-circuit the check by hoisting it up the chain; however, the risk is that we leave all ManagementCommand CRDs with their last execution status. So if we have dozens of CRDs in some previous execution state, and we short-circuit the kusto client endpoint check, we leave the CRDs in their previous status condition state, which is misleading. I think the intent with controllers is that each CRD is suppose to reflect its own state.

@jessejlt jessejlt requested a review from mkeesey October 29, 2025 15:19
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.

3 participants