Skip to content

Commit 79a84da

Browse files
feat: add tart status get probe
Signed-off-by: dzmitryharchanin-tomtom <dzmitry.harchanin@tomtom.com>
1 parent 88752c5 commit 79a84da

File tree

6 files changed

+85
-6
lines changed

6 files changed

+85
-6
lines changed

pkg/clients/tart/client.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"bytes"
2121
"encoding/base64"
2222
"fmt"
23+
"net"
2324
"os"
2425
"os/exec"
2526
"path"
@@ -75,6 +76,22 @@ func (c *Client) GetTartVersion() (string, error) {
7576
return version, nil
7677
}
7778

79+
func (c *Client) GetTartVMIP(tartVMName string) (string, error) {
80+
if !isValidExecutablePath(c.tartPath) {
81+
return "", fmt.Errorf("invalid tart path: %s", c.tartPath)
82+
}
83+
// #nosec G204 - tartPath is a trusted configuration value, not user input
84+
out, err := exec.Command(c.tartPath, "ip", tartVMName).CombinedOutput()
85+
if err != nil {
86+
return "", err
87+
}
88+
ip := net.ParseIP(strings.TrimRight(string(out), "\r\n"))
89+
if ip == nil {
90+
return "", fmt.Errorf("failed to get tart VM IP")
91+
}
92+
return ip.String(), nil
93+
}
94+
7895
func (c *Client) BuildCMDArguments(tartVMName string, config types.RunnerConfig) []string {
7996
var args []string
8097

pkg/prober/probe/tart/tart.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2025 TomTom N.V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package tart
18+
19+
import (
20+
"fmt"
21+
22+
"github.com/tomtom-international/macos-actions-runner-controller/pkg/clients/tart"
23+
"github.com/tomtom-international/macos-actions-runner-controller/pkg/prober/probe"
24+
)
25+
26+
type tartProber struct {
27+
client *tart.Client
28+
}
29+
30+
type Prober interface {
31+
Probe(tartVMName string) (probe.Result, string, error)
32+
}
33+
34+
func New(tartClient *tart.Client) Prober {
35+
return tartProber{
36+
client: tartClient,
37+
}
38+
}
39+
40+
func (t tartProber) Probe(tartVMName string) (probe.Result, string, error) {
41+
_, err := t.client.GetTartVMIP(tartVMName)
42+
if err != nil {
43+
return probe.Failure, fmt.Sprintf("Failed to get tart VM %s IP", tartVMName), err
44+
}
45+
46+
return probe.Success, "tart probe success", nil
47+
}

pkg/prober/probe_manager.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"sync"
2222

2323
ghclient "github.com/tomtom-international/macos-actions-runner-controller/pkg/clients/github"
24+
tartclient "github.com/tomtom-international/macos-actions-runner-controller/pkg/clients/tart"
2425
"github.com/tomtom-international/macos-actions-runner-controller/pkg/logger"
2526
"github.com/tomtom-international/macos-actions-runner-controller/pkg/prober/results"
2627
pt "github.com/tomtom-international/macos-actions-runner-controller/pkg/prober/types"
@@ -39,11 +40,12 @@ type ProberManager struct {
3940

4041
func NewManager(
4142
githubClient *ghclient.Client,
43+
tartClient *tartclient.Client,
4244
stateManager *state.StateManager,
4345
livenessManager results.Manager,
4446
startupManager results.Manager) *ProberManager {
4547

46-
prober := newProber(githubClient)
48+
prober := newProber(githubClient, tartClient)
4749
return &ProberManager{
4850
stateManager: stateManager,
4951
prober: prober,

pkg/prober/prober.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2025 TomTom N.V.
3-
* Copyright 2015 The Kubernetes Authors.
3+
* Copyright 2014 The Kubernetes Authors.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -22,10 +22,12 @@ import (
2222
"time"
2323

2424
ghclient "github.com/tomtom-international/macos-actions-runner-controller/pkg/clients/github"
25+
tartclient "github.com/tomtom-international/macos-actions-runner-controller/pkg/clients/tart"
2526
"github.com/tomtom-international/macos-actions-runner-controller/pkg/logger"
2627
"github.com/tomtom-international/macos-actions-runner-controller/pkg/prober/probe"
2728
githubprobe "github.com/tomtom-international/macos-actions-runner-controller/pkg/prober/probe/github"
2829
httpprobe "github.com/tomtom-international/macos-actions-runner-controller/pkg/prober/probe/http"
30+
tartprobe "github.com/tomtom-international/macos-actions-runner-controller/pkg/prober/probe/tart"
2931
pt "github.com/tomtom-international/macos-actions-runner-controller/pkg/prober/types"
3032
)
3133

@@ -34,12 +36,14 @@ const maxProbeRetries = 3
3436
type prober struct {
3537
github githubprobe.Prober
3638
http httpprobe.Prober
39+
tart tartprobe.Prober
3740
}
3841

39-
func newProber(githubClient *ghclient.Client) *prober {
42+
func newProber(githubClient *ghclient.Client, tartClient *tartclient.Client) *prober {
4043
return &prober{
4144
github: githubprobe.New(githubClient),
4245
http: httpprobe.New(),
46+
tart: tartprobe.New(tartClient),
4347
}
4448
}
4549

@@ -90,10 +94,12 @@ func (pb *prober) runProbeWithRetries(spec *pt.Probe, target *pt.ProbeTarget, re
9094
func (pb *prober) runProbe(spec *pt.Probe, target *pt.ProbeTarget) (probe.Result, string, error) {
9195
timeout := time.Duration(spec.TimeoutSeconds) * time.Second
9296
switch {
97+
case spec.TartVMStatusGet != nil:
98+
logger.Debugf("Run TartVMStatusGet probe for traget: %s with ID: %s", target.Name, target.ID)
99+
return pb.tart.Probe(target.TartVMName)
93100
case spec.HTTPGet != nil:
94-
logger.Infof("HTTPGet probe for traget: %v with ID: %v", target.Name, target.ID)
101+
logger.Debugf("Run HTTPGet probe for traget: %s with ID: %s", target.Name, target.ID)
95102
return pb.http.Probe(timeout)
96-
97103
case spec.GitHubRunnerGet != nil:
98104
return pb.github.Probe(target.Name)
99105
default:

pkg/prober/types/types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ type ProbeHandler struct {
3939
HTTPGet *HTTPGetAction `json:"httpGet,omitempty" yaml:"httpGet,omitempty"`
4040

4141
GitHubRunnerGet *GitHubRunnerGetAction `json:"githubRunnerGet,omitempty" yaml:"githubRunnerGet,omitempty"`
42+
43+
TartVMStatusGet *TartVMStatusGetAction `json:"tartVMStatusGet,omitempty" yaml:"tartVMStatusGet,omitempty"`
4244
}
4345

4446
// URIScheme identifies the scheme used for connection to a host for Get actions
@@ -88,10 +90,14 @@ type GitHubRunnerGetAction struct {
8890
RunnerName string `json:"runnerName,omitempty" yaml:"runnerName,omitempty"`
8991
}
9092

93+
type TartVMStatusGetAction struct {
94+
}
95+
9196
type ProbeTarget struct {
9297
StartupProbe *Probe `json:"startupProbe,omitempty"`
9398
LivenessProbe *Probe `json:"livenessProbe,omitempty"`
9499
ID utils.UID `json:"id"`
100+
TartVMName string `json:"tartVMName"`
95101
Name string `json:"name"`
96102
Type ProbeTargetType `json:"type"`
97103
}

pkg/tarter/tarter.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func NewTarter(tarterConfig *config.TarterConfig,
103103
versionInfo: versionInfo,
104104
githubClient: githubClient,
105105
tartClient: tartClient,
106-
proberManager: prober.NewManager(githubClient, stateMachine, livenessManager, startupManager),
106+
proberManager: prober.NewManager(githubClient, tartClient, stateMachine, livenessManager, startupManager),
107107
StateManager: stateMachine,
108108
runnerManager: runner.NewRunnerManager(tartClient, githubClient, stateMachine, maxActiveRunners, nodeName),
109109
eventBus: eventBus,
@@ -174,6 +174,7 @@ func (t *Tarter) addProber(runner *tt.Runner) {
174174
logger.Infof("Adding probe for runner %v ...", runner.ID)
175175
probeTarget := &pt.ProbeTarget{
176176
ID: runner.ID,
177+
TartVMName: fmt.Sprintf("%s-%s", runner.Config.Name, string(runner.ID)),
177178
Name: runner.GhaRunnerName, // GhaRunnerName used by GitHub prober
178179
Type: pt.ProbeTargetTypeTartRunner,
179180
StartupProbe: runner.Config.StartupProbe,

0 commit comments

Comments
 (0)