Skip to content

Commit d01fae8

Browse files
authored
Merge pull request #1156 from k8up-io/fix/archive-nil-s3-985
Fix nil pointer panic in S3Spec.RestoreEnvVars with nil receiver
2 parents a6929dd + 127b65f commit d01fae8

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

api/v1/backend.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ func (in *S3Spec) String() string {
147147

148148
// RestoreEnvVars returns the env vars for this backend when using Restore jobs.
149149
func (in *S3Spec) RestoreEnvVars() map[string]*corev1.EnvVar {
150+
if in == nil {
151+
return nil
152+
}
150153
vars := make(map[string]*corev1.EnvVar)
151154
if in.AccessKeyIDSecretRef != nil {
152155
vars[cfg.RestoreS3AccessKeyIDEnvName] = &corev1.EnvVar{

api/v1/restore_types_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package v1
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestS3SpecRestoreEnvVarsWithNilReceiver(t *testing.T) {
10+
// When a user specifies "s3:" with a nil value in YAML,
11+
// S3 is nil but RestoreMethod is not.
12+
// Calling RestoreEnvVars() on nil S3Spec must not panic.
13+
var s3 *S3Spec
14+
assert.NotPanics(t, func() {
15+
result := s3.RestoreEnvVars()
16+
assert.Nil(t, result)
17+
})
18+
}

0 commit comments

Comments
 (0)