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

Reduce context content #151

Open
fran2810 opened this issue Oct 7, 2024 · 0 comments
Open

Reduce context content #151

fran2810 opened this issue Oct 7, 2024 · 0 comments

Comments

@fran2810
Copy link
Contributor

fran2810 commented Oct 7, 2024

We save a lot of redundant objects in our context which make it heavy, for example

// Update the logger with the username
c.Set(LoggerCtxKey, userLogger)
c.Set(KubeClientCtxKey, kubeClient)
c.Set(DynamicClientCtxKey, dynClient)
c.Set(TokenCtxKey, token)
c.Set(ConfigKey, config)

We dont need to save the dynamic client and the k8s client we can shift the logic of building the clients to the context file and than we will call it only in needed routes. the only things we will need in our context is logger and config which will use to build the specified clients here:

func GetKubeClient(c *gin.Context) (kubernetes.Interface, error) {
kube, exists := c.Get(KubeClientCtxKey)
if !exists {
return nil, c.Error(customerrors.NewNotFoundError("kubernetes client not found in context"))
}
return kube.(kubernetes.Interface), nil
}
// GetDynClient retrieves the dynamic client from the gin.Context.
func GetDynClient(c *gin.Context) (client.Client, error) {
kube, exists := c.Get(DynamicClientCtxKey)
if !exists {
return nil, c.Error(customerrors.NewNotFoundError("dynamic client not found in context"))
}
return kube.(client.Client), nil
}

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