mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Remove the need for plugins to implement AdmissionHandler for v0alpha1 (#93272)
This commit is contained in:
parent
d60a28b3c8
commit
01a4e6b9af
@ -66,8 +66,6 @@ func RegisterAPIService(
|
||||
var err error
|
||||
var builder *DataSourceAPIBuilder
|
||||
all := pluginStore.Plugins(context.Background(), plugins.TypeDataSource)
|
||||
// ATTENTION: Adding a datasource here requires the plugin to implement
|
||||
// an AdmissionHandler to validate the datasource settings.
|
||||
ids := []string{
|
||||
"grafana-testdata-datasource",
|
||||
"prometheus",
|
||||
|
@ -367,6 +367,10 @@ func (s *Service) prepareInstanceSettings(ctx context.Context, settings *backend
|
||||
rsp, err := s.pluginClient.ValidateAdmission(ctx, req)
|
||||
if err != nil {
|
||||
if errors.Is(err, plugins.ErrMethodNotImplemented) {
|
||||
if settings.APIVersion == "v0alpha1" {
|
||||
// For v0alpha1 we don't require plugins to implement ValidateAdmission
|
||||
return settings, nil
|
||||
}
|
||||
return nil, errutil.Internal("plugin.unimplemented").
|
||||
Errorf("plugin (%s) with apiVersion=%s must implement ValidateAdmission", p.ID, settings.APIVersion)
|
||||
}
|
||||
@ -388,6 +392,10 @@ func (s *Service) prepareInstanceSettings(ctx context.Context, settings *backend
|
||||
rsp, err := s.pluginClient.MutateAdmission(ctx, req)
|
||||
if err != nil {
|
||||
if errors.Is(err, plugins.ErrMethodNotImplemented) {
|
||||
if settings.APIVersion == "v0alpha1" {
|
||||
// For v0alpha1 we don't require plugins to implement MutateAdmission
|
||||
return settings, nil
|
||||
}
|
||||
return nil, errutil.Internal("plugin.unimplemented").
|
||||
Errorf("plugin (%s) with apiVersion=%s must implement MutateAdmission", p.ID, settings.APIVersion)
|
||||
}
|
||||
|
@ -135,13 +135,35 @@ func TestService_AddDataSource(t *testing.T) {
|
||||
OrgID: 1,
|
||||
Type: "test", // required to validate apiserver
|
||||
Name: "test",
|
||||
APIVersion: "v0alpha1",
|
||||
APIVersion: "v1",
|
||||
}
|
||||
_, err := dsService.AddDataSource(context.Background(), cmd)
|
||||
require.NoError(t, err)
|
||||
require.True(t, validateExecuted)
|
||||
})
|
||||
|
||||
t.Run("should ignore if AdmissionHandler is not implemented for v0alpha1", func(t *testing.T) {
|
||||
dsService := initDSService(t)
|
||||
dsService.pluginStore = &pluginstore.FakePluginStore{
|
||||
PluginList: []pluginstore.Plugin{{
|
||||
JSONData: plugins.JSONData{
|
||||
ID: "test",
|
||||
Type: plugins.TypeDataSource,
|
||||
Name: "test",
|
||||
},
|
||||
}},
|
||||
}
|
||||
dsService.pluginClient = &pluginfakes.FakePluginClient{}
|
||||
cmd := &datasources.AddDataSourceCommand{
|
||||
OrgID: 1,
|
||||
Type: "test", // required to validate apiserver
|
||||
Name: "test",
|
||||
APIVersion: "v0alpha1",
|
||||
}
|
||||
_, err := dsService.AddDataSource(context.Background(), cmd)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("should fail at validation", func(t *testing.T) {
|
||||
dsService := initDSService(t)
|
||||
dsService.pluginStore = &pluginstore.FakePluginStore{
|
||||
|
Loading…
Reference in New Issue
Block a user