mirror of
https://github.com/dsx-ai-factory/nvke.git
synced 2026-12-07 04:35:58 +08:00
* build: bump the go-dependencies group across 1 directory with 8 updates Bumps the go-dependencies group with 8 updates in the / directory: | Package | From | To | | --- | --- | --- | | [github.com/prometheus/common](https://github.com/prometheus/common) | `0.73.1` | `0.74.0` | | [golang.org/x/crypto](https://github.com/golang/crypto) | `0.58.0` | `0.59.0` | | [github.com/cedar-policy/cedar-go](https://github.com/cedar-policy/cedar-go) | `1.9.0` | `1.9.2` | | [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) | `0.152.0` | `0.153.0` | | go.temporal.io/api | `1.64.2` | `1.64.3` | | go.temporal.io/sdk | `1.50.0` | `1.51.0` | | [golang.org/x/mod](https://github.com/golang/mod) | `0.42.0` | `0.43.0` | | [google.golang.org/api](https://github.com/googleapis/google-api-go-client) | `0.311.0` | `0.315.0` | Updates `github.com/prometheus/common` from 0.73.1 to 0.74.0 - [Release notes](https://github.com/prometheus/common/releases) - [Changelog](https://github.com/prometheus/common/blob/main/CHANGELOG.md) - [Commits](https://github.com/prometheus/common/compare/v0.73.1...v0.74.0) Updates `golang.org/x/crypto` from 0.58.0 to 0.59.0 - [Commits](https://github.com/golang/crypto/compare/v0.58.0...v0.59.0) Updates `github.com/cedar-policy/cedar-go` from 1.9.0 to 1.9.2 - [Release notes](https://github.com/cedar-policy/cedar-go/releases) - [Commits](https://github.com/cedar-policy/cedar-go/compare/v1.9.0...v1.9.2) Updates `github.com/getkin/kin-openapi` from 0.152.0 to 0.153.0 - [Release notes](https://github.com/getkin/kin-openapi/releases) - [Commits](https://github.com/getkin/kin-openapi/compare/v0.152.0...v0.153.0) Updates `go.temporal.io/api` from 1.64.2 to 1.64.3 Updates `go.temporal.io/sdk` from 1.50.0 to 1.51.0 Updates `golang.org/x/mod` from 0.42.0 to 0.43.0 - [Commits](https://github.com/golang/mod/compare/v0.42.0...v0.43.0) Updates `google.golang.org/api` from 0.311.0 to 0.315.0 - [Release notes](https://github.com/googleapis/google-api-go-client/releases) - [Changelog](https://github.com/googleapis/google-api-go-client/blob/main/CHANGES.md) - [Commits](https://github.com/googleapis/google-api-go-client/compare/v0.311.0...v0.315.0) --- updated-dependencies: - dependency-name: github.com/prometheus/common dependency-version: 0.74.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-dependencies - dependency-name: golang.org/x/crypto dependency-version: 0.59.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-dependencies - dependency-name: github.com/cedar-policy/cedar-go dependency-version: 1.9.2 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-dependencies - dependency-name: github.com/getkin/kin-openapi dependency-version: 0.153.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-dependencies - dependency-name: go.temporal.io/api dependency-version: 1.64.3 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-dependencies - dependency-name: go.temporal.io/sdk dependency-version: 1.51.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-dependencies - dependency-name: golang.org/x/mod dependency-version: 0.43.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-dependencies - dependency-name: google.golang.org/api dependency-version: 0.315.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-dependencies ... Signed-off-by: dependabot[bot] <support@github.com> * build: regenerate notices and workspace, move to DescribeWorkflow Regenerate the third-party notices and go.work.sum for the dependency bumps. Replace the deprecated Temporal DescribeWorkflowExecution with DescribeWorkflow, which the Temporal SDK 1.51.0 bump flags under SA1019. Signed-off-by: dbudris <dbudris@nvidia.com> * build: align workspace manifests after rebase and migrate the gofail teardown test to DescribeWorkflow Signed-off-by: dbudris <dbudris@nvidia.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dbudris <dbudris@nvidia.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
171 lines
6.5 KiB
Go
171 lines
6.5 KiB
Go
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package controlplane
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"sort"
|
|
|
|
enums "go.temporal.io/api/enums/v1"
|
|
workflowpb "go.temporal.io/api/workflow/v1"
|
|
"go.temporal.io/sdk/client"
|
|
|
|
"github.com/dsx-ai-factory/nvke/controller/internal/constants"
|
|
"github.com/dsx-ai-factory/nvke/controller/internal/db"
|
|
"github.com/dsx-ai-factory/nvke/controller/internal/nodes"
|
|
"github.com/dsx-ai-factory/nvke/controller/internal/otelx"
|
|
"github.com/dsx-ai-factory/nvke/controller/internal/temporal/workflows"
|
|
)
|
|
|
|
// reconcileRequestedDeletes turns accepted control-plane node deletes into
|
|
// teardowns, one per cluster at a time.
|
|
//
|
|
// DELETE /nodes/{id} does not tear a control-plane node down inline under this
|
|
// flag: it records the request and returns 202, and this loop owns when the
|
|
// teardown actually starts. Serializing here is what keeps two etcd member
|
|
// removals from overlapping, which no teardown-time dry-run can prevent once
|
|
// both workflows are already running.
|
|
//
|
|
// It reports whether a teardown was started, so the caller can let the resulting
|
|
// node write re-enqueue the cluster instead of acting on a stale snapshot.
|
|
func (r *reconciler) reconcileRequestedDeletes(
|
|
ctx context.Context,
|
|
cluster db.Cluster,
|
|
cp *controlPlane,
|
|
) (bool, error) {
|
|
requested := cp.nodesWithDeleteRequested()
|
|
|
|
logger := r.logger.With(
|
|
"clusterID", cluster.ID,
|
|
"clusterName", cluster.Name,
|
|
"requestedDeletes", len(requested),
|
|
)
|
|
|
|
// The in-flight check runs before the "nothing requested" return on purpose.
|
|
// A teardown whose workflow closed without completing is not in flight, and
|
|
// nothing else retries it: the outbox marks its entry processed as soon as
|
|
// the workflow starts, so the node keeps Deleting for good. That one row then
|
|
// defers every later control-plane delete, join, remediation and rollout, and
|
|
// still counts toward the control plane's size, so no replacement is built
|
|
// either. A wedged cluster has no requested deletes left, so returning early
|
|
// would never look at it.
|
|
if deleting, ok := cp.nodeTearingDown(); ok {
|
|
restarted, err := r.restartFailedTeardown(ctx, deleting)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
if restarted {
|
|
return true, nil
|
|
}
|
|
if len(requested) == 0 {
|
|
return false, nil
|
|
}
|
|
logger.Info("Deferring control-plane node delete: another teardown is already in flight",
|
|
"inFlightNodeID", deleting.ID,
|
|
"inFlightNodeName", deleting.Name,
|
|
)
|
|
return false, nil
|
|
}
|
|
|
|
if len(requested) == 0 {
|
|
return false, nil
|
|
}
|
|
|
|
next := selectNextControlPlaneNodeToDelete(requested)
|
|
nodeLogger := logger.With("nodeID", next.ID, "nodeName", next.Name)
|
|
|
|
if err := nodes.StartRequestedTeardown(ctx, r.db, next.ID); err != nil {
|
|
return false, fmt.Errorf("starting teardown for requested control-plane node delete %s (%s): %w", next.ID, next.Name, err)
|
|
}
|
|
|
|
nodeLogger.Info("Started teardown for a requested control-plane node delete")
|
|
return true, nil
|
|
}
|
|
|
|
// restartFailedTeardown starts a fresh TeardownNode run for a node whose last
|
|
// run closed without completing, and reports whether it started one.
|
|
//
|
|
// Same shape as joinWorkflowStatus above and reconcileK8sUpgrade: Temporal keeps
|
|
// returning the closed execution, so without an explicit restart the node stays
|
|
// Deleting forever. TeardownNode is idempotent step by step -- the cancels treat
|
|
// a missing workflow as success, the drain and the kube Node delete ignore a
|
|
// node that is already gone, the CAPI deletes ignore NotFound, and the agent's
|
|
// etcd member removal succeeds when the member is absent -- so a second run
|
|
// picks up wherever the first stopped.
|
|
func (r *reconciler) restartFailedTeardown(ctx context.Context, node db.Node) (bool, error) {
|
|
if r.controllerTemporalClient == nil {
|
|
return false, nil
|
|
}
|
|
|
|
workflowID := constants.TeardownNodeWorkflowPrefix + node.ID.String()
|
|
desc, err := r.controllerTemporalClient.DescribeWorkflow(ctx, workflowID, "")
|
|
if err != nil {
|
|
if isWorkflowNotFoundError(err) {
|
|
// The outbox has not delivered the start yet. Leave it alone.
|
|
return false, nil
|
|
}
|
|
return false, fmt.Errorf("describing teardown workflow for node %s: %w", node.ID, err)
|
|
}
|
|
if !teardownClosedUnsuccessfully(desc.RawResponse.GetWorkflowExecutionInfo()) {
|
|
return false, nil
|
|
}
|
|
|
|
input, err := nodes.RestartTeardownInput(node)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
ctx, span := otelx.StartWorkflowSpan(ctx, otelx.WorkflowStart, otelx.WorkflowAttributes{
|
|
WorkflowType: constants.TeardownNodeWorkflowType,
|
|
WorkflowID: workflowID,
|
|
ClusterID: node.ClusterID,
|
|
NodePoolID: node.NodePoolID,
|
|
NodeID: node.ID,
|
|
NodeName: node.Name,
|
|
})
|
|
run, err := r.controllerTemporalClient.ExecuteWorkflow(ctx, client.StartWorkflowOptions{
|
|
ID: workflowID,
|
|
TaskQueue: r.cfg.TemporalTaskQueue,
|
|
WorkflowIDConflictPolicy: enums.WORKFLOW_ID_CONFLICT_POLICY_USE_EXISTING,
|
|
WorkflowIDReusePolicy: enums.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY,
|
|
}, workflows.TeardownNode, input)
|
|
otelx.EndWorkflowSpan(span, err)
|
|
if err != nil {
|
|
return false, fmt.Errorf("restarting teardown workflow for node %s (%s): %w", node.ID, node.Name, err)
|
|
}
|
|
|
|
r.logger.WarnContext(ctx, "Restarted a control-plane node teardown whose workflow closed without completing",
|
|
"node_id", node.ID,
|
|
"node_name", node.Name,
|
|
"workflow_id", workflowID,
|
|
"run_id", run.GetRunID(),
|
|
)
|
|
return true, nil
|
|
}
|
|
|
|
// teardownClosedUnsuccessfully reports whether a described TeardownNode run has
|
|
// finished and did not complete, so nothing will finish that teardown unless a
|
|
// new run starts.
|
|
func teardownClosedUnsuccessfully(info *workflowpb.WorkflowExecutionInfo) bool {
|
|
return info.GetCloseTime() != nil && info.GetStatus() != enums.WORKFLOW_EXECUTION_STATUS_COMPLETED
|
|
}
|
|
|
|
// selectNextControlPlaneNodeToDelete picks the request that has been waiting
|
|
// longest, so a queue of accepted deletes drains in the order it was accepted
|
|
// and no request starves behind a newer one. Ties break on node ID to keep the
|
|
// choice stable across reconciles.
|
|
func selectNextControlPlaneNodeToDelete(requested []db.Node) db.Node {
|
|
sorted := make([]db.Node, len(requested))
|
|
copy(sorted, requested)
|
|
sort.Slice(sorted, func(i, j int) bool {
|
|
a, b := sorted[i].Conditions.DeleteRequested, sorted[j].Conditions.DeleteRequested
|
|
if !a.LastTransitionTime.Equal(b.LastTransitionTime) {
|
|
return a.LastTransitionTime.Before(b.LastTransitionTime)
|
|
}
|
|
return sorted[i].ID.String() < sorted[j].ID.String()
|
|
})
|
|
return sorted[0]
|
|
}
|