mirror of
https://github.com/dsx-ai-factory/nvke.git
synced 2026-12-07 04:35:58 +08:00
The repository was renamed from dsx-ai-factory/nke to dsx-ai-factory/nvke on 2026-10-10. Its id is unchanged, so guards, rulesets, environments and the OIDC subject carried over, and GitHub redirects the old URLs. The tree still named the old repository where the name is a contract rather than a URL: the module lines of the 12 Go modules and about 1,700 import lines, the proto go_package (embedded in node_agent.pb.go, regenerated here), both THIRD_PARTY_NOTICES.md files (regenerated), the lint local-prefix and depguard entries, ldflags, the go-licenses ignore lists, the documented repository URLs and gh commands, and the ghcr.io/dsx-ai-factory/nke image paths in workflows, the chart default and the e2e defaults. Only the organisation and repository segments change. Directories, identifiers, binary, image, chart, package, label, namespace and environment variable names, the CODEOWNERS team slugs and CHANGELOG.md stay as they are. Closes #1448 Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
76 lines
2.3 KiB
Go
76 lines
2.3 KiB
Go
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package workflows
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"go.temporal.io/sdk/temporal"
|
|
"go.temporal.io/sdk/workflow"
|
|
|
|
"github.com/dsx-ai-factory/nvke/controller/internal/db"
|
|
"github.com/dsx-ai-factory/nvke/controller/internal/temporal/activities"
|
|
)
|
|
|
|
const (
|
|
// runbookEnvTrue is the value runbooks expect for a boolean environment flag.
|
|
runbookEnvTrue = "true"
|
|
)
|
|
|
|
// Add ActivityOptions to the context, tuned for database interactions that should be fast.
|
|
// Indefinite retry with backoff to handle transient database errors.
|
|
func withDBOptions(ctx workflow.Context) workflow.Context {
|
|
return workflow.WithActivityOptions(ctx, workflow.ActivityOptions{
|
|
StartToCloseTimeout: 5 * time.Second,
|
|
RetryPolicy: &temporal.RetryPolicy{
|
|
InitialInterval: 5 * time.Second,
|
|
MaximumInterval: 1 * time.Minute,
|
|
BackoffCoefficient: 2,
|
|
MaximumAttempts: 0, // indefinite retry
|
|
},
|
|
})
|
|
}
|
|
|
|
// Add ActivityOptions for Kubernetes deletions that may block on finalizers.
|
|
func withK8sDeleteWaitOptions(ctx workflow.Context) workflow.Context {
|
|
return workflow.WithActivityOptions(ctx, workflow.ActivityOptions{
|
|
StartToCloseTimeout: 20 * time.Minute,
|
|
HeartbeatTimeout: 30 * time.Second,
|
|
RetryPolicy: &temporal.RetryPolicy{
|
|
InitialInterval: 5 * time.Second,
|
|
MaximumInterval: 1 * time.Minute,
|
|
BackoffCoefficient: 2,
|
|
MaximumAttempts: 0,
|
|
},
|
|
})
|
|
}
|
|
|
|
type nodeMetricLabels struct {
|
|
ClusterName string
|
|
NodeType string
|
|
}
|
|
|
|
func getNodeMetricLabels(ctx workflow.Context, nodeID uuid.UUID) (nodeMetricLabels, error) {
|
|
var a *activities.Activities
|
|
|
|
var nodePool db.NodePool
|
|
if err := workflow.ExecuteActivity(withDBOptions(ctx), a.GetNodePoolForNode, nodeID).Get(ctx, &nodePool); err != nil {
|
|
return nodeMetricLabels{}, fmt.Errorf("failed to get node pool: %w", err)
|
|
}
|
|
|
|
var cluster db.Cluster
|
|
if err := workflow.ExecuteActivity(withDBOptions(ctx), a.GetClusterForNode, nodeID).Get(ctx, &cluster); err != nil {
|
|
return nodeMetricLabels{}, fmt.Errorf("failed to get cluster: %w", err)
|
|
}
|
|
|
|
nodeType := "worker"
|
|
if nodePool.ControlPlane {
|
|
nodeType = "cp"
|
|
}
|
|
|
|
return nodeMetricLabels{ClusterName: cluster.Name, NodeType: nodeType}, nil
|
|
}
|