diff --git a/pkg/registry/apis/dashboard/register.go b/pkg/registry/apis/dashboard/register.go index cb97e15aa22..0d15aa5a439 100644 --- a/pkg/registry/apis/dashboard/register.go +++ b/pkg/registry/apis/dashboard/register.go @@ -22,6 +22,14 @@ var ( _ builder.OpenAPIPostProcessor = (*DashboardsAPIBuilder)(nil) ) +func FeatureEnabled(features featuremgmt.FeatureToggles) bool { + return featuremgmt.AnyEnabled(features, + featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs, + featuremgmt.FlagKubernetesDashboardsAPI, + featuremgmt.FlagKubernetesDashboards, // << the UI will call the new apis + featuremgmt.FlagProvisioning) +} + // This is used just so wire has something unique to return type DashboardsAPIBuilder struct{} @@ -29,7 +37,7 @@ func RegisterAPIService( features featuremgmt.FeatureToggles, apiregistration builder.APIRegistrar, ) *DashboardsAPIBuilder { - if !features.IsEnabledGlobally(featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs) && !features.IsEnabledGlobally(featuremgmt.FlagKubernetesDashboardsAPI) { + if !FeatureEnabled(features) { return nil // skip registration unless opting into experimental apis or dashboards in the k8s api } builder := &DashboardsAPIBuilder{} diff --git a/pkg/registry/apis/dashboard/v0alpha1/register.go b/pkg/registry/apis/dashboard/v0alpha1/register.go index 164b4eeac45..79570ae76fb 100644 --- a/pkg/registry/apis/dashboard/v0alpha1/register.go +++ b/pkg/registry/apis/dashboard/v0alpha1/register.go @@ -63,7 +63,7 @@ func RegisterAPIService(cfg *setting.Cfg, features featuremgmt.FeatureToggles, tracing *tracing.TracingService, unified resource.ResourceClient, ) *DashboardsAPIBuilder { - if !features.IsEnabledGlobally(featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs) && !features.IsEnabledGlobally(featuremgmt.FlagKubernetesDashboardsAPI) { + if !dashboard.FeatureEnabled(features) { return nil // skip registration unless opting into experimental apis or dashboards in the k8s api } diff --git a/pkg/registry/apis/dashboard/v1alpha1/register.go b/pkg/registry/apis/dashboard/v1alpha1/register.go index 0744ba56573..5023cee667a 100644 --- a/pkg/registry/apis/dashboard/v1alpha1/register.go +++ b/pkg/registry/apis/dashboard/v1alpha1/register.go @@ -59,7 +59,7 @@ func RegisterAPIService(cfg *setting.Cfg, features featuremgmt.FeatureToggles, tracing *tracing.TracingService, unified resource.ResourceClient, ) *DashboardsAPIBuilder { - if !features.IsEnabledGlobally(featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs) && !features.IsEnabledGlobally(featuremgmt.FlagKubernetesDashboardsAPI) { + if !dashboard.FeatureEnabled(features) { return nil // skip registration unless opting into experimental apis or dashboards in the k8s api } diff --git a/pkg/registry/apis/dashboard/v2alpha1/register.go b/pkg/registry/apis/dashboard/v2alpha1/register.go index 0484201f79c..4c0b8378138 100644 --- a/pkg/registry/apis/dashboard/v2alpha1/register.go +++ b/pkg/registry/apis/dashboard/v2alpha1/register.go @@ -59,7 +59,7 @@ func RegisterAPIService(cfg *setting.Cfg, features featuremgmt.FeatureToggles, tracing *tracing.TracingService, unified resource.ResourceClient, ) *DashboardsAPIBuilder { - if !features.IsEnabledGlobally(featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs) && !features.IsEnabledGlobally(featuremgmt.FlagKubernetesDashboardsAPI) { + if !dashboard.FeatureEnabled(features) { return nil // skip registration unless opting into experimental apis or dashboards in the k8s api } diff --git a/pkg/registry/apis/folders/register.go b/pkg/registry/apis/folders/register.go index 0da47483355..7b8628ef9a1 100644 --- a/pkg/registry/apis/folders/register.go +++ b/pkg/registry/apis/folders/register.go @@ -5,7 +5,6 @@ import ( "errors" "slices" - grafanarest "github.com/grafana/grafana/pkg/apiserver/rest" "github.com/prometheus/client_golang/prometheus" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -17,6 +16,8 @@ import ( common "k8s.io/kube-openapi/pkg/common" "k8s.io/kube-openapi/pkg/spec3" + grafanarest "github.com/grafana/grafana/pkg/apiserver/rest" + "github.com/grafana/grafana/pkg/apimachinery/identity" "github.com/grafana/grafana/pkg/apimachinery/utils" "github.com/grafana/grafana/pkg/apis/folder/v0alpha1" @@ -55,8 +56,11 @@ func RegisterAPIService(cfg *setting.Cfg, accessControl accesscontrol.AccessControl, registerer prometheus.Registerer, ) *FolderAPIBuilder { - if !features.IsEnabledGlobally(featuremgmt.FlagKubernetesFolders) && !features.IsEnabledGlobally(featuremgmt.FlagGrafanaAPIServerTestingWithExperimentalAPIs) { - return nil // skip registration unless opting into Kubernetes folders or unless we want to customise registration when testing + if !featuremgmt.AnyEnabled(features, + featuremgmt.FlagKubernetesFolders, + featuremgmt.FlagGrafanaAPIServerTestingWithExperimentalAPIs, + featuremgmt.FlagProvisioning) { + return nil // skip registration unless opting into Kubernetes folders or unless we want to customize registration when testing } builder := &FolderAPIBuilder{ diff --git a/pkg/registry/apis/peakq/register.go b/pkg/registry/apis/peakq/register.go index 54306e85daa..d77305389a8 100644 --- a/pkg/registry/apis/peakq/register.go +++ b/pkg/registry/apis/peakq/register.go @@ -28,8 +28,10 @@ func NewPeakQAPIBuilder() *PeakQAPIBuilder { } func RegisterAPIService(features featuremgmt.FeatureToggles, apiregistration builder.APIRegistrar, reg prometheus.Registerer) *PeakQAPIBuilder { - if !((features.IsEnabledGlobally(featuremgmt.FlagQueryService) && features.IsEnabledGlobally(featuremgmt.FlagQueryLibrary)) || - features.IsEnabledGlobally(featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs)) { + if !featuremgmt.AnyEnabled(features, + featuremgmt.FlagQueryService, + featuremgmt.FlagQueryLibrary, + featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs) { return nil // skip registration unless explicitly added (or all experimental are added) } builder := NewPeakQAPIBuilder() diff --git a/pkg/registry/apis/scope/register.go b/pkg/registry/apis/scope/register.go index afe6eca4cfd..733f966aebf 100644 --- a/pkg/registry/apis/scope/register.go +++ b/pkg/registry/apis/scope/register.go @@ -3,6 +3,7 @@ package scope import ( "fmt" + "github.com/prometheus/client_golang/prometheus" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apiserver/pkg/authorization/authorizer" @@ -12,8 +13,6 @@ import ( "k8s.io/kube-openapi/pkg/spec3" "k8s.io/kube-openapi/pkg/validation/spec" - "github.com/prometheus/client_golang/prometheus" - scope "github.com/grafana/grafana/pkg/apis/scope/v0alpha1" "github.com/grafana/grafana/pkg/services/apiserver/builder" "github.com/grafana/grafana/pkg/services/featuremgmt" @@ -29,8 +28,9 @@ func NewScopeAPIBuilder() *ScopeAPIBuilder { } func RegisterAPIService(features featuremgmt.FeatureToggles, apiregistration builder.APIRegistrar, reg prometheus.Registerer) *ScopeAPIBuilder { - if !(features.IsEnabledGlobally(featuremgmt.FlagScopeApi) || - features.IsEnabledGlobally(featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs)) { + if !featuremgmt.AnyEnabled(features, + featuremgmt.FlagScopeApi, + featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs) { return nil // skip registration unless opting into experimental apis } builder := NewScopeAPIBuilder() diff --git a/pkg/services/featuremgmt/models.go b/pkg/services/featuremgmt/models.go index 6260547585b..018cb6046e6 100644 --- a/pkg/services/featuremgmt/models.go +++ b/pkg/services/featuremgmt/models.go @@ -23,6 +23,15 @@ type FeatureToggles interface { GetEnabled(ctx context.Context) map[string]bool } +func AnyEnabled(f FeatureToggles, flags ...string) bool { + for _, flag := range flags { + if f.IsEnabledGlobally(flag) { + return true + } + } + return false +} + // FeatureFlagStage indicates the quality level type FeatureFlagStage int