Skip to content

Conversation

bharath-b-rh
Copy link
Contributor

PR has following changes

  • Updates bitwarden deployment to use the user configured secret for certificates.
  • Updates tests to validate the deployment object is updated as per user configuration.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Sep 19, 2025
@openshift-ci-robot
Copy link

openshift-ci-robot commented Sep 19, 2025

@bharath-b-rh: This pull request references ESO-155 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the epic to target the "4.21.0" version, but no target version was set.

In response to this:

PR has following changes

  • Updates bitwarden deployment to use the user configured secret for certificates.
  • Updates tests to validate the deployment object is updated as per user configuration.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

Copy link

openshift-ci bot commented Sep 19, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bharath-b-rh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 19, 2025
Copy link

@mytreya-rh mytreya-rh left a comment

Choose a reason for hiding this comment

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

[claude generated] Good improvement for Bitwarden certificate management! The changes properly address user-configured secrets for certificates. However, there are areas for improvement in error handling, validation, and test completeness.

case bitwardenDeploymentAssetName:
deployment.Labels["app.kubernetes.io/version"] = bitwardenImageVersionEnvVarName
updateBitwardenServerContainerSpec(deployment, bitwardenImage)
updateBitwardenVolumeConfig(deployment, externalsecrets)

Choose a reason for hiding this comment

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

[claude generated] Good architectural improvement: Adding the volume config update here ensures Bitwarden deployments get the proper certificate configuration. However, consider adding error handling for cases where the deployment structure is unexpected.

}
for i, volume := range deployment.Spec.Template.Spec.Volumes {
if volume.Name == "bitwarden-tls-certs" {
deployment.Spec.Template.Spec.Volumes[i].Secret.SecretName = secretName
Copy link

@mytreya-rh mytreya-rh Sep 26, 2025

Choose a reason for hiding this comment

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

[claude generated] Security consideration: The code assumes volume.Secret is not nil, but this could cause a nil pointer dereference panic if the volume is configured as a different type (ConfigMap, EmptyDir, etc.). Consider adding a nil check: if volume.Secret != nil before accessing SecretName.

}
return true, nil
})
m.UpdateWithRetryCalls(func(ctx context.Context, obj client.Object, _ ...client.UpdateOption) error {

Choose a reason for hiding this comment

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

[claude generated] Test improvement: Good addition of deployment capture mechanism. This allows proper validation of the reconciler's behavior. Consider adding validation for the case where capturedDeployment is nil.

}
},
},
{

Choose a reason for hiding this comment

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

[claude generated] Excellent test coverage: The new Bitwarden test case thoroughly validates both volume secret name updates and container image updates. This provides good regression protection for the certificate configuration feature.

Copy link

@mytreya-rh mytreya-rh left a comment

Choose a reason for hiding this comment

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

/lgtm

Added few suggestions but not too particular about addressing as part of this PR.

},
}
},
validateDeployment: func(t *testing.T, deployment *appsv1.Deployment) {

Choose a reason for hiding this comment

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

The validation logic is a bit too verbose.
Please consider a declarative approach now or in future.
Like a list of paths/hierarchies in the deployment struct, the expected value, and the assertion text.

updateWebhookContainerSpec(deployment, image, logLevel)
case certControllerDeploymentAssetName:
updateCertControllerContainerSpec(deployment, image, logLevel)
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.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 26, 2025
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Oct 6, 2025
Copy link

openshift-ci bot commented Oct 6, 2025

New changes are detected. LGTM label has been removed.

Copy link

coderabbitai bot commented Oct 6, 2025

Walkthrough

Adds a helper that sets the Bitwarden TLS certs volume SecretName from BitwardenSecretManagerProvider.SecretRef and calls it when building the Bitwarden Deployment. Tests were expanded to capture the reconciled Deployment, assert the volume secret name, verify container image, and validate pod spec fields in a new Bitwarden-with-secretRef test.

Changes

Cohort / File(s) Change summary
Controller logic: Bitwarden volume config
pkg/controller/external_secrets/deployments.go
Adds updateBitwardenVolumeConfig(deployment, esc) which ensures a bitwarden-tls-certs volume exists, creates or updates a SecretVolumeSource, and sets its SecretName from BitwardenSecretManagerProvider.SecretRef.Name; invoked from getDeploymentObject for the Bitwarden deployment asset.
Tests: Deployment capture and validation
pkg/controller/external_secrets/deployments_test.go
Extends test harness to pass a captured Deployment pointer into preReq, capture Create/Update calls via DeepCopy, introduces validateDeployment callback and a new test case "bitwarden is enabled with secretRef for certificates" that asserts the volume secret name, checks the bitwarden-sdk-server container image (uses commontest.TestExternalSecretsImageName), and validates pod spec fields (affinity, pod/node affinity, tolerations, nodeSelector, resources).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title “ESO-155: Fixes bitwarden deployment to use custom certificates” directly conveys that the change enables the Bitwarden deployment to utilize custom certificate secrets and references the associated Jira issue, making it specific and aligned with the core code modifications.
Description Check ✅ Passed The pull request description clearly states that the Bitwarden deployment is updated to use a user-configured certificate secret and that tests have been updated to validate this behavior, which accurately reflects the underlying code and test changes.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between abab87b and 5e3364d.

📒 Files selected for processing (2)
  • pkg/controller/external_secrets/deployments.go (2 hunks)
  • pkg/controller/external_secrets/deployments_test.go (16 hunks)
🔇 Additional comments (4)
pkg/controller/external_secrets/deployments.go (1)

134-134: LGTM!

The call to updateBitwardenVolumeConfig is appropriately placed in the Bitwarden deployment path to configure custom certificates.

pkg/controller/external_secrets/deployments_test.go (3)

24-26: Good test infrastructure enhancement.

The addition of capturedDeployment parameter and validateDeployment callback enables thorough validation of reconciler behavior. This pattern provides excellent test coverage for deployment mutations.


526-616: Excellent test coverage for Bitwarden certificate configuration.

The new test case thoroughly validates the Bitwarden deployment update behavior:

  • Verifies the bitwarden-tls-certs volume secret name is correctly updated from user configuration
  • Validates the bitwarden-sdk-server container image is properly set
  • Confirms basic deployment structure integrity

The test properly addresses previous feedback by using bitwardenDeploymentAssetName and validating against the expected image constant.


649-651: Clean validation pattern.

The conditional invocation of validateDeployment only when a deployment is captured is a clean approach that avoids test failures when deployments aren't expected to be modified.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 5f07a1e and faa64e8.

📒 Files selected for processing (2)
  • pkg/controller/external_secrets/deployments.go (2 hunks)
  • pkg/controller/external_secrets/deployments_test.go (16 hunks)
🔇 Additional comments (4)
pkg/controller/external_secrets/deployments.go (1)

134-134: LGTM!

The integration of the Bitwarden volume configuration update is properly placed within the bitwarden deployment case.

pkg/controller/external_secrets/deployments_test.go (3)

24-47: LGTM!

The deployment capture mechanism is well implemented and enables proper validation of the reconciler's behavior. The use of a pointer-to-pointer pattern allows the preReq function to populate the captured deployment for later validation.

Also applies to: 630-633


52-312: Comprehensive validation with room for future refactoring.

The validation functions provide thorough coverage of deployment configurations including images, labels, affinity rules, tolerations, node selectors, and resource requirements. While the validation logic is verbose, it ensures proper behavior.

As per a past review comment: Consider a declarative approach in future refactoring—a list of paths/hierarchies in the deployment struct with expected values and assertion text could reduce verbosity.


651-658: LGTM!

The validation ensures that the status image is correctly updated after successful deployment reconciliation and that the validateDeployment callback is invoked when provided. This completes the end-to-end validation flow.

Comment on lines 397 to 406
func updateBitwardenVolumeConfig(deployment *appsv1.Deployment, esc *operatorv1alpha1.ExternalSecretsConfig) {
if esc.Spec.Plugins.BitwardenSecretManagerProvider.SecretRef != nil &&
esc.Spec.Plugins.BitwardenSecretManagerProvider.SecretRef.Name != "" {
for i := range deployment.Spec.Template.Spec.Volumes {
if deployment.Spec.Template.Spec.Volumes[i].Name == "bitwarden-tls-certs" {
deployment.Spec.Template.Spec.Volumes[i].Secret.SecretName = esc.Spec.Plugins.BitwardenSecretManagerProvider.SecretRef.Name
}
}
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Add nil checks to prevent potential panics.

The function has two nil pointer dereference risks:

  1. Line 398: esc.Spec.Plugins.BitwardenSecretManagerProvider.SecretRef - No nil check for BitwardenSecretManagerProvider before accessing SecretRef
  2. Line 402: deployment.Spec.Template.Spec.Volumes[i].Secret.SecretName - No nil check for Secret before accessing SecretName. If the volume is configured as a different type (ConfigMap, EmptyDir, etc.), this will panic.

Apply this diff to add defensive checks and optimize the loop:

 func updateBitwardenVolumeConfig(deployment *appsv1.Deployment, esc *operatorv1alpha1.ExternalSecretsConfig) {
-	if esc.Spec.Plugins.BitwardenSecretManagerProvider.SecretRef != nil &&
-		esc.Spec.Plugins.BitwardenSecretManagerProvider.SecretRef.Name != "" {
+	if esc.Spec.Plugins.BitwardenSecretManagerProvider != nil &&
+		esc.Spec.Plugins.BitwardenSecretManagerProvider.SecretRef != nil &&
+		esc.Spec.Plugins.BitwardenSecretManagerProvider.SecretRef.Name != "" {
 		for i := range deployment.Spec.Template.Spec.Volumes {
 			if deployment.Spec.Template.Spec.Volumes[i].Name == "bitwarden-tls-certs" {
+				if deployment.Spec.Template.Spec.Volumes[i].Secret == nil {
+					continue
+				}
 				deployment.Spec.Template.Spec.Volumes[i].Secret.SecretName = esc.Spec.Plugins.BitwardenSecretManagerProvider.SecretRef.Name
+				break
 			}
 		}
 	}
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func updateBitwardenVolumeConfig(deployment *appsv1.Deployment, esc *operatorv1alpha1.ExternalSecretsConfig) {
if esc.Spec.Plugins.BitwardenSecretManagerProvider.SecretRef != nil &&
esc.Spec.Plugins.BitwardenSecretManagerProvider.SecretRef.Name != "" {
for i := range deployment.Spec.Template.Spec.Volumes {
if deployment.Spec.Template.Spec.Volumes[i].Name == "bitwarden-tls-certs" {
deployment.Spec.Template.Spec.Volumes[i].Secret.SecretName = esc.Spec.Plugins.BitwardenSecretManagerProvider.SecretRef.Name
}
}
}
}
func updateBitwardenVolumeConfig(deployment *appsv1.Deployment, esc *operatorv1alpha1.ExternalSecretsConfig) {
if esc.Spec.Plugins.BitwardenSecretManagerProvider != nil &&
esc.Spec.Plugins.BitwardenSecretManagerProvider.SecretRef != nil &&
esc.Spec.Plugins.BitwardenSecretManagerProvider.SecretRef.Name != "" {
for i := range deployment.Spec.Template.Spec.Volumes {
if deployment.Spec.Template.Spec.Volumes[i].Name == "bitwarden-tls-certs" {
if deployment.Spec.Template.Spec.Volumes[i].Secret == nil {
continue
}
deployment.Spec.Template.Spec.Volumes[i].Secret.SecretName = esc.Spec.Plugins.BitwardenSecretManagerProvider.SecretRef.Name
break
}
}
}
}
🤖 Prompt for AI Agents
In pkg/controller/external_secrets/deployments.go around lines 397 to 406, guard
against nil dereferences by first checking
esc.Spec.Plugins.BitwardenSecretManagerProvider is not nil before accessing its
SecretRef, then check SecretRef is non-nil and has a non-empty Name; iterate the
deployment.Spec.Template.Spec.Volumes and for each volume only update
Secret.SecretName if volume.Secret is non-nil (skip other volume types), assign
the SecretName from
esc.Spec.Plugins.BitwardenSecretManagerProvider.SecretRef.Name and break the
loop once the "bitwarden-tls-certs" volume is found and updated.

@openshift-ci openshift-ci bot added px-approved Signifies that Product Support has signed off on this PR qe-approved Signifies that QE has signed off on this PR labels Oct 7, 2025
@openshift-ci-robot
Copy link

openshift-ci-robot commented Oct 7, 2025

@bharath-b-rh: This pull request references ESO-155 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the epic to target the "4.21.0" version, but no target version was set.

In response to this:

PR has following changes

  • Updates bitwarden deployment to use the user configured secret for certificates.
  • Updates tests to validate the deployment object is updated as per user configuration.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@bharath-b-rh
Copy link
Contributor Author

/label px-approved
/label docs-approved

@openshift-ci openshift-ci bot added the docs-approved Signifies that Docs has signed off on this PR label Oct 7, 2025
@bharath-b-rh
Copy link
Contributor Author

/remove qe-approved

@bharath-b-rh
Copy link
Contributor Author

/remove-qe-approved

@bharath-b-rh
Copy link
Contributor Author

/hold for verification

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 7, 2025
Copy link

openshift-ci bot commented Oct 7, 2025

@bharath-b-rh: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-operator 5e3364d link true /test e2e-operator

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 7, 2025
@openshift-merge-robot
Copy link

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. docs-approved Signifies that Docs has signed off on this PR jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. px-approved Signifies that Product Support has signed off on this PR qe-approved Signifies that QE has signed off on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants