-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: refactor to single instance garm client with auto init and login #48
Conversation
2e1cc29
to
4009915
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice refactoring, really like it ❤️
just one nit about variable naming
pkg/client/client.go
Outdated
@@ -20,6 +20,8 @@ import ( | |||
"github.com/mercedes-benz/garm-operator/pkg/metrics" | |||
) | |||
|
|||
var Instance BaseClient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm bothered by the term Instance
here ... Instance in the scope of GARM could be a Runner as well.
What do you think about one of the following two options:
Instance
will be renamed toGarmClient
- As
BaseClient
is an extended version ofgarmClient.GarmAPI
,BaseClient
will becomeGarmClient
and with thatInstance
will beBaseClient
(or justClient
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are right, this might be confusing. I´ll probably like the second option better: then its clear that a GarmClient
is the defact Base
which has all necessary methods for Auth and default API methods for all garm resources. And the Instance of it is an instanciated Client
.
104c752
to
e85d92c
Compare
e85d92c
to
5c7ad0d
Compare
5c7ad0d
to
717610e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
just one idea came into my mind (could be a dedicated follow up PR)
expose the expiration-time of the current used token as metric.
Creates the garm-api client once as a single instance, so there are no more unnecesary login api calls on every reconcile. Also the operator initializes garm-server automatically again and attempts a login, once the garm-server dies or the auth token expires.
Essentially in main the client gets created once
main.go
Every garm-client method gets passed as callback to EnsureAuth
enterprise.go
Inside EnsureAuth, the client method gets executed, and checked for a 401 http error, which would result in an intit and login call, before retrying the same client method again. The single instance client is then authenticated again for every caller.
client.go