From 9127cb0e8c59a333fb71d3bea8950559ad852475 Mon Sep 17 00:00:00 2001 From: kshave Date: Wed, 7 Aug 2024 15:18:31 +0100 Subject: [PATCH] Add ability to select single node by prefix - Update controller to be able to schedule a test to a single worker node via a nodename prefix. --- README.md | 13 +++++++++++++ chart/synthetic-heart/values.yaml | 18 +++++++++--------- .../controller/synthetictest_controller.go | 12 +++++++----- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 61fef0b..3dc09fc 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,19 @@ spec: retries: 3 ``` +#### Synthetic-test spec functionality + +Node selection: + +- `node: *` + - Run on all nodes +- `node: worker*` + - Run on all nodes with the prefix 'worker' +- `node: $` + - Run on a single (random) node +- `node: worker$` + - Run on a single node with the prefix 'worker' + ### The Agent ![Synthetic Heart Agent Architecture](./docs/agent_architecture.png) diff --git a/chart/synthetic-heart/values.yaml b/chart/synthetic-heart/values.yaml index a7df643..a519ba9 100644 --- a/chart/synthetic-heart/values.yaml +++ b/chart/synthetic-heart/values.yaml @@ -3,9 +3,9 @@ controller: logLevel: INFO image: - repository: bakshi41c/synheart-controller - tag: "v1.2.1" - pullPolicy: Always + repository: localhost/synheart-controller + tag: "dev-latest" + pullPolicy: IfNotPresent ports: - containerPort: 2112 # For prometheus protocol: TCP @@ -28,9 +28,9 @@ agent: printPluginLogs: onFail # Whether to print logs of test runs (always, onFail, never) exportRate: 15s # How often to export health status of plugins/agent image: - repository: bakshi41c/synheart-agent - tag: "v1.2.1-with-py" - pullPolicy: Always + repository: localhost/synheart-agent + tag: "dev-latest" + pullPolicy: IfNotPresent ports: - containerPort: 2112 # For prometheus protocol: TCP @@ -60,9 +60,9 @@ agent: restapi: logLevel: INFO image: - repository: bakshi41c/synheart-restapi - tag: "v1.2.1" - pullPolicy: Always + repository: localhost/synheart-restapi + tag: "dev-latest" + pullPolicy: IfNotPresent annotations: {} ports: - containerPort: 8080 diff --git a/controller/internal/controller/synthetictest_controller.go b/controller/internal/controller/synthetictest_controller.go index b428592..fe027e8 100644 --- a/controller/internal/controller/synthetictest_controller.go +++ b/controller/internal/controller/synthetictest_controller.go @@ -20,6 +20,11 @@ import ( "context" "crypto/md5" "fmt" + "math/rand/v2" + "os" + "strings" + "time" + "github.com/cisco-open/synthetic-heart/common" "github.com/cisco-open/synthetic-heart/common/proto" "github.com/cisco-open/synthetic-heart/common/storage" @@ -33,15 +38,12 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" - "math/rand/v2" - "os" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" - "time" ) // SyntheticTestReconciler reconciles a SyntheticTest object @@ -106,7 +108,7 @@ func (r *SyntheticTestReconciler) Reconcile(ctx context.Context, request ctrl.Re configId := common.ComputeSynTestConfigId(instance.Name, instance.Namespace) // check if the test has the special key for node/pod assignment - needsNodeAssignment := instance.Spec.Node == "$" + needsNodeAssignment := strings.Contains(instance.Spec.Node, "$") needsPodAssignment := false if podNameVal, ok := instance.Spec.PodLabelSelector[common.SpecialKeyPodName]; ok && podNameVal == "$" { needsPodAssignment = true @@ -141,7 +143,7 @@ func (r *SyntheticTestReconciler) Reconcile(ctx context.Context, request ctrl.Re if needsNodeAssignment || needsPodAssignment { logger.Info("assigning agent for syntest", "name", instance.Name, "node", node, "podLabelSelector", podLabelSelector) if needsNodeAssignment { - node = "" // set the node to blank + node = strings.ReplaceAll(node, "$", "*") } if needsPodAssignment { delete(podLabelSelector, common.SpecialKeyPodName) // remove the special key for assignment