mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
[Feature] Add Feature dependency (#1357)
This commit is contained in:
parent
544833f72f
commit
7ad5d275b4
5 changed files with 71 additions and 12 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
|
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
|
||||||
- (Feature) Backup lifetime - remove Backup once its lifetime has been reached
|
- (Feature) Backup lifetime - remove Backup once its lifetime has been reached
|
||||||
|
- (Feature) Add Feature dependency
|
||||||
|
|
||||||
## [1.2.31](https://github.com/arangodb/kube-arangodb/tree/1.2.31) (2023-07-14)
|
## [1.2.31](https://github.com/arangodb/kube-arangodb/tree/1.2.31) (2023-07-14)
|
||||||
- (Improvement) Block traffic on the services if there is more than 1 active leader in ActiveFailover mode
|
- (Improvement) Block traffic on the services if there is more than 1 active leader in ActiveFailover mode
|
||||||
|
|
|
@ -304,9 +304,12 @@ func executeMain(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
podNameParts := strings.Split(name, "-")
|
podNameParts := strings.Split(name, "-")
|
||||||
operatorID := podNameParts[len(podNameParts)-1]
|
operatorID := podNameParts[len(podNameParts)-1]
|
||||||
|
|
||||||
|
if operatorID != "" {
|
||||||
logging.Global().RegisterWrappers(func(in *zerolog.Event) *zerolog.Event {
|
logging.Global().RegisterWrappers(func(in *zerolog.Event) *zerolog.Event {
|
||||||
return in.Str("operator-id", operatorID)
|
return in.Str("operator-id", operatorID)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
logger.Info("nice to meet you")
|
logger.Info("nice to meet you")
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
package features
|
package features
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/arangodb/go-driver"
|
"github.com/arangodb/go-driver"
|
||||||
|
|
||||||
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
|
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
|
||||||
|
@ -32,11 +34,30 @@ const (
|
||||||
Disabled = "false"
|
Disabled = "false"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Features []Feature
|
||||||
|
|
||||||
|
func (f Features) Get(name string) (Feature, bool) {
|
||||||
|
for _, feature := range features {
|
||||||
|
if feature.Name() == name {
|
||||||
|
return feature, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f Features) Sort() {
|
||||||
|
sort.Slice(f, func(i, j int) bool {
|
||||||
|
return f[i].Name() < f[j].Name()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
var _ Feature = &feature{}
|
var _ Feature = &feature{}
|
||||||
|
|
||||||
type Feature interface {
|
type Feature interface {
|
||||||
Name() string
|
Name() string
|
||||||
Description() string
|
Description() string
|
||||||
|
Dependencies() []Feature
|
||||||
Version() driver.Version
|
Version() driver.Version
|
||||||
EnterpriseRequired() bool
|
EnterpriseRequired() bool
|
||||||
OperatorEnterpriseRequired() bool
|
OperatorEnterpriseRequired() bool
|
||||||
|
@ -56,6 +77,19 @@ type feature struct {
|
||||||
deprecated string
|
deprecated string
|
||||||
constValue *bool
|
constValue *bool
|
||||||
hidden bool
|
hidden bool
|
||||||
|
dependencies []Feature
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feature) Dependencies() []Feature {
|
||||||
|
if len(f.dependencies) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
q := make([]Feature, len(f.dependencies))
|
||||||
|
|
||||||
|
copy(q, f.dependencies)
|
||||||
|
|
||||||
|
return q
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f feature) ImageSupported(i *api.ImageInfo) bool {
|
func (f feature) ImageSupported(i *api.ImageInfo) bool {
|
||||||
|
@ -82,6 +116,12 @@ func (f feature) Enabled() bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, dep := range f.dependencies {
|
||||||
|
if !dep.Enabled() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if f.constValue != nil {
|
if f.constValue != nil {
|
||||||
return *f.constValue
|
return *f.constValue
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,8 @@ var optionalGracefulShutdown = &feature{
|
||||||
enterpriseRequired: false,
|
enterpriseRequired: false,
|
||||||
enabledByDefault: false,
|
enabledByDefault: false,
|
||||||
hidden: true,
|
hidden: true,
|
||||||
|
|
||||||
|
dependencies: []Feature{gracefulShutdown},
|
||||||
}
|
}
|
||||||
|
|
||||||
func GracefulShutdown() Feature {
|
func GracefulShutdown() Feature {
|
||||||
|
|
|
@ -23,6 +23,7 @@ package features
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -34,7 +35,7 @@ import (
|
||||||
|
|
||||||
const prefixArg = "deployment.feature"
|
const prefixArg = "deployment.feature"
|
||||||
|
|
||||||
var features = map[string]Feature{}
|
var features Features
|
||||||
var featuresLock sync.Mutex
|
var featuresLock sync.Mutex
|
||||||
var enableAll = false
|
var enableAll = false
|
||||||
|
|
||||||
|
@ -42,15 +43,13 @@ func registerFeature(f Feature) {
|
||||||
featuresLock.Lock()
|
featuresLock.Lock()
|
||||||
defer featuresLock.Unlock()
|
defer featuresLock.Unlock()
|
||||||
|
|
||||||
if f == nil {
|
if _, ok := features.Get(f.Name()); ok {
|
||||||
panic("Feature cannot be nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := features[f.Name()]; ok {
|
|
||||||
panic("Feature already registered")
|
panic("Feature already registered")
|
||||||
}
|
}
|
||||||
|
|
||||||
features[f.Name()] = f
|
features = append(features, f)
|
||||||
|
|
||||||
|
features.Sort()
|
||||||
}
|
}
|
||||||
|
|
||||||
var internalCMD = &cobra.Command{
|
var internalCMD = &cobra.Command{
|
||||||
|
@ -67,8 +66,8 @@ func Iterate(iterator Iterator) {
|
||||||
featuresLock.Lock()
|
featuresLock.Lock()
|
||||||
defer featuresLock.Unlock()
|
defer featuresLock.Unlock()
|
||||||
|
|
||||||
for name, feature := range features {
|
for _, feature := range features {
|
||||||
iterator(name, feature)
|
iterator(feature.Name(), feature)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,6 +129,13 @@ func cmdRun(_ *cobra.Command, _ []string) {
|
||||||
for _, feature := range features {
|
for _, feature := range features {
|
||||||
println(fmt.Sprintf("Feature: %s", feature.Name()))
|
println(fmt.Sprintf("Feature: %s", feature.Name()))
|
||||||
println(fmt.Sprintf("Description: %s", feature.Description()))
|
println(fmt.Sprintf("Description: %s", feature.Description()))
|
||||||
|
if deps := feature.Dependencies(); len(deps) > 0 {
|
||||||
|
names := make([]string, len(deps))
|
||||||
|
for id := range names {
|
||||||
|
names[id] = deps[id].Name()
|
||||||
|
}
|
||||||
|
println(fmt.Sprintf("Dependencies: %s", strings.Join(names, ", ")))
|
||||||
|
}
|
||||||
if feature.EnabledByDefault() {
|
if feature.EnabledByDefault() {
|
||||||
println("Enabled: true")
|
println("Enabled: true")
|
||||||
} else {
|
} else {
|
||||||
|
@ -155,6 +161,7 @@ func cmdRun(_ *cobra.Command, _ []string) {
|
||||||
|
|
||||||
// Supported returns false when:
|
// Supported returns false when:
|
||||||
// - feature is disabled.
|
// - feature is disabled.
|
||||||
|
// - any feature dependency is disabled.
|
||||||
// - a given version is lower than minimum feature version.
|
// - a given version is lower than minimum feature version.
|
||||||
// - feature expects enterprise but a given enterprise arg is not true.
|
// - feature expects enterprise but a given enterprise arg is not true.
|
||||||
func Supported(f Feature, v driver.Version, enterprise bool) bool {
|
func Supported(f Feature, v driver.Version, enterprise bool) bool {
|
||||||
|
@ -167,6 +174,12 @@ func Supported(f Feature, v driver.Version, enterprise bool) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, dependency := range f.Dependencies() {
|
||||||
|
if !Supported(dependency, v, enterprise) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return v.CompareTo(f.Version()) >= 0
|
return v.CompareTo(f.Version()) >= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue