Skip to content

Commit

Permalink
rename secretMetadata to secretsMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
linglingye001 committed Jul 19, 2024
1 parent 030d112 commit 4d0ffb2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 44 deletions.
20 changes: 10 additions & 10 deletions internal/controller/appconfigurationprovider_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ var _ = Describe("AppConfiguationProvider controller", func() {
},
SecretReferences: map[string]*loader.TargetSecretReference{
secretName: {
Type: corev1.SecretTypeTLS,
SecretMetadata: make(map[string]loader.KeyVaultSecretMetadata),
Type: corev1.SecretTypeTLS,
SecretsMetadata: make(map[string]loader.KeyVaultSecretMetadata),
},
secretName2: {
Type: corev1.SecretTypeOpaque,
SecretMetadata: make(map[string]loader.KeyVaultSecretMetadata),
Type: corev1.SecretTypeOpaque,
SecretsMetadata: make(map[string]loader.KeyVaultSecretMetadata),
},
},
}
Expand Down Expand Up @@ -266,8 +266,8 @@ var _ = Describe("AppConfiguationProvider controller", func() {
ConfigMapSettings: configMapResult,
SecretReferences: map[string]*loader.TargetSecretReference{
secretName: {
Type: corev1.SecretType("Opaque"),
SecretMetadata: make(map[string]loader.KeyVaultSecretMetadata),
Type: corev1.SecretType("Opaque"),
SecretsMetadata: make(map[string]loader.KeyVaultSecretMetadata),
},
},
}
Expand Down Expand Up @@ -637,8 +637,8 @@ var _ = Describe("AppConfiguationProvider controller", func() {
ConfigMapSettings: configMapResult,
SecretReferences: map[string]*loader.TargetSecretReference{
secretName: {
Type: corev1.SecretType("Opaque"),
SecretMetadata: secretMetadata,
Type: corev1.SecretType("Opaque"),
SecretsMetadata: secretMetadata,
},
},
}
Expand Down Expand Up @@ -721,8 +721,8 @@ var _ = Describe("AppConfiguationProvider controller", func() {
}
mockedSecretReference := make(map[string]*loader.TargetSecretReference)
mockedSecretReference[secretName] = &loader.TargetSecretReference{
Type: corev1.SecretType("Opaque"),
SecretMetadata: newSecretMetadata,
Type: corev1.SecretType("Opaque"),
SecretsMetadata: newSecretMetadata,
}

newTargetSettings := &loader.TargetKeyValueSettings{
Expand Down
16 changes: 8 additions & 8 deletions internal/controller/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,24 +201,24 @@ func (processor *AppConfigurationProviderProcessor) processSecretReferenceRefres
secretReferencesToSolve := make(map[string]*loader.TargetSecretReference)
copiedSecretReferences := make(map[string]*loader.TargetSecretReference)
for secretName, reference := range reconcileState.ExistingSecretReferences {
for key, uriSegment := range reference.SecretMetadata {
for key, uriSegment := range reference.SecretsMetadata {
if uriSegment.SecretVersion == "" {
if secretReferencesToSolve[secretName] == nil {
secretReferencesToSolve[secretName] = &loader.TargetSecretReference{
Type: reference.Type,
SecretMetadata: make(map[string]loader.KeyVaultSecretMetadata),
Type: reference.Type,
SecretsMetadata: make(map[string]loader.KeyVaultSecretMetadata),
}
}
secretReferencesToSolve[secretName].SecretMetadata[key] = uriSegment
secretReferencesToSolve[secretName].SecretsMetadata[key] = uriSegment
}

if copiedSecretReferences[secretName] == nil {
copiedSecretReferences[secretName] = &loader.TargetSecretReference{
Type: reference.Type,
SecretMetadata: make(map[string]loader.KeyVaultSecretMetadata),
Type: reference.Type,
SecretsMetadata: make(map[string]loader.KeyVaultSecretMetadata),
}
}
copiedSecretReferences[secretName].SecretMetadata[key] = uriSegment
copiedSecretReferences[secretName].SecretsMetadata[key] = uriSegment
}
}

Expand All @@ -235,7 +235,7 @@ func (processor *AppConfigurationProviderProcessor) processSecretReferenceRefres
}

for secretName, reference := range resolvedSecrets.SecretReferences {
maps.Copy(copiedSecretReferences[secretName].SecretMetadata, reference.SecretMetadata)
maps.Copy(copiedSecretReferences[secretName].SecretsMetadata, reference.SecretsMetadata)
}

processor.Settings.SecretSettings = existingSecrets
Expand Down
10 changes: 5 additions & 5 deletions internal/controller/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,16 @@ func shouldCreateOrUpdate(processor *AppConfigurationProviderProcessor, secretNa
}

secretReference := processor.Settings.SecretReferences[secretName]
if len(existingSecretReferences[secretName].SecretMetadata) != len(secretReference.SecretMetadata) {
if len(existingSecretReferences[secretName].SecretsMetadata) != len(secretReference.SecretsMetadata) {
return true
}

for key, secretMetadata := range secretReference.SecretMetadata {
if _, ok := existingSecretReferences[secretName].SecretMetadata[key]; !ok {
for key, secretMetadata := range secretReference.SecretsMetadata {
if _, ok := existingSecretReferences[secretName].SecretsMetadata[key]; !ok {
return true
}
if existingSecretReferences[secretName].SecretMetadata[key].SecretId != nil && secretMetadata.SecretId != nil &&
*(existingSecretReferences[secretName].SecretMetadata[key].SecretId) != *(secretMetadata.SecretId) {
if existingSecretReferences[secretName].SecretsMetadata[key].SecretId != nil && secretMetadata.SecretId != nil &&
*(existingSecretReferences[secretName].SecretsMetadata[key].SecretId) != *(secretMetadata.SecretId) {
return true
}
}
Expand Down
16 changes: 8 additions & 8 deletions internal/loader/configuraiton_setting_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ var _ = Describe("AppConfiguationProvider Get All Settings", func() {
secretReferencesToResolve := map[string]*TargetSecretReference{
secretName: {
Type: corev1.SecretTypeTLS,
SecretMetadata: map[string]KeyVaultSecretMetadata{
SecretsMetadata: map[string]KeyVaultSecretMetadata{
secretName: {
HostName: "fake-vault",
SecretName: "fake-secret",
Expand Down Expand Up @@ -459,7 +459,7 @@ var _ = Describe("AppConfiguationProvider Get All Settings", func() {
secretReferencesToResolve := map[string]*TargetSecretReference{
secretName: {
Type: corev1.SecretTypeTLS,
SecretMetadata: map[string]KeyVaultSecretMetadata{
SecretsMetadata: map[string]KeyVaultSecretMetadata{
secretName: {
HostName: "fake-vault",
SecretName: "fake-secret",
Expand Down Expand Up @@ -515,7 +515,7 @@ var _ = Describe("AppConfiguationProvider Get All Settings", func() {
secretReferencesToResolve := map[string]*TargetSecretReference{
secretName: {
Type: corev1.SecretTypeTLS,
SecretMetadata: map[string]KeyVaultSecretMetadata{
SecretsMetadata: map[string]KeyVaultSecretMetadata{
secretName: {
HostName: "fake-vault",
SecretName: "fake-secret",
Expand Down Expand Up @@ -571,7 +571,7 @@ var _ = Describe("AppConfiguationProvider Get All Settings", func() {
secretReferencesToResolve := map[string]*TargetSecretReference{
secretName: {
Type: corev1.SecretTypeTLS,
SecretMetadata: map[string]KeyVaultSecretMetadata{
SecretsMetadata: map[string]KeyVaultSecretMetadata{
secretName: {
HostName: "fake-vault",
SecretName: "fake-secret",
Expand Down Expand Up @@ -627,7 +627,7 @@ var _ = Describe("AppConfiguationProvider Get All Settings", func() {
secretReferencesToResolve := map[string]*TargetSecretReference{
secretName: {
Type: corev1.SecretTypeTLS,
SecretMetadata: map[string]KeyVaultSecretMetadata{
SecretsMetadata: map[string]KeyVaultSecretMetadata{
secretName: {
HostName: "fake-vault",
SecretName: "fake-secret",
Expand Down Expand Up @@ -686,7 +686,7 @@ var _ = Describe("AppConfiguationProvider Get All Settings", func() {
secretReferencesToResolve := map[string]*TargetSecretReference{
secretName: {
Type: corev1.SecretTypeTLS,
SecretMetadata: map[string]KeyVaultSecretMetadata{
SecretsMetadata: map[string]KeyVaultSecretMetadata{
secretName: {
HostName: "fake-vault",
SecretName: "fake-secret",
Expand Down Expand Up @@ -743,7 +743,7 @@ var _ = Describe("AppConfiguationProvider Get All Settings", func() {
secretReferencesToResolve := map[string]*TargetSecretReference{
secretName: {
Type: corev1.SecretTypeTLS,
SecretMetadata: map[string]KeyVaultSecretMetadata{
SecretsMetadata: map[string]KeyVaultSecretMetadata{
secretName: {
HostName: "fake-vault",
SecretName: "fake-secret",
Expand Down Expand Up @@ -800,7 +800,7 @@ var _ = Describe("AppConfiguationProvider Get All Settings", func() {
secretReferencesToResolve := map[string]*TargetSecretReference{
secretName: {
Type: corev1.SecretTypeTLS,
SecretMetadata: map[string]KeyVaultSecretMetadata{
SecretsMetadata: map[string]KeyVaultSecretMetadata{
secretName: {
HostName: "fake-vault",
SecretName: "fake-secret",
Expand Down
26 changes: 13 additions & 13 deletions internal/loader/configuration_setting_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type TargetKeyValueSettings struct {

type TargetSecretReference struct {
Type corev1.SecretType
SecretMetadata map[string]KeyVaultSecretMetadata
SecretsMetadata map[string]KeyVaultSecretMetadata
SecretResourceVersion string
}

Expand Down Expand Up @@ -196,8 +196,8 @@ func (csl *ConfigurationSettingLoader) CreateKeyValueSettings(ctx context.Contex

if csl.Spec.Secret != nil {
rawSettings.SecretReferences[csl.Spec.Secret.Target.SecretName] = &TargetSecretReference{
Type: corev1.SecretTypeOpaque,
SecretMetadata: make(map[string]KeyVaultSecretMetadata),
Type: corev1.SecretTypeOpaque,
SecretsMetadata: make(map[string]KeyVaultSecretMetadata),
}
}

Expand Down Expand Up @@ -258,11 +258,11 @@ func (csl *ConfigurationSettingLoader) CreateKeyValueSettings(ctx context.Contex

if _, ok := rawSettings.SecretReferences[secretName]; !ok {
rawSettings.SecretReferences[secretName] = &TargetSecretReference{
Type: secretType,
SecretMetadata: make(map[string]KeyVaultSecretMetadata),
Type: secretType,
SecretsMetadata: make(map[string]KeyVaultSecretMetadata),
}
}
rawSettings.SecretReferences[secretName].SecretMetadata[trimmedKey] = *secretMetadata
rawSettings.SecretReferences[secretName].SecretsMetadata[trimmedKey] = *secretMetadata
default:
rawSettings.KeyValueSettings[trimmedKey] = setting.Value
rawSettings.IsJsonContentTypeMap[trimmedKey] = isJsonContentType(setting.ContentType)
Expand Down Expand Up @@ -375,9 +375,9 @@ func (csl *ConfigurationSettingLoader) ResolveSecretReferences(

var eg errgroup.Group
if targetSecretReference.Type == corev1.SecretTypeOpaque {
if len(targetSecretReference.SecretMetadata) > 0 {
if len(targetSecretReference.SecretsMetadata) > 0 {
lock := &sync.Mutex{}
for key, kvReference := range targetSecretReference.SecretMetadata {
for key, kvReference := range targetSecretReference.SecretsMetadata {
currentKey := key
currentReference := kvReference
eg.Go(func() error {
Expand All @@ -388,9 +388,9 @@ func (csl *ConfigurationSettingLoader) ResolveSecretReferences(
lock.Lock()
defer lock.Unlock()
resolvedSecrets[name].Data[currentKey] = []byte(*resolvedSecret.Value)
currentUriSegment := targetSecretReference.SecretMetadata[currentKey]
currentUriSegment := targetSecretReference.SecretsMetadata[currentKey]
currentUriSegment.SecretId = resolvedSecret.ID
secretReferencesToResolve[name].SecretMetadata[currentKey] = currentUriSegment
secretReferencesToResolve[name].SecretsMetadata[currentKey] = currentUriSegment
return nil
})
}
Expand All @@ -401,10 +401,10 @@ func (csl *ConfigurationSettingLoader) ResolveSecretReferences(
}
} else if targetSecretReference.Type == corev1.SecretTypeTLS {
eg.Go(func() error {
resolvedSecret, err := resolver.Resolve(targetSecretReference.SecretMetadata[name], ctx)
currentUriSegment := targetSecretReference.SecretMetadata[name]
resolvedSecret, err := resolver.Resolve(targetSecretReference.SecretsMetadata[name], ctx)
currentUriSegment := targetSecretReference.SecretsMetadata[name]
currentUriSegment.SecretId = resolvedSecret.ID
secretReferencesToResolve[name].SecretMetadata[name] = currentUriSegment
secretReferencesToResolve[name].SecretsMetadata[name] = currentUriSegment
if err != nil {
return fmt.Errorf("fail to resolve the Key Vault reference type setting '%s': %s", name, err.Error())
}
Expand Down

0 comments on commit 4d0ffb2

Please sign in to comment.