Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/controller-info only works when a server-configuration is applied #310

Open
bavarianbidi opened this issue Nov 20, 2024 · 0 comments
Open

Comments

@bavarianbidi
Copy link
Contributor

In the garm-operator we want to check the version of the connected garm-server.
We are doing this by getting the server version via the /controller-info endpoint.

Unfortunately it's some kind of a chicken-egg problem. We need the version before we start our controller-loops.
To work around this, we've implemented the following patch which applies a "default" configuration just to make the /controller-info endpoint work - mercedes-benz/garm-operator#215

I'm not 100% sure about the intention, but could we probably relax some of the decisions here:

func NewUrlsRequiredMiddleware(store common.Store) (Middleware, error) {
return &urlsRequired{
store: store,
}, nil
}
type urlsRequired struct {
store common.Store
}
func (u *urlsRequired) Middleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctrlInfo, err := u.store.ControllerInfo()
if err != nil || ctrlInfo.WebhookURL == "" || ctrlInfo.MetadataURL == "" || ctrlInfo.CallbackURL == "" {
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusConflict)
if err := json.NewEncoder(w).Encode(params.URLsRequired); err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to encode response")
}
return
}
next.ServeHTTP(w, r.WithContext(ctx))
})
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant