1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

[Feature] Add P0 Compare func (#1490)

This commit is contained in:
Adam Janikowski 2023-11-17 12:17:38 +01:00 committed by GitHub
parent 5fe686928e
commit cdaf4a0b35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 0 deletions

View file

@ -13,6 +13,7 @@
- (Feature) Add support for CRD validation schemas
- (Bugfix) Fix Replaced Member Zone during Replace operation
- (Feature) (ML) Handlers
- (Feature) Add P0 Compare Func
## [1.2.35](https://github.com/arangodb/kube-arangodb/tree/1.2.35) (2023-11-06)
- (Maintenance) Update go-driver to v1.6.0, update IsNotFound() checks

View file

@ -27,6 +27,75 @@ import (
"github.com/arangodb/kube-arangodb/pkg/logging"
)
// P0 runs compare of the provided templates without generic parameters
func P0[T interface{}](
log logging.Logger,
actionBuilder api.ActionBuilder,
checksum Checksum[T],
spec, status Template[T],
evaluators ...GenP0[T]) (mode Mode, plan api.Plan, err error) {
if spec.GetChecksum() == status.GetChecksum() {
return SkippedRotation, nil, nil
}
mode = SilentRotation
// Try to fill fields
newStatus := status.GetTemplate()
currentSpec := spec.GetTemplate()
g := NewFuncGenP0[T](currentSpec, newStatus)
evaluatorsFunc := make([]Func, len(evaluators))
for id := range evaluators {
evaluatorsFunc[id] = g(evaluators[id])
}
if m, p, err := Evaluate(actionBuilder, evaluatorsFunc...); err != nil {
log.Err(err).Error("Error while getting diff")
return SkippedRotation, nil, err
} else {
mode = mode.And(m)
plan = append(plan, p...)
}
// Diff has been generated! Proceed with calculations
checksumString, err := checksum(newStatus)
if err != nil {
log.Err(err).Error("Error while getting checksum")
return SkippedRotation, nil, err
}
if checksumString != spec.GetChecksum() {
line := log
// Rotate anyway!
specData, statusData, diff, err := Diff(currentSpec, newStatus)
if err == nil {
if diff != "" {
line = line.Str("diff", diff)
}
if specData != "" {
line = line.Str("spec", specData)
}
if statusData != "" {
line = line.Str("status", statusData)
}
}
line.Info("Resource %s needs rotation - templates does not match", reflect.TypeOf(currentSpec).String())
return GracefulRotation, nil, nil
}
return
}
// P2 runs compare of the provided templates with 2 generic parameters
func P2[T interface{}, P1, P2 interface{}](
log logging.Logger,

View file

@ -20,6 +20,16 @@
package compare
type GenP0[T interface{}] func(spec, status *T) Func
type FuncGenP0[T interface{}] func(in GenP0[T]) Func
func NewFuncGenP0[T interface{}](spec, status *T) FuncGenP0[T] {
return func(in GenP0[T]) Func {
return in(spec, status)
}
}
type GenP2[T, P1, P2 interface{}] func(p1 P1, p2 P2, spec, status *T) Func
type FuncGenP2[T, P1, P2 interface{}] func(in GenP2[T, P1, P2]) Func