Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pkg/controller/external_secrets/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func (r *Reconciler) getDeploymentObject(assetName string, esc *operatorv1alpha1
case bitwardenDeploymentAssetName:

Choose a reason for hiding this comment

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

Initially we are creating a list of various deployments, and feeding it to createOrApplyDeploymentFromAsset.
createOrApplyDeploymentFromAsset is calling the current function, and then we are again having conditional logic based on the specific kind of deployment we are working with.

i feel we can refactor it by supplementing the "deployments" struct:

deployments := []struct {
		assetName string
		condition bool
	}

with more fields so that the code that works on it further need not differentiate on the actual kind.

Attaching an example implementation (it excludes the current PR changes):
restructure.patch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, will create a follow up PR to refactor the code.

deployment.Labels["app.kubernetes.io/version"] = os.Getenv(bitwardenImageVersionEnvVarName)
updateBitwardenServerContainerSpec(deployment, bitwardenImage)
updateBitwardenVolumeConfig(deployment, esc)
}

if err := r.updateResourceRequirement(deployment, esc); err != nil {
Expand Down Expand Up @@ -392,3 +393,25 @@ func updateBitwardenServerContainerSpec(deployment *appsv1.Deployment, image str
}
}
}

func updateBitwardenVolumeConfig(deployment *appsv1.Deployment, esc *operatorv1alpha1.ExternalSecretsConfig) {
const certsVolumeName = "bitwarden-tls-certs"

if esc.Spec.Plugins.BitwardenSecretManagerProvider.SecretRef != nil &&
esc.Spec.Plugins.BitwardenSecretManagerProvider.SecretRef.Name != "" {
if deployment.Spec.Template.Spec.Volumes == nil {
deployment.Spec.Template.Spec.Volumes = append(deployment.Spec.Template.Spec.Volumes, corev1.Volume{
Name: certsVolumeName,
})
}

for i := range deployment.Spec.Template.Spec.Volumes {
if deployment.Spec.Template.Spec.Volumes[i].Name == certsVolumeName {
if deployment.Spec.Template.Spec.Volumes[i].Secret == nil {
deployment.Spec.Template.Spec.Volumes[i].Secret = &corev1.SecretVolumeSource{}
}
deployment.Spec.Template.Spec.Volumes[i].Secret.SecretName = esc.Spec.Plugins.BitwardenSecretManagerProvider.SecretRef.Name
}
}
}
}
Loading