From 73bc387eea22bcefc1110efaadaa24d6dd0e7e14 Mon Sep 17 00:00:00 2001 From: William Dumont Date: Tue, 2 Jul 2024 14:16:29 +0200 Subject: [PATCH] community components don't depend on the feature stability flag --- internal/component/registry.go | 8 ++++-- .../internal/controller/component_registry.go | 27 +++++++++++++------ .../internal/controller/loader_test.go | 8 ++++++ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/internal/component/registry.go b/internal/component/registry.go index 6a928005d9..9809b415ab 100644 --- a/internal/component/registry.go +++ b/internal/component/registry.go @@ -163,15 +163,19 @@ func (r Registration) CloneArguments() Arguments { // - the name is in use by another component, // - the name is invalid, // - the component name has a suffix length mismatch with an existing component, -// - the component's stability level is not defined. +// - the component's stability level is not defined and the component is not a community component +// - the component's stability level is defined and the component is a community component // // NOTE: the above panics will trigger during the integration tests if the registrations are invalid. func Register(r Registration) { if _, exist := registered[r.Name]; exist { panic(fmt.Sprintf("Component name %q already registered", r.Name)) } - if r.Stability == featuregate.StabilityUndefined { + switch { + case !r.Community && r.Stability == featuregate.StabilityUndefined: panic(fmt.Sprintf("Component %q has an undefined stability level - please provide stability level when registering the component", r.Name)) + case r.Community && r.Stability != featuregate.StabilityUndefined: + panic(fmt.Sprintf("Community component %q has a defined stability level - community components are not affected by the stability level. It should remain `undefined`", r.Name)) } parsed, err := parseComponentName(r.Name) diff --git a/internal/runtime/internal/controller/component_registry.go b/internal/runtime/internal/controller/component_registry.go index 2e8e73898d..4db44a3028 100644 --- a/internal/runtime/internal/controller/component_registry.go +++ b/internal/runtime/internal/controller/component_registry.go @@ -35,11 +35,17 @@ func (reg defaultComponentRegistry) Get(name string) (component.Registration, er if !exists { return component.Registration{}, fmt.Errorf("cannot find the definition of component name %q", name) } - if err := featuregate.CheckAllowed(cr.Stability, reg.minStability, fmt.Sprintf("component %q", name)); err != nil { - return component.Registration{}, err + + if cr.Community { + if !reg.community { + return component.Registration{}, fmt.Errorf("the component %q is a community component. Use the --community-component command-line flag to enable community components", name) + } + return cr, nil // community components are not affected by feature stability } - if cr.Community && !reg.community { - return component.Registration{}, fmt.Errorf("the component %q is a community component. Use the --community-component command-line flag to enable community components", name) + + err := featuregate.CheckAllowed(cr.Stability, reg.minStability, fmt.Sprintf("component %q", name)) + if err != nil { + return component.Registration{}, err } return cr, nil } @@ -71,11 +77,16 @@ func (m registryMap) Get(name string) (component.Registration, error) { if !ok { return component.Registration{}, fmt.Errorf("cannot find the definition of component name %q", name) } - if err := featuregate.CheckAllowed(reg.Stability, m.minStability, fmt.Sprintf("component %q", name)); err != nil { - return component.Registration{}, err + if reg.Community { + if !m.community { + return component.Registration{}, fmt.Errorf("the component %q is a community component. Use the --community-component command-line flag to enable community components", name) + } + return reg, nil // community components are not affected by feature stability } - if reg.Community && !m.community { - return component.Registration{}, fmt.Errorf("the component %q is a community component. Use the --community-component command-line flag to enable community components", name) + + err := featuregate.CheckAllowed(reg.Stability, m.minStability, fmt.Sprintf("component %q", name)) + if err != nil { + return component.Registration{}, err } return reg, nil } diff --git a/internal/runtime/internal/controller/loader_test.go b/internal/runtime/internal/controller/loader_test.go index 1947f864df..ca96f237b1 100644 --- a/internal/runtime/internal/controller/loader_test.go +++ b/internal/runtime/internal/controller/loader_test.go @@ -197,6 +197,14 @@ func TestLoader(t *testing.T) { require.NoError(t, diags.ErrorOrNil()) }) + t.Run("Load community component with community enabled and undefined stability level", func(t *testing.T) { + options := newLoaderOptionsWithStability(featuregate.StabilityUndefined) + options.ComponentGlobals.Community = true + l := controller.NewLoader(options) + diags := applyFromContent(t, l, []byte(testFileCommunity), nil, nil) + require.NoError(t, diags.ErrorOrNil()) + }) + t.Run("Load community component with community disabled", func(t *testing.T) { l := controller.NewLoader(newLoaderOptions()) diags := applyFromContent(t, l, []byte(testFileCommunity), nil, nil)