Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix: move fixes from different branch
Daniel Hougaarde76d2f58eaea
diff --git a/k8-operator/controllers/infisicalpushsecret/infisicalpushsecret_helper.go b/k8-operator/controllers/infisicalpushsecret/infisicalpushsecret_helper.goindex ebe125a491..9ba514dbcc 100644--- a/k8-operator/controllers/infisicalpushsecret/infisicalpushsecret_helper.go+++ b/k8-operator/controllers/infisicalpushsecret/infisicalpushsecret_helper.go@@ -148,15 +148,6 @@ func (r *InfisicalPushSecretReconciler) ReconcileInfisicalPushSecret(ctx contextIncludeImports: false,})- existingSecretsContainsKey := func(key string) bool {- for _, secret := range existingSecrets {- if secret.SecretKey == key {- return true- }- }- return false- }-getExistingSecretByKey := func(key string) *infisicalSdk.Secret {for _, secret := range existingSecrets {if secret.SecretKey == key {@@ -175,6 +166,15 @@ func (r *InfisicalPushSecretReconciler) ReconcileInfisicalPushSecret(ctx contextreturn nil}+ updateExistingSecretByKey := func(key string, newSecretValue string) {+ for i := range existingSecrets {+ if existingSecrets[i].SecretKey == key {+ existingSecrets[i].SecretValue = newSecretValue+ break+ }+ }+ }+if err != nil {return fmt.Errorf("unable to list secrets [err=%s]", err)}@@ -192,7 +192,8 @@ func (r *InfisicalPushSecretReconciler) ReconcileInfisicalPushSecret(ctx contextinfisicalPushSecret.Status.ManagedSecrets = make(map[string]string) // (string[id], string[key] )for secretKey, secretValue := range kubeSecrets {- if existingSecretsContainsKey(secretKey) {+ if exists := getExistingSecretByKey(secretKey); exists != nil {+if updatePolicy == string(constants.PUSH_SECRET_REPLACE_POLICY_ENABLED) {updatedSecret, err := infisicalClient.Secrets().Update(infisicalSdk.UpdateSecretOptions{SecretKey: secretKey,@@ -306,7 +307,7 @@ func (r *InfisicalPushSecretReconciler) ReconcileInfisicalPushSecret(ctx context// We need to check if any new secrets have been added in the kube secretfor currentSecretKey := range kubeSecrets {- if !existingSecretsContainsKey(currentSecretKey) {+ if exists := getExistingSecretByKey(currentSecretKey); exists == nil {// Some secrets has been added, verify that the secret that has been added is not already managed by the operatorif _, ok := infisicalPushSecret.Status.ManagedSecrets[currentSecretKey]; !ok {@@ -332,21 +333,29 @@ func (r *InfisicalPushSecretReconciler) ReconcileInfisicalPushSecret(ctx context}} else {if updatePolicy == string(constants.PUSH_SECRET_REPLACE_POLICY_ENABLED) {- updatedSecret, err := infisicalClient.Secrets().Update(infisicalSdk.UpdateSecretOptions{- SecretKey: currentSecretKey,- NewSecretValue: kubeSecrets[currentSecretKey],- ProjectID: destination.ProjectID,- Environment: destination.EnvironmentSlug,- SecretPath: destination.SecretsPath,- })- if err != nil {- secretsFailedToUpdate = append(secretsFailedToUpdate, currentSecretKey)- logger.Info(fmt.Sprintf("unable to update secret [key=%s] [err=%s]", currentSecretKey, err))- continue- }+ existingSecret := getExistingSecretByKey(currentSecretKey)++ if existingSecret != nil && existingSecret.SecretValue != kubeSecrets[currentSecretKey] {+ logger.Info(fmt.Sprintf("Secret with key [key=%s] has changed value. Updating secret in Infisical", currentSecretKey))- infisicalPushSecret.Status.ManagedSecrets[updatedSecret.ID] = currentSecretKey+ updatedSecret, err := infisicalClient.Secrets().Update(infisicalSdk.UpdateSecretOptions{+ SecretKey: currentSecretKey,+ NewSecretValue: kubeSecrets[currentSecretKey],+ ProjectID: destination.ProjectID,+ Environment: destination.EnvironmentSlug,+ SecretPath: destination.SecretsPath,+ })++ if err != nil {+ secretsFailedToUpdate = append(secretsFailedToUpdate, currentSecretKey)+ logger.Info(fmt.Sprintf("unable to update secret [key=%s] [err=%s]", currentSecretKey, err))+ continue+ }++ updateExistingSecretByKey(currentSecretKey, kubeSecrets[currentSecretKey])+ infisicalPushSecret.Status.ManagedSecrets[updatedSecret.ID] = currentSecretKey+ }}}}