Skip to content

Commit f26e5b2

Browse files
Merge branch 'main' into K8SPSMDB-1491-incremental-backup
2 parents f830521 + 7af8a76 commit f26e5b2

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

pkg/controller/perconaservermongodb/pbm.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/pkg/errors"
1414
"go.mongodb.org/mongo-driver/mongo"
1515
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
16+
"gopkg.in/yaml.v3"
1617
corev1 "k8s.io/api/core/v1"
1718
"k8s.io/apimachinery/pkg/labels"
1819
"k8s.io/apimachinery/pkg/types"
@@ -130,7 +131,7 @@ func (r *ReconcilePerconaServerMongoDB) reconcilePBMConfig(ctx context.Context,
130131
return strings.Compare(a.Name, b.Name)
131132
})
132133

133-
hash, err := hashPBMConfiguration(c)
134+
hash, err := hashPBMConfiguration(c, cr)
134135
if err != nil {
135136
return errors.Wrap(err, "hash config")
136137
}
@@ -196,12 +197,20 @@ func (r *ReconcilePerconaServerMongoDB) reconcilePBMConfig(ctx context.Context,
196197
return nil
197198
}
198199

199-
func hashPBMConfiguration(c []config.Config) (string, error) {
200+
func hashPBMConfiguration(c []config.Config, cr *psmdbv1.PerconaServerMongoDB) (string, error) {
201+
// Use YAML marshaller so that even credentials are included
202+
if cr.CompareVersion("1.22.0") >= 0 {
203+
v, err := yaml.Marshal(c)
204+
if err != nil {
205+
return "", err
206+
}
207+
return sha256Hash(v), nil
208+
}
209+
// Use JSON for versions prior to 1.22.0
200210
v, err := json.Marshal(c)
201211
if err != nil {
202212
return "", err
203213
}
204-
205214
return sha256Hash(v), nil
206215
}
207216

pkg/controller/perconaservermongodb/pbm_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import (
1010
"github.com/percona/percona-backup-mongodb/pbm/storage/gcs"
1111
"github.com/percona/percona-backup-mongodb/pbm/storage/mio"
1212
"github.com/percona/percona-backup-mongodb/pbm/storage/s3"
13+
"github.com/stretchr/testify/require"
14+
15+
psmdbv1 "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1"
1316
)
1417

1518
func TestIsResyncNeeded(t *testing.T) {
@@ -431,3 +434,32 @@ func TestIsResyncNeeded(t *testing.T) {
431434
})
432435
}
433436
}
437+
438+
func TestHashPBMConfiguration(t *testing.T) {
439+
t.Run("updating credentials changes hash", func(t *testing.T) {
440+
cr := &psmdbv1.PerconaServerMongoDB{Spec: psmdbv1.PerconaServerMongoDBSpec{CRVersion: "1.22.0"}}
441+
cfg := []config.Config{
442+
{
443+
Name: "test",
444+
Storage: config.StorageConf{
445+
S3: &s3.Config{
446+
Bucket: "operator-testing",
447+
Region: "us-east-1",
448+
EndpointURL: "https://s3.amazonaws.com",
449+
Prefix: "prefix",
450+
},
451+
},
452+
},
453+
}
454+
hash1, err := hashPBMConfiguration(cfg, cr)
455+
require.NoError(t, err)
456+
457+
cfg[0].Storage.S3.Credentials = s3.Credentials{
458+
AccessKeyID: "some-access-key",
459+
SecretAccessKey: "some-secret-key",
460+
}
461+
hash2, err := hashPBMConfiguration(cfg, cr)
462+
require.NoError(t, err)
463+
require.NotEqual(t, hash1, hash2)
464+
})
465+
}

0 commit comments

Comments
 (0)