K8s/Folders: Use v1beta1 and app-sdk based spec (#103975)

This commit is contained in:
Ryan McKinley
2025-04-14 23:20:10 +03:00
committed by GitHub
parent acfd998fa6
commit 0283c98e30
90 changed files with 1255 additions and 2407 deletions
+4 -4
View File
@@ -307,7 +307,7 @@ func TestService_OrgID(t *testing.T) {
desc: "should set org id from default namespace",
req: &authn.Request{HTTPRequest: &http.Request{
Header: map[string][]string{},
URL: mustParseURL("http://localhost/apis/folder.grafana.app/v1/namespaces/default/folders"),
URL: mustParseURL("http://localhost/apis/folder.grafana.app/v1beta1/namespaces/default/folders"),
}},
expectedOrgID: 1,
},
@@ -315,7 +315,7 @@ func TestService_OrgID(t *testing.T) {
desc: "should set org id from namespace",
req: &authn.Request{HTTPRequest: &http.Request{
Header: map[string][]string{},
URL: mustParseURL("http://localhost/apis/folder.grafana.app/v1/namespaces/org-2/folders"),
URL: mustParseURL("http://localhost/apis/folder.grafana.app/v1beta1/namespaces/org-2/folders"),
}},
expectedOrgID: 2,
},
@@ -323,7 +323,7 @@ func TestService_OrgID(t *testing.T) {
desc: "should set set org 1 for stack namespace",
req: &authn.Request{HTTPRequest: &http.Request{
Header: map[string][]string{},
URL: mustParseURL("http://localhost/apis/folder.grafana.app/v1/namespaces/stacks-100/folders"),
URL: mustParseURL("http://localhost/apis/folder.grafana.app/v1beta1/namespaces/stacks-100/folders"),
}},
stackID: 100,
expectedOrgID: 1,
@@ -332,7 +332,7 @@ func TestService_OrgID(t *testing.T) {
desc: "should error for wrong stack namespace",
req: &authn.Request{HTTPRequest: &http.Request{
Header: map[string][]string{},
URL: mustParseURL("http://localhost/apis/folder.grafana.app/v1/namespaces/stacks-100/folders"),
URL: mustParseURL("http://localhost/apis/folder.grafana.app/v1beta1/namespaces/stacks-100/folders"),
}},
stackID: 101,
expectedOrgID: 0,
@@ -4,15 +4,15 @@ import (
"context"
"fmt"
"github.com/grafana/authlib/types"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/pager"
"github.com/grafana/authlib/types"
folderv1 "github.com/grafana/grafana/apps/folder/pkg/apis/folder/v1beta1"
"github.com/grafana/grafana/pkg/apimachinery/utils"
folderv1 "github.com/grafana/grafana/pkg/apis/folder/v1"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/storage/legacysql"
"github.com/grafana/grafana/pkg/storage/unified/sql/sqltemplate"
+2 -2
View File
@@ -1,10 +1,10 @@
package common
import (
authzv1 "github.com/grafana/authlib/authz/proto/v1"
"google.golang.org/protobuf/types/known/structpb"
folders "github.com/grafana/grafana/pkg/apis/folder/v1"
authzv1 "github.com/grafana/authlib/authz/proto/v1"
folders "github.com/grafana/grafana/apps/folder/pkg/apis/folder/v1beta1"
iamalpha1 "github.com/grafana/grafana/pkg/apis/iam/v0alpha1"
authzextv1 "github.com/grafana/grafana/pkg/services/authz/proto/v1"
)
+1 -1
View File
@@ -2,7 +2,7 @@ package zanzana
import (
dashboards "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v1alpha1"
folders "github.com/grafana/grafana/pkg/apis/folder/v1"
folders "github.com/grafana/grafana/apps/folder/pkg/apis/folder/v1beta1"
)
const (
@@ -28,9 +28,9 @@ import (
"github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard"
dashboardv0 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v0alpha1"
dashboardv1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v1alpha1"
folderv1 "github.com/grafana/grafana/apps/folder/pkg/apis/folder/v1beta1"
"github.com/grafana/grafana/pkg/apimachinery/identity"
"github.com/grafana/grafana/pkg/apimachinery/utils"
folderv1 "github.com/grafana/grafana/pkg/apis/folder/v1"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/kvstore"
"github.com/grafana/grafana/pkg/infra/log"
@@ -18,7 +18,7 @@ func TestFolderConversions(t *testing.T) {
input := &unstructured.Unstructured{}
err := input.UnmarshalJSON([]byte(`{
"kind": "Folder",
"apiVersion": "folder.grafana.app/v1",
"apiVersion": "folder.grafana.app/v1beta1",
"metadata": {
"name": "be79sztagf20wd",
"namespace": "default",
@@ -86,10 +86,10 @@ func TestFolderConversions(t *testing.T) {
func TestFolderListConversions(t *testing.T) {
input := &unstructured.UnstructuredList{}
err := input.UnmarshalJSON([]byte(`{
"apiVersion": "folder.grafana.app/v1",
"apiVersion": "folder.grafana.app/v1beta1",
"items": [
{
"apiVersion": "folder.grafana.app/v1",
"apiVersion": "folder.grafana.app/v1beta1",
"kind": "Folder",
"metadata": {
"annotations": {
@@ -113,7 +113,7 @@ func TestFolderListConversions(t *testing.T) {
}
},
{
"apiVersion": "folder.grafana.app/v1",
"apiVersion": "folder.grafana.app/v1beta1",
"kind": "Folder",
"metadata": {
"annotations": {
@@ -135,7 +135,7 @@ func TestFolderListConversions(t *testing.T) {
}
},
{
"apiVersion": "folder.grafana.app/v1",
"apiVersion": "folder.grafana.app/v1beta1",
"kind": "Folder",
"metadata": {
"annotations": {
@@ -158,7 +158,7 @@ func TestFolderListConversions(t *testing.T) {
}
},
{
"apiVersion": "folder.grafana.app/v1",
"apiVersion": "folder.grafana.app/v1beta1",
"kind": "Folder",
"metadata": {
"annotations": {
@@ -180,7 +180,7 @@ func TestFolderListConversions(t *testing.T) {
}
},
{
"apiVersion": "folder.grafana.app/v1",
"apiVersion": "folder.grafana.app/v1beta1",
"kind": "Folder",
"metadata": {
"annotations": {
@@ -203,7 +203,7 @@ func TestFolderListConversions(t *testing.T) {
}
},
{
"apiVersion": "folder.grafana.app/v1",
"apiVersion": "folder.grafana.app/v1beta1",
"kind": "Folder",
"metadata": {
"annotations": {},
+1 -1
View File
@@ -19,8 +19,8 @@ import (
"github.com/grafana/dskit/concurrency"
dashboardv1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v1alpha1"
folderv1 "github.com/grafana/grafana/apps/folder/pkg/apis/folder/v1beta1"
"github.com/grafana/grafana/pkg/apimachinery/identity"
folderv1 "github.com/grafana/grafana/pkg/apis/folder/v1"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/events"
"github.com/grafana/grafana/pkg/infra/db"
@@ -14,9 +14,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
folderv1 "github.com/grafana/grafana/apps/folder/pkg/apis/folder/v1beta1"
"github.com/grafana/grafana/pkg/apimachinery/identity"
"github.com/grafana/grafana/pkg/apimachinery/utils"
folderv1 "github.com/grafana/grafana/pkg/apis/folder/v1"
"github.com/grafana/grafana/pkg/events"
"github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/infra/slugify"
@@ -15,9 +15,9 @@ import (
"k8s.io/apimachinery/pkg/selection"
clientrest "k8s.io/client-go/rest"
foldersv1 "github.com/grafana/grafana/apps/folder/pkg/apis/folder/v1beta1"
"github.com/grafana/grafana/pkg/apimachinery/identity"
"github.com/grafana/grafana/pkg/apimachinery/utils"
foldersv1 "github.com/grafana/grafana/pkg/apis/folder/v1"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/log/logtest"
@@ -82,11 +82,11 @@ func TestIntegrationFolderServiceViaUnifiedStorage(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("DELETE /apis/folder.grafana.app/v1/namespaces/default/folders/deletefolder", func(w http.ResponseWriter, req *http.Request) {
mux.HandleFunc("DELETE /apis/folder.grafana.app/v1beta1/namespaces/default/folders/deletefolder", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
})
mux.HandleFunc("GET /apis/folder.grafana.app/v1/namespaces/default/folders", func(w http.ResponseWriter, req *http.Request) {
mux.HandleFunc("GET /apis/folder.grafana.app/v1beta1/namespaces/default/folders", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
l := &foldersv1.FolderList{}
l.Kind = "Folder"
@@ -94,7 +94,7 @@ func TestIntegrationFolderServiceViaUnifiedStorage(t *testing.T) {
require.NoError(t, err)
})
mux.HandleFunc("GET /apis/folder.grafana.app/v1/namespaces/default/folders/foo", func(w http.ResponseWriter, req *http.Request) {
mux.HandleFunc("GET /apis/folder.grafana.app/v1beta1/namespaces/default/folders/foo", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
namespacer := func(_ int64) string { return "1" }
result, err := internalfolders.LegacyFolderToUnstructured(fooFolder, namespacer)
@@ -104,7 +104,7 @@ func TestIntegrationFolderServiceViaUnifiedStorage(t *testing.T) {
require.NoError(t, err)
})
mux.HandleFunc("GET /apis/folder.grafana.app/v1/namespaces/default/folders/updatefolder", func(w http.ResponseWriter, req *http.Request) {
mux.HandleFunc("GET /apis/folder.grafana.app/v1beta1/namespaces/default/folders/updatefolder", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
namespacer := func(_ int64) string { return "1" }
result, err := internalfolders.LegacyFolderToUnstructured(updateFolder, namespacer)
@@ -114,7 +114,7 @@ func TestIntegrationFolderServiceViaUnifiedStorage(t *testing.T) {
require.NoError(t, err)
})
mux.HandleFunc("PUT /apis/folder.grafana.app/v1/namespaces/default/folders/updatefolder", func(w http.ResponseWriter, req *http.Request) {
mux.HandleFunc("PUT /apis/folder.grafana.app/v1beta1/namespaces/default/folders/updatefolder", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
buf, err := io.ReadAll(req.Body)
require.NoError(t, err)
@@ -133,17 +133,17 @@ func TestIntegrationFolderServiceViaUnifiedStorage(t *testing.T) {
require.NoError(t, err)
})
mux.HandleFunc("GET /apis/folder.grafana.app/v1/namespaces/default/folders/ady4yobv315a8e", func(w http.ResponseWriter, req *http.Request) {
mux.HandleFunc("GET /apis/folder.grafana.app/v1beta1/namespaces/default/folders/ady4yobv315a8e", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(w).Encode(unifiedStorageFolder)
require.NoError(t, err)
})
mux.HandleFunc("PUT /apis/folder.grafana.app/v1/namespaces/default/folders/ady4yobv315a8e", func(w http.ResponseWriter, req *http.Request) {
mux.HandleFunc("PUT /apis/folder.grafana.app/v1beta1/namespaces/default/folders/ady4yobv315a8e", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(w).Encode(unifiedStorageFolder)
require.NoError(t, err)
})
mux.HandleFunc("POST /apis/folder.grafana.app/v1/namespaces/default/folders", func(w http.ResponseWriter, req *http.Request) {
mux.HandleFunc("POST /apis/folder.grafana.app/v1beta1/namespaces/default/folders", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
buf, err := io.ReadAll(req.Body)
require.NoError(t, err)
@@ -16,7 +16,7 @@ import (
"github.com/grafana/grafana/pkg/apimachinery/utils"
"github.com/grafana/grafana/pkg/storage/unified/resource"
folderv1 "github.com/grafana/grafana/pkg/apis/folder/v1"
folderv1 "github.com/grafana/grafana/apps/folder/pkg/apis/folder/v1beta1"
"github.com/grafana/grafana/pkg/infra/log"
internalfolders "github.com/grafana/grafana/pkg/registry/apis/folders"
"github.com/grafana/grafana/pkg/services/accesscontrol"