Skip to content

Commit

Permalink
Add ability to select single node by prefix (#22)
Browse files Browse the repository at this point in the history
- Update controller to be able to schedule a test to a single worker node via a nodename prefix.
  • Loading branch information
kshave authored Aug 15, 2024
1 parent 572559e commit fb58e54
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions chart/synthetic-heart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions controller/internal/controller/synthetictest_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fb58e54

Please sign in to comment.