Skip to content

Commit

Permalink
feat(operator): add ee modules (#961)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag authored Dec 6, 2023
1 parent 9b02048 commit 4330cf4
Show file tree
Hide file tree
Showing 6 changed files with 399 additions and 13 deletions.
347 changes: 347 additions & 0 deletions components/fctl/membershipclient/go.sum

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions components/operator/apis/stack/v1beta3/configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,28 @@ func (in *ConfigurationServicesSpec) List() []string {
return ret
}

func (in *ConfigurationServicesSpec) IsDisabled(service string) bool {
func (in *ConfigurationServicesSpec) getDisabledProperty(service string) *bool {
valueOf := reflect.ValueOf(in).Elem().FieldByName(strcase.ToCamel(service))
if valueOf.IsValid() {
_, ok := valueOf.Type().FieldByName("CommonServiceProperties")
if !ok {
return false
return nil
}
commonServiceProperties := valueOf.FieldByName("CommonServiceProperties")
properties := commonServiceProperties.Interface().(CommonServiceProperties)
return properties.Disabled != nil && *properties.Disabled
return properties.Disabled
}
return false
return nil
}

func (in *ConfigurationServicesSpec) IsExplicitlyDisabled(service string) bool {
disabled := in.getDisabledProperty(service)
return disabled != nil && *disabled
}

func (in *ConfigurationServicesSpec) IsExplicitlyEnabled(service string) bool {
disabled := in.getDisabledProperty(service)
return disabled != nil && !*disabled
}

// TODO: Handle validation
Expand Down
16 changes: 13 additions & 3 deletions components/operator/apis/stack/v1beta3/stack_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,23 @@ type StackSpec struct {
Services StackServicesSpec `json:"services,omitempty"`
}

func (in *StackServicesSpec) IsDisabled(service string) bool {
func (in *StackServicesSpec) getDisabledProperty(service string) *bool {
valueOf := reflect.ValueOf(in).Elem().FieldByName(strcase.ToCamel(service))
if valueOf.IsValid() {
properties := valueOf.Interface().(StackServicePropertiesSpec)
return properties.Disabled != nil && *properties.Disabled
return properties.Disabled
}
return false
return nil
}

func (in *StackServicesSpec) IsExplicitlyDisabled(service string) bool {
disabled := in.getDisabledProperty(service)
return disabled != nil && *disabled
}

func (in *StackServicesSpec) IsExplicitlyEnabled(service string) bool {
disabled := in.getDisabledProperty(service)
return disabled != nil && !*disabled
}

type ControlAuthentication struct {
Expand Down
2 changes: 1 addition & 1 deletion components/operator/internal/modules/gateway/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func createCaddyfile(context modules.ServiceInstallConfiguration) string {
fallback = *context.Configuration.Spec.Services.Gateway.Fallback
redirect = true
} else {
if !context.IsDisabled("control") {
if !context.IsDisabled("control", false) {
fallback = fmt.Sprintf("control:%d", servicesMap["control"].Port)
}
}
Expand Down
15 changes: 15 additions & 0 deletions components/operator/internal/modules/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ type Module interface {
Versions() map[string]Version
}

// As standard modules are always enabled, EE modules are, by default disabled.
// To enable an ee module, it must be explicitely defined with disabled == false,
// either in global configuration, or per stack
type EEModule interface {
IsEE() bool
}

func IsEE(m Module) bool {
eeModule, ok := m.(EEModule)
if ok {
ok = eeModule.IsEE()
}
return ok
}

type DependsOnAwareModule interface {
Module
DependsOn() []Module
Expand Down
14 changes: 9 additions & 5 deletions components/operator/internal/modules/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ type ReconciliationConfig struct {
Platform Platform
}

func (s *ReconciliationConfig) IsDisabled(module string) bool {
return s.Stack.Spec.Services.IsDisabled(module) || s.Configuration.Spec.Services.IsDisabled(module)
func (s *ReconciliationConfig) IsDisabled(module string, isEE bool) bool {
if isEE {
return !s.Stack.Spec.Services.IsExplicitlyEnabled(module) && !s.Configuration.Spec.Services.IsExplicitlyEnabled(module)
} else {
return s.Stack.Spec.Services.IsExplicitlyDisabled(module) || s.Configuration.Spec.Services.IsExplicitlyDisabled(module)
}
}

type StackReconciler struct {
Expand Down Expand Up @@ -143,7 +147,7 @@ func (r *StackReconciler) Reconcile(ctx context.Context) (bool, error) {

if r.Configuration.Spec.LightMode {
for _, module := range getSortedModules() {
if r.IsDisabled(module.Name()) {
if r.IsDisabled(module.Name(), IsEE(module)) {
continue
}
if !r.ready.Contains(module) {
Expand All @@ -169,7 +173,7 @@ func (r *StackReconciler) Reconcile(ctx context.Context) (bool, error) {
logger.Info("Finalize modules")
allReady := true
for _, module := range getSortedModules() {
if r.IsDisabled(module.Name()) {
if r.IsDisabled(module.Name(), IsEE(module)) {
continue
}
if !r.ready.Contains(module) {
Expand Down Expand Up @@ -319,7 +323,7 @@ func (r *StackReconciler) prepareModule(ctx context.Context, module Module,
return nil
}

if r.IsDisabled(module.Name()) {
if r.IsDisabled(module.Name(), IsEE(module)) {
return r.scaleDownStackModule(ctx, module)
}

Expand Down

1 comment on commit 4330cf4

@vercel
Copy link

@vercel vercel bot commented on 4330cf4 Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.