Provisioning: Add refs endpoint (#108014)

This commit is contained in:
Roberto Jiménez Sánchez
2025-07-11 13:58:39 -07:00
committed by GitHub
parent a33b634a9f
commit 05a2d26787
17 changed files with 727 additions and 0 deletions
@@ -1859,6 +1859,79 @@
}
]
},
"/apis/provisioning.grafana.app/v0alpha1/namespaces/{namespace}/repositories/{name}/refs": {
"get": {
"tags": [
"Repository"
],
"summary": "Repository refs listing",
"description": "Get the repository references",
"operationId": "getRepositoryRefs",
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"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": {
"default": {}
},
"x-kubernetes-list-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"
},
"metadata": {
"default": {}
}
}
}
}
}
}
},
"x-kubernetes-action": "connect",
"x-kubernetes-group-version-kind": {
"group": "provisioning.grafana.app",
"version": "v0alpha1",
"kind": "RefList"
}
},
"parameters": [
{
"name": "name",
"in": "path",
"description": "name of the RefList",
"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/provisioning.grafana.app/v0alpha1/namespaces/{namespace}/repositories/{name}/render/{guid}": {
"get": {
"tags": [
@@ -3037,6 +3110,70 @@
}
}
},
"com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1.RefItem": {
"type": "object",
"required": [
"name"
],
"properties": {
"hash": {
"description": "The SHA hash of the commit this ref points to",
"type": "string"
},
"name": {
"description": "The name of the reference (branch or tag)",
"type": "string",
"default": ""
},
"refURL": {
"description": "The URL to the reference (branch or tag)",
"type": "string"
}
}
},
"com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1.RefList": {
"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": {
"default": {},
"allOf": [
{
"$ref": "#/components/schemas/com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1.RefItem"
}
]
},
"x-kubernetes-list-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"
},
"metadata": {
"default": {},
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.ListMeta"
}
]
}
},
"x-kubernetes-group-version-kind": [
{
"group": "provisioning.grafana.app",
"kind": "RefList",
"version": "v0alpha1"
}
]
},
"com.github.grafana.grafana.pkg.apis.provisioning.v0alpha1.Repository": {
"description": "When this code is changed, make sure to update the code generation. As of writing, this can be done via the hack dir in the root of the repo: ./hack/update-codegen.sh provisioning If you've opened the generated files in this dir at some point in VSCode, you may also have to re-open them to clear errors.",
"type": "object",
@@ -83,6 +83,36 @@ func TestIntegrationProvisioning_CreatingAndGetting(t *testing.T) {
Suffix("files/").
Do(context.Background())
require.NoError(t, rsp.Error())
// Verify that we can list refs
rsp = helper.AdminREST.Get().
Namespace("default").
Resource("repositories").
Name(name).
Suffix("refs").
Do(context.Background())
if expectedRepo.Spec.Type == provisioning.LocalRepositoryType {
require.ErrorContains(t, rsp.Error(), "does not support versioned operations")
} else {
require.NoError(t, rsp.Error())
refs := &provisioning.RefList{}
err = rsp.Into(refs)
require.NoError(t, err)
require.True(t, len(refs.Items) >= 1, "should have at least one ref")
var foundBranch bool
for _, ref := range refs.Items {
// FIXME: this assertion should be improved for all git types and take things from config
if ref.Name == "integration-test" {
require.Equal(t, "0f3370c212b04b9704e00f6926ef339bf91c7a1b", ref.Hash)
require.Equal(t, "https://github.com/grafana/grafana-git-sync-demo/tree/integration-test", ref.RefURL)
foundBranch = true
}
}
require.True(t, foundBranch, "branch should be found")
}
})
}