rgw: fix error handling for secret lookup

Get will return a non-nil pointer even in the error case.

Signed-off-by: Steven Fackler <sfackler@gmail.com>
(cherry picked from commit 6935dfdc47)
This commit is contained in:
Steven Fackler authored and Mergify committed 2025-01-24 06:37:10 +00:00
1 parent 402e082343
commit 69920a3a29
2 files changed
+9 -3

No files matched your search

+3 -3
View File
@@ -872,10 +872,10 @@ func (c *clusterConfig) generateVolumeSourceWithCaBundleSecret() (*v1.SecretVolu
func (c *clusterConfig) rgwTLSSecretType(secretName string) (v1.SecretType, error) {
rgwTlsSecret, err := c.context.Clientset.CoreV1().Secrets(c.clusterInfo.Namespace).Get(c.clusterInfo.Context, secretName, metav1.GetOptions{})
if rgwTlsSecret != nil {
return rgwTlsSecret.Type, nil
if err != nil {
return "", errors.Wrapf(err, "failed to get Kubernetes secrets referring the TLS certificates")
}
return "", errors.Wrapf(err, "no Kubernetes secrets referring TLS certificates found")
return rgwTlsSecret.Type, nil
}
func getDaemonName(rgwConfig *rgwConfig) string {
+6
View File
@@ -182,6 +182,12 @@ func TestSSLPodSpec(t *testing.T) {
assert.Error(t, err)
// Using SSLCertificateRef
c.store.Spec.Gateway.SSLCertificateRef = "bogusCert"
// Secret missing, will return error
_, err = c.makeRGWPodSpec(rgwConfig)
assert.Error(t, err)
// Opaque Secret
c.store.Spec.Gateway.SSLCertificateRef = "mycert"
rgwtlssecret := &v1.Secret{