Skip to content

Commit 114eda2

Browse files
authored
fix: apply a dummy default controller config (#215)
to make garm work after the initialization, we apply a default config for webhookURL, metadataURL and callbackURL this config will be overwritten once a garmserverconfig CR got applied during the initial start of garm with the operator, the `controller info` will look like: ```bash +-------------------------+-------------------------------------------------------------------------+ | FIELD | VALUE | +-------------------------+-------------------------------------------------------------------------+ | Controller ID | dd2524b9-0789-499d-ba7d-3dba65cf9d3f | | Hostname | garm-server-7c9d8f57b6-54zt2 | | Metadata URL | https://initial.metadata.garm.cloud | | Callback URL | https://initial.callback.garm.cloud | | Webhook Base URL | https://initial.webhook.garm.cloud | | Controller Webhook URL | https://initial.webhook.garm.cloud/dd2524b9-0789-499d-ba7d-3dba65cf9d3f | | Minimum Job Age Backoff | 30 | | Version | v0.1.5 | +-------------------------+-------------------------------------------------------------------------+ ``` after a corresponding `garmserverconfig` CR gets applied, the `controller info` will look like: ```bash garm-cli-v0.1.5 controller show +-------------------------+---------------------------------------------------------------------------------------------+ | FIELD | VALUE | +-------------------------+---------------------------------------------------------------------------------------------+ | Controller ID | dd2524b9-0789-499d-ba7d-3dba65cf9d3f | | Hostname | garm-server-7c9d8f57b6-54zt2 | | Metadata URL | http://garm-server.garm-server.svc:9997/api/v1/metadata | | Callback URL | http://garm-server.garm-server.svc:9997/api/v1/callbacks | | Webhook Base URL | http://garm-server.garm-server.svc:9997/api/v1/webhook | | Controller Webhook URL | http://garm-server.garm-server.svc:9997/api/v1/webhook/dd2524b9-0789-499d-ba7d-3dba65cf9d3f | | Minimum Job Age Backoff | 30 | | Version | v0.1.5 | +-------------------------+---------------------------------------------------------------------------------------------+ ``` Signed-off-by: Mario Constanti <mario.constanti@mercedes-benz.com>
1 parent f0044a2 commit 114eda2

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

pkg/client/client.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
"errors"
88
"fmt"
9+
"net/http"
910
"net/url"
1011
"strings"
1112
"time"
@@ -189,15 +190,23 @@ func IsUnauthenticatedError(err interface{}) bool {
189190
if !ok {
190191
return false
191192
}
192-
return apiErr.IsCode(401)
193+
return apiErr.IsCode(http.StatusUnauthorized)
193194
}
194195

195196
func IsNotFoundError(err interface{}) bool {
196197
apiErr, ok := err.(runtime.ClientResponseStatus)
197198
if !ok {
198199
return false
199200
}
200-
return apiErr.IsCode(404)
201+
return apiErr.IsCode(http.StatusNotFound)
202+
}
203+
204+
func IsConflictError(err interface{}) bool {
205+
apiErr, ok := err.(runtime.ClientResponseStatus)
206+
if !ok {
207+
return false
208+
}
209+
return apiErr.IsCode(http.StatusConflict)
201210
}
202211

203212
type Func[T interface{}] func() (T, error)

pkg/client/controller.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ package client
33

44
import (
55
"github.com/cloudbase/garm/client/controller"
6+
garmcontroller "github.com/cloudbase/garm/client/controller"
67
"github.com/cloudbase/garm/client/controller_info"
8+
"github.com/cloudbase/garm/params"
79

810
"github.com/mercedes-benz/garm-operator/pkg/metrics"
11+
"github.com/mercedes-benz/garm-operator/pkg/util"
912
)
1013

1114
type ControllerClient interface {
@@ -23,12 +26,33 @@ func NewControllerClient() ControllerClient {
2326
}
2427
}
2528

29+
const (
30+
initialMetadataURL = "https://initial.metadata.garm.local"
31+
initialCallbackURL = "https://initial.callback.garm.local"
32+
initialWebhookURL = "https://initial.webhook.garm.local"
33+
)
34+
2635
func (s *controllerClient) GetControllerInfo() (*controller_info.ControllerInfoOK, error) {
2736
return EnsureAuth(func() (*controller_info.ControllerInfoOK, error) {
2837
metrics.TotalGarmCalls.WithLabelValues("controller.Info").Inc()
2938
controllerInfo, err := s.GarmAPI().ControllerInfo.ControllerInfo(&controller_info.ControllerInfoParams{}, s.Token())
3039
if err != nil {
3140
metrics.GarmCallErrors.WithLabelValues("controller.Info").Inc()
41+
42+
// after the first run, garm needs a configuration for webhook, metadata and callback
43+
// to make garm work after the first run, we set some defaults
44+
if IsConflictError(err) {
45+
updateParams := garmcontroller.NewUpdateControllerParams().WithBody(params.UpdateControllerParams{
46+
MetadataURL: util.StringPtr(initialMetadataURL),
47+
CallbackURL: util.StringPtr(initialCallbackURL),
48+
WebhookURL: util.StringPtr(initialWebhookURL),
49+
})
50+
// let's initiate the new controller with some defaults
51+
_, err := s.UpdateController(updateParams)
52+
if err != nil {
53+
return nil, err
54+
}
55+
}
3256
return nil, err
3357
}
3458
return controllerInfo, nil

0 commit comments

Comments
 (0)