Skip to content

Commit

Permalink
Apply suggestions regarding secret handling.
Browse files Browse the repository at this point in the history
Co-Authored-By: Amshuman K R <[email protected]>
  • Loading branch information
George Kuruvilla and Amshuman K R authored Mar 6, 2020
1 parent 4aa8959 commit 31b28fd
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions controllers/etcd_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,24 +747,24 @@ func (r *EtcdReconciler) getMapFromEtcd(etcd *druidv1alpha1.Etcd) (map[string]in

func (r *EtcdReconciler) addFinalizersToDependantSecrets(etcd *druidv1alpha1.Etcd) error {

tlsSecrets := []string{}
secrets := []string{}
if etcd.Spec.Etcd.TLS != nil {
// As the secrets inside TLS field are required, we error in case they are not found.
tlsSecrets = append(tlsSecrets,
secrets = append(secrets,
etcd.Spec.Etcd.TLS.ClientTLSSecretRef.Name,
etcd.Spec.Etcd.TLS.ServerTLSSecretRef.Name,
etcd.Spec.Etcd.TLS.TLSCASecretRef.Name,
)
}
if etcd.Spec.Backup.Store != nil && etcd.Spec.Backup.Store.SecretRef != nil {
// As the store secret is required, we error in case it is not found as well.
tlsSecrets = append(tlsSecrets, etcd.Spec.Backup.Store.SecretRef.Name)
secrets = append(secrets, etcd.Spec.Backup.Store.SecretRef.Name)
}

for _, tlsSecret := range tlsSecrets {
for _, secretName := range secrets {
secret := corev1.Secret{}
if err := r.Client.Get(context.TODO(), types.NamespacedName{
Name: tlsSecret,
Name: secretName,
Namespace: etcd.Namespace,
}, &secret); err != nil {
return err
Expand All @@ -785,22 +785,22 @@ func (r *EtcdReconciler) addFinalizersToDependantSecrets(etcd *druidv1alpha1.Etc

func (r *EtcdReconciler) removeFinalizersToDependantSecrets(etcd *druidv1alpha1.Etcd) error {

tlsSecrets := []string{}
secrets := []string{}
if etcd.Spec.Etcd.TLS != nil {
tlsSecrets = append(tlsSecrets,
secrets = append(secrets,
etcd.Spec.Etcd.TLS.ClientTLSSecretRef.Name,
etcd.Spec.Etcd.TLS.ServerTLSSecretRef.Name,
etcd.Spec.Etcd.TLS.TLSCASecretRef.Name,
)
}
if etcd.Spec.Backup.Store != nil && etcd.Spec.Backup.Store.SecretRef != nil {
tlsSecrets = append(tlsSecrets, etcd.Spec.Backup.Store.SecretRef.Name)
secrets = append(secrets, etcd.Spec.Backup.Store.SecretRef.Name)
}

for _, tlsSecret := range tlsSecrets {
for _, secretName := range secrets {
secret := corev1.Secret{}
err := r.Client.Get(context.TODO(), types.NamespacedName{
Name: tlsSecret,
Name: secretName,
Namespace: etcd.Namespace,
}, &secret)
if err != nil && !errors.IsNotFound(err) {
Expand Down

0 comments on commit 31b28fd

Please sign in to comment.