ShortURL: Implement /goto with a sub-resource (#110972)
This commit is contained in:
@@ -865,6 +865,55 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"/apis/shorturl.grafana.app/v1alpha1/namespaces/{namespace}/shorturls/{name}/goto": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"ShortURL"
|
||||
],
|
||||
"description": "connect GET requests to goto of ShortURL",
|
||||
"operationId": "getShortURLGoto",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"*/*": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/com.github.grafana.grafana.apps.shorturl.pkg.apis.shorturl.v1alpha1.GetGoto"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"x-kubernetes-action": "connect",
|
||||
"x-kubernetes-group-version-kind": {
|
||||
"group": "shorturl.grafana.app",
|
||||
"version": "v1alpha1",
|
||||
"kind": "ResourceCallOptions"
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "name",
|
||||
"in": "path",
|
||||
"description": "name of the ResourceCallOptions",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "namespace",
|
||||
"in": "path",
|
||||
"description": "object name and auth scope, such as for teams and projects",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"uniqueItems": true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"/apis/shorturl.grafana.app/v1alpha1/namespaces/{namespace}/shorturls/{name}/status": {
|
||||
"get": {
|
||||
"tags": [
|
||||
@@ -1158,6 +1207,17 @@
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"com.github.grafana.grafana.apps.shorturl.pkg.apis.shorturl.v1alpha1.GetGoto": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"url"
|
||||
],
|
||||
"properties": {
|
||||
"url": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"com.github.grafana.grafana.apps.shorturl.pkg.apis.shorturl.v1alpha1.ShortURL": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -6,9 +6,7 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/shorturls"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
@@ -17,6 +15,8 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
grafanarest "github.com/grafana/grafana/pkg/apiserver/rest"
|
||||
"github.com/grafana/grafana/pkg/services/apiserver/options"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/shorturls"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/tests/apis"
|
||||
"github.com/grafana/grafana/pkg/tests/testinfra"
|
||||
@@ -68,7 +68,7 @@ func TestIntegrationShortURL(t *testing.T) {
|
||||
AppModeProduction: false, // required for unified storage
|
||||
DisableAnonymous: true,
|
||||
APIServerStorageType: options.StorageTypeUnified,
|
||||
EnableFeatureToggles: []string{"kubernetesShortURLs"},
|
||||
EnableFeatureToggles: []string{featuremgmt.FlagKubernetesShortURLs},
|
||||
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
|
||||
RESOURCEGROUP: {
|
||||
DualWriterMode: grafanarest.Mode0,
|
||||
@@ -78,60 +78,38 @@ func TestIntegrationShortURL(t *testing.T) {
|
||||
doLegacyOnlyTests(t, helper)
|
||||
})
|
||||
|
||||
t.Run("with dual write (unified storage, mode 1)", func(t *testing.T) {
|
||||
mode := grafanarest.Mode1
|
||||
helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
|
||||
AppModeProduction: false,
|
||||
DisableAnonymous: true,
|
||||
APIServerStorageType: options.StorageTypeUnified,
|
||||
EnableFeatureToggles: []string{"kubernetesShortURLs"},
|
||||
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
|
||||
RESOURCEGROUP: {
|
||||
DualWriterMode: mode,
|
||||
for _, mode := range []grafanarest.DualWriterMode{
|
||||
grafanarest.Mode1,
|
||||
grafanarest.Mode2,
|
||||
// grafanarest.Mode3, TODO: the /goto function needs to use an UpdateStatus client
|
||||
// grafanarest.Mode4,
|
||||
} {
|
||||
t.Run(fmt.Sprintf("with dual write (unified storage, mode %d)", mode), func(t *testing.T) {
|
||||
helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
|
||||
AppModeProduction: false,
|
||||
DisableAnonymous: true,
|
||||
APIServerStorageType: options.StorageTypeUnified,
|
||||
EnableFeatureToggles: []string{
|
||||
featuremgmt.FlagKubernetesShortURLs,
|
||||
},
|
||||
},
|
||||
})
|
||||
doDualWriteTests(t, helper, mode)
|
||||
})
|
||||
|
||||
t.Run("with dual write (unified storage, mode 2)", func(t *testing.T) {
|
||||
mode := grafanarest.Mode2
|
||||
helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
|
||||
AppModeProduction: false,
|
||||
DisableAnonymous: true,
|
||||
APIServerStorageType: options.StorageTypeUnified,
|
||||
EnableFeatureToggles: []string{"kubernetesShortURLs"},
|
||||
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
|
||||
RESOURCEGROUP: {
|
||||
DualWriterMode: mode,
|
||||
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
|
||||
RESOURCEGROUP: {
|
||||
DualWriterMode: mode,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
doDualWriteTests(t, helper, mode)
|
||||
})
|
||||
doDualWriteTests(t, helper, mode)
|
||||
})
|
||||
|
||||
t.Run("with dual write (unified storage, mode 3)", func(t *testing.T) {
|
||||
mode := grafanarest.Mode3
|
||||
helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
|
||||
AppModeProduction: false,
|
||||
DisableAnonymous: true,
|
||||
APIServerStorageType: options.StorageTypeUnified,
|
||||
EnableFeatureToggles: []string{"kubernetesShortURLs"},
|
||||
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
|
||||
RESOURCEGROUP: {
|
||||
DualWriterMode: mode,
|
||||
},
|
||||
},
|
||||
})
|
||||
doDualWriteTests(t, helper, mode)
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("with dual write (unified storage, mode 5)", func(t *testing.T) {
|
||||
helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
|
||||
AppModeProduction: false,
|
||||
DisableAnonymous: true,
|
||||
APIServerStorageType: options.StorageTypeUnified,
|
||||
EnableFeatureToggles: []string{"kubernetesShortURLs"},
|
||||
EnableFeatureToggles: []string{
|
||||
featuremgmt.FlagKubernetesShortURLs,
|
||||
},
|
||||
UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{
|
||||
RESOURCEGROUP: {
|
||||
DualWriterMode: grafanarest.Mode5,
|
||||
|
||||
Reference in New Issue
Block a user