Provisioning: Add pure git repository type (#106815)
* Add repository type git to spec * Register git type * Update test checks
This commit is contained in:
@@ -41,6 +41,8 @@ var RepositoryResourceInfo = utils.NewResourceInfo(GROUP, VERSION,
|
||||
target = m.Spec.Local.Path
|
||||
case GitHubRepositoryType:
|
||||
target = m.Spec.GitHub.URL
|
||||
case GitRepositoryType:
|
||||
target = m.Spec.Git.URL
|
||||
}
|
||||
|
||||
return []interface{}{
|
||||
|
||||
@@ -59,6 +59,24 @@ type GitHubRepositoryConfig struct {
|
||||
Path string `json:"path,omitempty"`
|
||||
}
|
||||
|
||||
type GitRepositoryConfig struct {
|
||||
// The repository URL (e.g. `https://github.com/example/test.git`).
|
||||
URL string `json:"url,omitempty"`
|
||||
// The branch to use in the repository.
|
||||
Branch string `json:"branch"`
|
||||
// Token for accessing the repository. If set, it will be encrypted into encryptedToken, then set to an empty string again.
|
||||
Token string `json:"token,omitempty"`
|
||||
// Token for accessing the repository, but encrypted. This is not possible to read back to a user decrypted.
|
||||
// +listType=atomic
|
||||
EncryptedToken []byte `json:"encryptedToken,omitempty"`
|
||||
// Path is the subdirectory for the Grafana data. If specified, Grafana will ignore anything that is outside this directory in the repository.
|
||||
// This is usually something like `grafana/`. Trailing and leading slash are not required. They are always added when needed.
|
||||
// The path is relative to the root of the repository, regardless of the leading slash.
|
||||
//
|
||||
// When specifying something like `grafana-`, we will not look for `grafana-*`; we will only look for files under the directory `/grafana-/`. That means `/grafana-example.json` would not be found.
|
||||
Path string `json:"path,omitempty"`
|
||||
}
|
||||
|
||||
// RepositoryType defines the types of Repository
|
||||
// +enum
|
||||
type RepositoryType string
|
||||
@@ -67,8 +85,14 @@ type RepositoryType string
|
||||
const (
|
||||
LocalRepositoryType RepositoryType = "local"
|
||||
GitHubRepositoryType RepositoryType = "github"
|
||||
GitRepositoryType RepositoryType = "git"
|
||||
)
|
||||
|
||||
// IsGit returns true if the repository type is git or github
|
||||
func (r RepositoryType) IsGit() bool {
|
||||
return r == GitRepositoryType || r == GitHubRepositoryType
|
||||
}
|
||||
|
||||
type RepositorySpec struct {
|
||||
// The repository display name (shown in the UI)
|
||||
Title string `json:"title"`
|
||||
@@ -92,9 +116,12 @@ type RepositorySpec struct {
|
||||
Local *LocalRepositoryConfig `json:"local,omitempty"`
|
||||
|
||||
// The repository on GitHub.
|
||||
// Mutually exclusive with local | github.
|
||||
// TODO: github or just 'git'??
|
||||
// Mutually exclusive with local | github | git.
|
||||
GitHub *GitHubRepositoryConfig `json:"github,omitempty"`
|
||||
|
||||
// The repository on Git.
|
||||
// Mutually exclusive with local | github | git.
|
||||
Git *GitRepositoryConfig `json:"git,omitempty"`
|
||||
}
|
||||
|
||||
// SyncTargetType defines where we want all values to resolve
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package v0alpha1_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1"
|
||||
)
|
||||
|
||||
func TestRepositoryType_IsGit(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
repoType v0alpha1.RepositoryType
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "git",
|
||||
repoType: v0alpha1.GitRepositoryType,
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "github",
|
||||
repoType: v0alpha1.GitHubRepositoryType,
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "local",
|
||||
repoType: v0alpha1.LocalRepositoryType,
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := tt.repoType.IsGit()
|
||||
if got != tt.want {
|
||||
t.Errorf("IsGit() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -127,6 +127,27 @@ func (in *GitHubRepositoryConfig) DeepCopy() *GitHubRepositoryConfig {
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *GitRepositoryConfig) DeepCopyInto(out *GitRepositoryConfig) {
|
||||
*out = *in
|
||||
if in.EncryptedToken != nil {
|
||||
in, out := &in.EncryptedToken, &out.EncryptedToken
|
||||
*out = make([]byte, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitRepositoryConfig.
|
||||
func (in *GitRepositoryConfig) DeepCopy() *GitRepositoryConfig {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(GitRepositoryConfig)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *HealthStatus) DeepCopyInto(out *HealthStatus) {
|
||||
*out = *in
|
||||
@@ -501,6 +522,11 @@ func (in *RepositorySpec) DeepCopyInto(out *RepositorySpec) {
|
||||
*out = new(GitHubRepositoryConfig)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
if in.Git != nil {
|
||||
in, out := &in.Git, &out.Git
|
||||
*out = new(GitRepositoryConfig)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA
|
||||
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.FileItem": schema_pkg_apis_provisioning_v0alpha1_FileItem(ref),
|
||||
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.FileList": schema_pkg_apis_provisioning_v0alpha1_FileList(ref),
|
||||
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.GitHubRepositoryConfig": schema_pkg_apis_provisioning_v0alpha1_GitHubRepositoryConfig(ref),
|
||||
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.GitRepositoryConfig": schema_pkg_apis_provisioning_v0alpha1_GitRepositoryConfig(ref),
|
||||
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.HealthStatus": schema_pkg_apis_provisioning_v0alpha1_HealthStatus(ref),
|
||||
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.HistoryItem": schema_pkg_apis_provisioning_v0alpha1_HistoryItem(ref),
|
||||
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.HistoryList": schema_pkg_apis_provisioning_v0alpha1_HistoryList(ref),
|
||||
@@ -313,6 +314,60 @@ func schema_pkg_apis_provisioning_v0alpha1_GitHubRepositoryConfig(ref common.Ref
|
||||
}
|
||||
}
|
||||
|
||||
func schema_pkg_apis_provisioning_v0alpha1_GitRepositoryConfig(ref common.ReferenceCallback) common.OpenAPIDefinition {
|
||||
return common.OpenAPIDefinition{
|
||||
Schema: spec.Schema{
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Type: []string{"object"},
|
||||
Properties: map[string]spec.Schema{
|
||||
"url": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "The repository URL (e.g. `https://github.com/example/test.git`).",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
"branch": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "The branch to use in the repository.",
|
||||
Default: "",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
"token": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "Token for accessing the repository. If set, it will be encrypted into encryptedToken, then set to an empty string again.",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
"encryptedToken": {
|
||||
VendorExtensible: spec.VendorExtensible{
|
||||
Extensions: spec.Extensions{
|
||||
"x-kubernetes-list-type": "atomic",
|
||||
},
|
||||
},
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "Token for accessing the repository, but encrypted. This is not possible to read back to a user decrypted.",
|
||||
Type: []string{"string"},
|
||||
Format: "byte",
|
||||
},
|
||||
},
|
||||
"path": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "Path is the subdirectory for the Grafana data. If specified, Grafana will ignore anything that is outside this directory in the repository. This is usually something like `grafana/`. Trailing and leading slash are not required. They are always added when needed. The path is relative to the root of the repository, regardless of the leading slash.\n\nWhen specifying something like `grafana-`, we will not look for `grafana-*`; we will only look for files under the directory `/grafana-/`. That means `/grafana-example.json` would not be found.",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
Required: []string{"branch"},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func schema_pkg_apis_provisioning_v0alpha1_HealthStatus(ref common.ReferenceCallback) common.OpenAPIDefinition {
|
||||
return common.OpenAPIDefinition{
|
||||
Schema: spec.Schema{
|
||||
@@ -1041,11 +1096,11 @@ func schema_pkg_apis_provisioning_v0alpha1_RepositorySpec(ref common.ReferenceCa
|
||||
},
|
||||
"type": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "The repository type. When selected oneOf the values below should be non-nil\n\nPossible enum values:\n - `\"github\"`\n - `\"local\"`",
|
||||
Description: "The repository type. When selected oneOf the values below should be non-nil\n\nPossible enum values:\n - `\"git\"`\n - `\"github\"`\n - `\"local\"`",
|
||||
Default: "",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
Enum: []interface{}{"github", "local"},
|
||||
Enum: []interface{}{"git", "github", "local"},
|
||||
},
|
||||
},
|
||||
"local": {
|
||||
@@ -1056,16 +1111,22 @@ func schema_pkg_apis_provisioning_v0alpha1_RepositorySpec(ref common.ReferenceCa
|
||||
},
|
||||
"github": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "The repository on GitHub. Mutually exclusive with local | github.",
|
||||
Description: "The repository on GitHub. Mutually exclusive with local | github | git.",
|
||||
Ref: ref("github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.GitHubRepositoryConfig"),
|
||||
},
|
||||
},
|
||||
"git": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "The repository on Git. Mutually exclusive with local | github | git.",
|
||||
Ref: ref("github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.GitRepositoryConfig"),
|
||||
},
|
||||
},
|
||||
},
|
||||
Required: []string{"title", "workflows", "sync", "type"},
|
||||
},
|
||||
},
|
||||
Dependencies: []string{
|
||||
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.GitHubRepositoryConfig", "github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.LocalRepositoryConfig", "github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.SyncOptions"},
|
||||
"github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.GitHubRepositoryConfig", "github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.GitRepositoryConfig", "github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.LocalRepositoryConfig", "github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1.SyncOptions"},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1156,11 +1217,11 @@ func schema_pkg_apis_provisioning_v0alpha1_RepositoryView(ref common.ReferenceCa
|
||||
},
|
||||
"type": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "The repository type\n\nPossible enum values:\n - `\"github\"`\n - `\"local\"`",
|
||||
Description: "The repository type\n\nPossible enum values:\n - `\"git\"`\n - `\"github\"`\n - `\"local\"`",
|
||||
Default: "",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
Enum: []interface{}{"github", "local"},
|
||||
Enum: []interface{}{"git", "github", "local"},
|
||||
},
|
||||
},
|
||||
"target": {
|
||||
@@ -1474,11 +1535,11 @@ func schema_pkg_apis_provisioning_v0alpha1_ResourceRepositoryInfo(ref common.Ref
|
||||
Properties: map[string]spec.Schema{
|
||||
"type": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "The repository type\n\nPossible enum values:\n - `\"github\"`\n - `\"local\"`",
|
||||
Description: "The repository type\n\nPossible enum values:\n - `\"git\"`\n - `\"github\"`\n - `\"local\"`",
|
||||
Default: "",
|
||||
Type: []string{"string"},
|
||||
Format: "",
|
||||
Enum: []interface{}{"github", "local"},
|
||||
Enum: []interface{}{"git", "github", "local"},
|
||||
},
|
||||
},
|
||||
"title": {
|
||||
|
||||
Reference in New Issue
Block a user