POC/Provisioning: Use RepositoryViewList for /settings endpoing (#99978)

* frontend settings as list

* frontend settings as list

* remove weird comment

* remove metadata

* lint

* Add hooks back

---------

Co-authored-by: Clarity-89 <homes89@ukr.net>
This commit is contained in:
Ryan McKinleyandClarity-89 authored and GitHub committed 2025-02-04 07:53:11 +02:00
1 parent e995715bb9
commit ca3db84d99
10 files changed
+163 -172

No files matched your search

+5 -6
View File
@@ -6,18 +6,17 @@ import (
// Summary shows a view of the configuration that is sanitized and is OK for logged in users to see
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type Settings struct {
type RepositoryViewList struct {
metav1.TypeMeta `json:",inline"`
// When a repository is configured to save everything in instance
Instance string `json:"instance,omitempty"`
// The basic repository settings
// +mapType=atomic
Repository map[string]RepositoryView `json:"repository"`
Items []RepositoryView `json:"items"`
}
type RepositoryView struct {
// The k8s name for this repository
Name string `json:"name"`
// Repository display
Title string `json:"title"`
@@ -507,6 +507,36 @@ func (in *RepositoryView) DeepCopy() *RepositoryView {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *RepositoryViewList) DeepCopyInto(out *RepositoryViewList) {
*out = *in
out.TypeMeta = in.TypeMeta
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]RepositoryView, len(*in))
copy(*out, *in)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RepositoryViewList.
func (in *RepositoryViewList) DeepCopy() *RepositoryViewList {
if in == nil {
return nil
}
out := new(RepositoryViewList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *RepositoryViewList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ResourceCount) DeepCopyInto(out *ResourceCount) {
*out = *in
@@ -693,38 +723,6 @@ func (in *S3RepositoryConfig) DeepCopy() *S3RepositoryConfig {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Settings) DeepCopyInto(out *Settings) {
*out = *in
out.TypeMeta = in.TypeMeta
if in.Repository != nil {
in, out := &in.Repository, &out.Repository
*out = make(map[string]RepositoryView, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Settings.
func (in *Settings) DeepCopy() *Settings {
if in == nil {
return nil
}
out := new(Settings)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *Settings) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *SyncJobOptions) DeepCopyInto(out *SyncJobOptions) {
*out = *in
@@ -35,6 +35,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.RepositorySpec": schema_pkg_apis_provisioning_v0alpha1_RepositorySpec(ref),
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.RepositoryStatus": schema_pkg_apis_provisioning_v0alpha1_RepositoryStatus(ref),
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.RepositoryView": schema_pkg_apis_provisioning_v0alpha1_RepositoryView(ref),
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.RepositoryViewList": schema_pkg_apis_provisioning_v0alpha1_RepositoryViewList(ref),
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.ResourceCount": schema_pkg_apis_provisioning_v0alpha1_ResourceCount(ref),
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.ResourceList": schema_pkg_apis_provisioning_v0alpha1_ResourceList(ref),
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.ResourceListItem": schema_pkg_apis_provisioning_v0alpha1_ResourceListItem(ref),
@@ -43,7 +44,6 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.ResourceType": schema_pkg_apis_provisioning_v0alpha1_ResourceType(ref),
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.ResourceWrapper": schema_pkg_apis_provisioning_v0alpha1_ResourceWrapper(ref),
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.S3RepositoryConfig": schema_pkg_apis_provisioning_v0alpha1_S3RepositoryConfig(ref),
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.Settings": schema_pkg_apis_provisioning_v0alpha1_Settings(ref),
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.SyncJobOptions": schema_pkg_apis_provisioning_v0alpha1_SyncJobOptions(ref),
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.SyncOptions": schema_pkg_apis_provisioning_v0alpha1_SyncOptions(ref),
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.SyncStatus": schema_pkg_apis_provisioning_v0alpha1_SyncStatus(ref),
@@ -1071,6 +1071,14 @@ func schema_pkg_apis_provisioning_v0alpha1_RepositoryView(ref common.ReferenceCa
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
Properties: map[string]spec.Schema{
"name": {
SchemaProps: spec.SchemaProps{
Description: "The k8s name for this repository",
Default: "",
Type: []string{"string"},
Format: "",
},
},
"title": {
SchemaProps: spec.SchemaProps{
Description: "Repository display",
@@ -1106,12 +1114,60 @@ func schema_pkg_apis_provisioning_v0alpha1_RepositoryView(ref common.ReferenceCa
},
},
},
Required: []string{"title", "readOnly", "type", "target"},
Required: []string{"name", "title", "readOnly", "type", "target"},
},
},
}
}
func schema_pkg_apis_provisioning_v0alpha1_RepositoryViewList(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Description: "Summary shows a view of the configuration that is sanitized and is OK for logged in users to see",
Type: []string{"object"},
Properties: map[string]spec.Schema{
"kind": {
SchemaProps: spec.SchemaProps{
Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
Type: []string{"string"},
Format: "",
},
},
"apiVersion": {
SchemaProps: spec.SchemaProps{
Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
Type: []string{"string"},
Format: "",
},
},
"items": {
VendorExtensible: spec.VendorExtensible{
Extensions: spec.Extensions{
"x-kubernetes-map-type": "atomic",
},
},
SchemaProps: spec.SchemaProps{
Type: []string{"array"},
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Default: map[string]interface{}{},
Ref: ref("github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.RepositoryView"),
},
},
},
},
},
},
Required: []string{"items"},
},
},
Dependencies: []string{
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.RepositoryView"},
}
}
func schema_pkg_apis_provisioning_v0alpha1_ResourceCount(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
@@ -1544,63 +1600,6 @@ func schema_pkg_apis_provisioning_v0alpha1_S3RepositoryConfig(ref common.Referen
}
}
func schema_pkg_apis_provisioning_v0alpha1_Settings(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Description: "Summary shows a view of the configuration that is sanitized and is OK for logged in users to see",
Type: []string{"object"},
Properties: map[string]spec.Schema{
"kind": {
SchemaProps: spec.SchemaProps{
Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
Type: []string{"string"},
Format: "",
},
},
"apiVersion": {
SchemaProps: spec.SchemaProps{
Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
Type: []string{"string"},
Format: "",
},
},
"instance": {
SchemaProps: spec.SchemaProps{
Description: "When a repository is configured to save everything in instance",
Type: []string{"string"},
Format: "",
},
},
"repository": {
VendorExtensible: spec.VendorExtensible{
Extensions: spec.Extensions{
"x-kubernetes-map-type": "atomic",
},
},
SchemaProps: spec.SchemaProps{
Description: "The basic repository settings",
Type: []string{"object"},
AdditionalProperties: &spec.SchemaOrBool{
Allows: true,
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Default: map[string]interface{}{},
Ref: ref("github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.RepositoryView"),
},
},
},
},
},
},
Required: []string{"repository"},
},
},
Dependencies: []string{
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.RepositoryView"},
}
}
func schema_pkg_apis_provisioning_v0alpha1_SyncJobOptions(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
@@ -4,6 +4,7 @@ API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/provis
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1,JobStatus,Errors
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1,JobStatus,Summary
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1,RepositoryList,Items
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1,RepositoryViewList,Items
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1,ResourceList,Items
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1,ResourceStats,Items
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1,TestResults,Errors
@@ -65,6 +65,7 @@ func NewExporter(
}, nil
}
//nolint:gocyclo
func (r *exporter) Export(ctx context.Context,
repo repository.Repository,
options provisioning.ExportJobOptions,
+17 -19
View File
@@ -2,7 +2,6 @@ package provisioning
import (
"context"
"encoding/json"
"fmt"
"net/http"
"strings"
@@ -702,19 +701,11 @@ spec:
}
}
compBase := "com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1."
schema := oas.Components.Schemas[compBase+"Settings"].Properties["repository"]
schema.AdditionalProperties.Schema = &spec.Schema{
SchemaProps: spec.SchemaProps{
Ref: spec.MustCreateRef("#/components/schemas/" + compBase + "RepositoryView"),
},
}
oas.Components.Schemas[compBase+"Settings"].Properties["repository"] = schema
schema = oas.Components.Schemas[compBase+"ResourceStats"].Properties["items"]
schema := oas.Components.Schemas[compBase+"ResourceStats"].Properties["items"]
schema.Items = &spec.SchemaOrArray{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
AllOf: []spec.Schema{ // shows up for swagger + RTK :shrug:
AllOf: []spec.Schema{
{
SchemaProps: spec.SchemaProps{
Ref: spec.MustCreateRef("#/components/schemas/" + compBase + "ResourceCount"),
@@ -726,14 +717,21 @@ spec:
}
oas.Components.Schemas[compBase+"ResourceStats"].Properties["items"] = schema
jj, _ := json.MarshalIndent(oas.Components.Schemas[compBase+"ResourceStats"], "", " ")
fmt.Printf(">> %s\n", string(jj))
// "allOf": [
// {
// "$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1.ResourceCount"
// }
// ]
schema = oas.Components.Schemas[compBase+"RepositoryViewList"].Properties["items"]
schema.Items = &spec.SchemaOrArray{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
AllOf: []spec.Schema{
{
SchemaProps: spec.SchemaProps{
Ref: spec.MustCreateRef("#/components/schemas/" + compBase + "RepositoryView"),
},
},
},
},
},
}
oas.Components.Schemas[compBase+"RepositoryViewList"].Properties["items"] = schema
return oas, nil
}
+6 -8
View File
@@ -95,7 +95,7 @@ func (b *APIBuilder) GetAPIRoutes() *builder.APIRoutes {
MediaTypeProps: spec3.MediaTypeProps{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Ref: spec.MustCreateRef("#/components/schemas/com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1.Settings"),
Ref: spec.MustCreateRef("#/components/schemas/com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1.RepositoryViewList"),
},
},
},
@@ -145,19 +145,17 @@ func (b *APIBuilder) handleSettings(w http.ResponseWriter, r *http.Request) {
return
}
settings := provisioning.Settings{
Repository: make(map[string]provisioning.RepositoryView, len(all)+2),
settings := provisioning.RepositoryViewList{
Items: make([]provisioning.RepositoryView, len(all)),
}
for _, val := range all {
settings.Repository[val.Name] = provisioning.RepositoryView{
for i, val := range all {
settings.Items[i] = provisioning.RepositoryView{
Name: val.ObjectMeta.Name,
Title: val.Spec.Title,
Type: val.Spec.Type,
ReadOnly: val.Spec.ReadOnly,
Target: val.Spec.Sync.Target,
}
if val.Spec.Sync.Target == provisioning.SyncTargetTypeInstance {
settings.Instance = val.Name
}
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(settings)
@@ -2479,7 +2479,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1.Settings"
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1.RepositoryViewList"
}
}
}
@@ -3405,12 +3405,18 @@
"com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1.RepositoryView": {
"type": "object",
"required": [
"name",
"title",
"readOnly",
"type",
"target"
],
"properties": {
"name": {
"description": "The k8s name for this repository",
"type": "string",
"default": ""
},
"readOnly": {
"description": "Edit options within the repository",
"type": "boolean",
@@ -3442,6 +3448,34 @@
}
}
},
"com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1.RepositoryViewList": {
"description": "Summary shows a view of the configuration that is sanitized and is OK for logged in users to see",
"type": "object",
"required": [
"items"
],
"properties": {
"apiVersion": {
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
"type": "string"
},
"items": {
"type": "array",
"items": {
"allOf": [
{
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1.RepositoryView"
}
]
},
"x-kubernetes-map-type": "atomic"
},
"kind": {
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
"type": "string"
}
}
},
"com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1.ResourceCount": {
"type": "object",
"required": [
@@ -3753,35 +3787,6 @@
}
}
},
"com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1.Settings": {
"description": "Summary shows a view of the configuration that is sanitized and is OK for logged in users to see",
"type": "object",
"required": [
"repository"
],
"properties": {
"apiVersion": {
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
"type": "string"
},
"instance": {
"description": "When a repository is configured to save everything in instance",
"type": "string"
},
"kind": {
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
"type": "string"
},
"repository": {
"description": "The basic repository settings",
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1.RepositoryView"
},
"x-kubernetes-map-type": "atomic"
}
}
},
"com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1.SyncJobOptions": {
"type": "object",
"properties": {
@@ -234,11 +234,11 @@ const injectedRtkApi = api
invalidatesTags: ['Repository'],
}),
getFrontendSettings: build.query<GetFrontendSettingsResponse, GetFrontendSettingsArg>({
query: (queryArg) => ({ url: `/settings` }),
query: () => ({ url: `/settings` }),
providesTags: ['Provisioning'],
}),
getResourceStats: build.query<GetResourceStatsResponse, GetResourceStatsArg>({
query: (queryArg) => ({ url: `/stats` }),
query: () => ({ url: `/stats` }),
providesTags: ['Provisioning'],
}),
}),
@@ -550,16 +550,10 @@ export type CreateRepositoryWebhookArg = {
/** name of the WebhookResponse */
name: string;
};
export type GetFrontendSettingsResponse = /** status 200 undefined */ Settings;
export type GetFrontendSettingsArg = {
/** workspace */
namespace: string;
};
export type GetFrontendSettingsResponse = /** status 200 undefined */ RepositoryViewList;
export type GetFrontendSettingsArg = void;
export type GetResourceStatsResponse = /** status 200 undefined */ ResourceStats;
export type GetResourceStatsArg = {
/** workspace */
namespace: string;
};
export type GetResourceStatsArg = void;
export type Time = string;
export type FieldsV1 = object;
export type ManagedFieldsEntry = {
@@ -1045,6 +1039,8 @@ export type WebhookResponse = {
kind?: string;
};
export type RepositoryView = {
/** The k8s name for this repository */
name: string;
/** Edit options within the repository */
readOnly: boolean;
/** When syncing, where values are saved
@@ -1063,17 +1059,12 @@ export type RepositoryView = {
- `"s3"` */
type: 'github' | 'local' | 's3';
};
export type Settings = {
export type RepositoryViewList = {
/** APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources */
apiVersion?: string;
/** When a repository is configured to save everything in instance */
instance?: string;
items: RepositoryView[];
/** Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds */
kind?: string;
/** The basic repository settings */
repository: {
[key: string]: RepositoryView;
};
};
export type ResourceStats = {
/** APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources */
+1
View File
@@ -65,6 +65,7 @@ const config: ConfigFile = {
argSuffix: 'Arg',
responseSuffix: 'Response',
tag: true,
hooks: true,
},
},
};