Skip to content

Commit

Permalink
community components don't depend on the feature stability flag
Browse files Browse the repository at this point in the history
  • Loading branch information
wildum committed Jul 2, 2024
1 parent 64d1a49 commit 73bc387
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
8 changes: 6 additions & 2 deletions internal/component/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 19 additions & 8 deletions internal/runtime/internal/controller/component_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions internal/runtime/internal/controller/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 73bc387

Please sign in to comment.