mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
[Feature] Agency ArangoSync State check (#1165)
This commit is contained in:
parent
8af2e617ac
commit
1ced857405
10 changed files with 157 additions and 6 deletions
|
@ -7,6 +7,7 @@
|
||||||
- (Refactoring) Extract kerrors package
|
- (Refactoring) Extract kerrors package
|
||||||
- (Refactoring) Extract Inspector Definitions package
|
- (Refactoring) Extract Inspector Definitions package
|
||||||
- (Bugfix) Fix PDBs Version discovery
|
- (Bugfix) Fix PDBs Version discovery
|
||||||
|
- (Feature) Agency ArangoSync State check
|
||||||
|
|
||||||
## [1.2.20](https://github.com/arangodb/kube-arangodb/tree/1.2.20) (2022-10-25)
|
## [1.2.20](https://github.com/arangodb/kube-arangodb/tree/1.2.20) (2022-10-25)
|
||||||
- (Feature) Add action progress
|
- (Feature) Add action progress
|
||||||
|
|
81
pkg/deployment/agency/arangosync.go
Normal file
81
pkg/deployment/agency/arangosync.go
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
//
|
||||||
|
// DISCLAIMER
|
||||||
|
//
|
||||||
|
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
||||||
|
//
|
||||||
|
|
||||||
|
package agency
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ json.Unmarshaler = &ArangoSyncLazy{}
|
||||||
|
)
|
||||||
|
|
||||||
|
// ArangoSyncLazy allows failure during load of the Sync state
|
||||||
|
type ArangoSyncLazy struct {
|
||||||
|
Error error
|
||||||
|
*ArangoSync
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ArangoSyncLazy) UnmarshalJSON(bytes []byte) error {
|
||||||
|
var s ArangoSync
|
||||||
|
|
||||||
|
if err := json.Unmarshal(bytes, &s); err != nil {
|
||||||
|
a.ArangoSync = nil
|
||||||
|
a.Error = err
|
||||||
|
} else {
|
||||||
|
a.ArangoSync = &s
|
||||||
|
a.Error = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type ArangoSync struct {
|
||||||
|
State ArangoSyncState `json:"synchronizationState"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ArangoSync) IsSyncInProgress() bool {
|
||||||
|
if a == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check Incoming
|
||||||
|
if s := a.State.Incoming.State; s != nil && *s != "inactive" && *s != "" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if a.State.Outgoing.Targets.Exists() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
type ArangoSyncState struct {
|
||||||
|
Incoming ArangoSyncIncomingState `json:"incoming"`
|
||||||
|
Outgoing ArangoSyncOutgoingState `json:"outgoing"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ArangoSyncIncomingState struct {
|
||||||
|
State *string `json:"state,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ArangoSyncOutgoingState struct {
|
||||||
|
Targets StateExists `json:"targets,omitempty"`
|
||||||
|
}
|
47
pkg/deployment/agency/arangosync_test.go
Normal file
47
pkg/deployment/agency/arangosync_test.go
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
//
|
||||||
|
// DISCLAIMER
|
||||||
|
//
|
||||||
|
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
||||||
|
//
|
||||||
|
|
||||||
|
package agency
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Sync_Target(t *testing.T) {
|
||||||
|
var s DumpState
|
||||||
|
require.NoError(t, json.Unmarshal(syncSource, &s))
|
||||||
|
|
||||||
|
require.NotNil(t, s.Agency.ArangoDB.ArangoSync.ArangoSync)
|
||||||
|
require.True(t, s.Agency.ArangoDB.ArangoSync.ArangoSync.State.Outgoing.Targets.Exists())
|
||||||
|
require.True(t, s.Agency.ArangoDB.ArangoSync.IsSyncInProgress())
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_Sync_Source(t *testing.T) {
|
||||||
|
var s DumpState
|
||||||
|
require.NoError(t, json.Unmarshal(syncTarget, &s))
|
||||||
|
|
||||||
|
require.NotNil(t, s.Agency.ArangoDB.ArangoSync.ArangoSync)
|
||||||
|
require.NotNil(t, s.Agency.ArangoDB.ArangoSync.ArangoSync.State.Incoming.State)
|
||||||
|
require.Equal(t, "running", *s.Agency.ArangoDB.ArangoSync.ArangoSync.State.Incoming.State)
|
||||||
|
require.True(t, s.Agency.ArangoDB.ArangoSync.IsSyncInProgress())
|
||||||
|
}
|
|
@ -32,4 +32,6 @@ func Test_Databases(t *testing.T) {
|
||||||
require.NoError(t, json.Unmarshal(agencyDump39HotBackup, &s))
|
require.NoError(t, json.Unmarshal(agencyDump39HotBackup, &s))
|
||||||
|
|
||||||
require.Contains(t, s.Agency.Arango.Plan.Databases, "_system")
|
require.Contains(t, s.Agency.Arango.Plan.Databases, "_system")
|
||||||
|
|
||||||
|
require.False(t, s.Agency.ArangoDB.ArangoSync.IsSyncInProgress())
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,13 +87,18 @@ func (c *cache) loadState(ctx context.Context, client agency.Agency) (State, err
|
||||||
type StateRoots []StateRoot
|
type StateRoots []StateRoot
|
||||||
|
|
||||||
type StateRoot struct {
|
type StateRoot struct {
|
||||||
Arango State `json:"arango"`
|
Arango State `json:"arango"`
|
||||||
|
ArangoDB StateDB `json:"arangodb,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DumpState struct {
|
type DumpState struct {
|
||||||
Agency StateRoot `json:"agency"`
|
Agency StateRoot `json:"agency"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type StateDB struct {
|
||||||
|
ArangoSync ArangoSyncLazy `json:"arangosync,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type State struct {
|
type State struct {
|
||||||
Supervision StateSupervision `json:"Supervision"`
|
Supervision StateSupervision `json:"Supervision"`
|
||||||
Plan StatePlan `json:"Plan"`
|
Plan StatePlan `json:"Plan"`
|
||||||
|
|
|
@ -20,7 +20,11 @@
|
||||||
|
|
||||||
package agency
|
package agency
|
||||||
|
|
||||||
import "github.com/arangodb/kube-arangodb/pkg/util"
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
|
|
||||||
|
"github.com/arangodb/kube-arangodb/pkg/util"
|
||||||
|
)
|
||||||
|
|
||||||
type StateExists []byte
|
type StateExists []byte
|
||||||
|
|
||||||
|
@ -42,10 +46,9 @@ func (d *StateExists) UnmarshalJSON(bytes []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
z := make([]byte, len(bytes))
|
data := sha256.Sum256(bytes)
|
||||||
|
allData := data[:]
|
||||||
|
|
||||||
copy(z, bytes)
|
*d = allData
|
||||||
|
|
||||||
*d = z
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,12 @@ var agencyDump39Jobs []byte
|
||||||
//go:embed testdata/longdata.json
|
//go:embed testdata/longdata.json
|
||||||
var longData []byte
|
var longData []byte
|
||||||
|
|
||||||
|
//go:embed testdata/sync.source.json
|
||||||
|
var syncSource []byte
|
||||||
|
|
||||||
|
//go:embed testdata/sync.target.json
|
||||||
|
var syncTarget []byte
|
||||||
|
|
||||||
var (
|
var (
|
||||||
data = map[string][]byte{
|
data = map[string][]byte{
|
||||||
"3.6": agencyDump36,
|
"3.6": agencyDump36,
|
||||||
|
|
|
@ -35,11 +35,15 @@ func Test_Target_HotBackup(t *testing.T) {
|
||||||
require.True(t, s.Agency.Arango.Target.HotBackup.Create.Exists())
|
require.True(t, s.Agency.Arango.Target.HotBackup.Create.Exists())
|
||||||
|
|
||||||
t.Log(s.Agency.Arango.Target.HotBackup.Create.time.String())
|
t.Log(s.Agency.Arango.Target.HotBackup.Create.time.String())
|
||||||
|
|
||||||
|
require.False(t, s.Agency.ArangoDB.ArangoSync.IsSyncInProgress())
|
||||||
})
|
})
|
||||||
t.Run("Does Not Exists", func(t *testing.T) {
|
t.Run("Does Not Exists", func(t *testing.T) {
|
||||||
var s DumpState
|
var s DumpState
|
||||||
require.NoError(t, json.Unmarshal(agencyDump39Satellite, &s))
|
require.NoError(t, json.Unmarshal(agencyDump39Satellite, &s))
|
||||||
|
|
||||||
require.False(t, s.Agency.Arango.Target.HotBackup.Create.Exists())
|
require.False(t, s.Agency.Arango.Target.HotBackup.Create.Exists())
|
||||||
|
|
||||||
|
require.False(t, s.Agency.ArangoDB.ArangoSync.IsSyncInProgress())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
1
pkg/deployment/agency/testdata/sync.source.json
vendored
Executable file
1
pkg/deployment/agency/testdata/sync.source.json
vendored
Executable file
File diff suppressed because one or more lines are too long
1
pkg/deployment/agency/testdata/sync.target.json
vendored
Executable file
1
pkg/deployment/agency/testdata/sync.target.json
vendored
Executable file
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue