mirror of https://github.com/status-im/consul.git
* config raft apply silent error (#10657) * return an error when the index is not valid * check response as bool when applying `CAOpSetConfig` * remove check for bool response * fix error message and add check to test * fix comment * add changelog Conflicts: agent/consul/state/connect_ca.go agent/consul/state/connect_ca_test.go * fix imports * fix imports in connect_ca_test.go
This commit is contained in:
parent
fad658591c
commit
168da807b7
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
ca: report an error when setting the ca config fail because of an index check.
|
||||
```
|
|
@ -3,6 +3,8 @@ package state
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/hashicorp/consul/agent/structs"
|
||||
"github.com/hashicorp/go-memdb"
|
||||
)
|
||||
|
@ -148,7 +150,7 @@ func (s *Store) CASetConfig(idx uint64, config *structs.CAConfiguration) error {
|
|||
|
||||
// CACheckAndSetConfig is used to try updating the CA configuration with a
|
||||
// given Raft index. If the CAS index specified is not equal to the last observed index
|
||||
// for the config, then the call is a noop,
|
||||
// for the config, then the call will return an error,
|
||||
func (s *Store) CACheckAndSetConfig(idx, cidx uint64, config *structs.CAConfiguration) (bool, error) {
|
||||
tx := s.db.Txn(true)
|
||||
defer tx.Abort()
|
||||
|
@ -164,7 +166,7 @@ func (s *Store) CACheckAndSetConfig(idx, cidx uint64, config *structs.CAConfigur
|
|||
// return early here.
|
||||
e, ok := existing.(*structs.CAConfiguration)
|
||||
if (ok && e.ModifyIndex != cidx) || (!ok && cidx != 0) {
|
||||
return false, nil
|
||||
return false, errors.Errorf("ModifyIndex did not match existing")
|
||||
}
|
||||
|
||||
if err := s.caSetConfigTxn(idx, tx, config); err != nil {
|
||||
|
|
|
@ -3,13 +3,18 @@ package state
|
|||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/consul/sdk/testutil"
|
||||
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-memdb"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/hashicorp/consul/agent/connect"
|
||||
"github.com/hashicorp/consul/agent/structs"
|
||||
"github.com/hashicorp/go-memdb"
|
||||
"github.com/pascaldekloe/goe/verify"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStore_CAConfig(t *testing.T) {
|
||||
|
@ -60,9 +65,9 @@ func TestStore_CAConfigCAS(t *testing.T) {
|
|||
ok, err := s.CACheckAndSetConfig(2, 0, &structs.CAConfiguration{
|
||||
Provider: "static",
|
||||
})
|
||||
if ok || err != nil {
|
||||
t.Fatalf("expected (false, nil), got: (%v, %#v)", ok, err)
|
||||
}
|
||||
|
||||
require.False(t, ok)
|
||||
testutil.RequireErrorContains(t, err, "ModifyIndex did not match existing")
|
||||
|
||||
// Check that the index is untouched and the entry
|
||||
// has not been updated.
|
||||
|
|
Loading…
Reference in New Issue