diff --git a/k8-operator/controllers/infisicalsecret_helper.go b/k8-operator/controllers/infisicalsecret_helper.go index 37d13592a..6141a75e7 100644 --- a/k8-operator/controllers/infisicalsecret_helper.go +++ b/k8-operator/controllers/infisicalsecret_helper.go @@ -40,6 +40,8 @@ var AuthStrategy = struct { UNIVERSAL_MACHINE_IDENTITY: "UNIVERSAL_MACHINE_IDENTITY", } +var machineIdentityTokenInstance *util.MachineIdentityToken + func (r *InfisicalSecretReconciler) GetInfisicalConfigMap(ctx context.Context) (configMap map[string]string, errToReturn error) { // default key values defaultConfigMapData := make(map[string]string) @@ -291,16 +293,11 @@ func (r *InfisicalSecretReconciler) ReconcileInfisicalSecret(ctx context.Context secretVersionBasedOnETag = managedKubeSecret.Annotations[SECRET_VERSION_ANNOTATION] } - if authStrategy == AuthStrategy.UNIVERSAL_MACHINE_IDENTITY && util.MachineIdentityTokenInstance == nil { + if authStrategy == AuthStrategy.UNIVERSAL_MACHINE_IDENTITY && machineIdentityTokenInstance == nil { // Create new machine identity token instance - util.MachineIdentityTokenInstance = util.NewMachineIdentityToken(infisicalMachineIdentityCreds.ClientId, infisicalMachineIdentityCreds.ClientSecret) + machineIdentityTokenInstance = util.NewMachineIdentityToken(infisicalMachineIdentityCreds.ClientId, infisicalMachineIdentityCreds.ClientSecret) } - // TODO: Also save a timestamp of when the token expires, so we know when to refetch an access token - - // if infisicalMachineIdentityCreds.ClientId != "" && infisicalMachineIdentityCreds.ClientSecret != "" { - // } - var plainTextSecretsFromApi []model.SingleEnvironmentVariable var updateAttributes model.UpdateAttributes @@ -324,7 +321,7 @@ func (r *InfisicalSecretReconciler) ReconcileInfisicalSecret(ctx context.Context fmt.Println("ReconcileInfisicalSecret: Fetched secrets via service token") } else if authStrategy == AuthStrategy.UNIVERSAL_MACHINE_IDENTITY { // Machine Identity - accessToken, err := util.MachineIdentityTokenInstance.GetToken() + accessToken, err := machineIdentityTokenInstance.GetToken() if err != nil { return fmt.Errorf("%s", "Waiting for access token to become available") diff --git a/k8-operator/packages/util/variables.go b/k8-operator/packages/util/variables.go deleted file mode 100644 index 1c75569bf..000000000 --- a/k8-operator/packages/util/variables.go +++ /dev/null @@ -1,3 +0,0 @@ -package util - -var MachineIdentityTokenInstance *MachineIdentityToken