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

Client profiles reconciliation #2243

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

AvihuHenya
Copy link
Contributor

@AvihuHenya AvihuHenya commented Jan 16, 2025

Watch over changes in odigos-pro secret and updates odigos-deployment respectively.
TODOs question about implementation in Reconcile function.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change name to secrets


err := ctrl.NewControllerManagedBy(mgr).
For(&corev1.Secret{}).
Named("odigos-pro").
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider aligning the name with other files in this component


type odigosConfigController struct {
client.Client
Scheme *runtime.Scheme
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

odigosNs := env.GetCurrentNamespace()
clientTokenConfig := &ClientProConfig{}

err := r.Client.Get(ctx, client.ObjectKey{Namespace: odigosNs, Name: k8sconsts.OdigosProSecretName}, proSecret)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move proSecret one line above the get

delete(odigosDeploymentConfig.Data, "expiry")
delete(odigosDeploymentConfig.Data, "profiles")

err := client.Update(ctx, odigosDeploymentConfig)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider using r.Client instead of sending the client as function argument

return ctrl.Result{}, fmt.Errorf("failed to parse JWT token: %w", err)
}
if claims, ok := token.Claims.(jwt.MapClaims); ok {
*clientTokenConfig = ClientProConfig{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*clientTokenConfig = ClientProConfig{
clientTokenConfig := ClientProConfig{

return nil
}

func (r *odigosConfigController) updateOdigosDeploymentConfigMap(clientConfig *ClientProConfig, odigosDeploymentConfig *corev1.ConfigMap) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function handleSecretDeletion is very similar and also calls Update on the cm. consider aligning them so they both Update the resource or both do not update the resource

Audience: claims["aud"].(string),
// TODO: what time format should be used?
Expiry: time.Unix(int64(claims["exp"].(float64)), 0).UTC().Format("02/01/2006 03:04:05 PM"),
Profiles: toStringSlice(claims["profiles"]),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use strings.Split(claims["profiles"], ",") for that

odigosDeploymentConfig.Data["expiry"] = clientConfig.Expiry

if len(clientConfig.Profiles) > 0 {
odigosDeploymentConfig.Data["profiles"] = strings.Join(clientConfig.Profiles, ",")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can simply pass the value from the jwt without spliting and joining it

Scheme *runtime.Scheme
}

type ClientProConfig struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type ClientProConfig struct {
type clientProConfig struct {

@BenElferink BenElferink added the enhancement New feature or request label Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants