Skip to content

Commit

Permalink
ProvisionedDatasourceXRD (#5)
Browse files Browse the repository at this point in the history
* adding scheme support for folder and dashboard v1beta1 apis

* refactored folder structure to combine types of the same groupName

* DataSource types

* define ProvisionedDataSource kinds

* make accessMode optional, align composition and endorced composition

* Type -> type

* I cannot type

* Update pkg/apis/grafana/v1beta1/datasource.go

Co-authored-by: David Katz <[email protected]>

* Update pkg/apis/grafana/v1beta1/datasource.go

Co-authored-by: David Katz <[email protected]>

* add deepcopy for spec provisioneddatasourcespec types

* Update config/composition.yaml

Co-authored-by: Yuzhou Liu <[email protected]>

* remove terraform fields

---------

Co-authored-by: David Katz <[email protected]>
Co-authored-by: David Katz <[email protected]>
Co-authored-by: Yuzhou Liu <[email protected]>
  • Loading branch information
4 people authored Jun 23, 2023
1 parent 5e25a3f commit c1c9718
Show file tree
Hide file tree
Showing 5 changed files with 309 additions and 0 deletions.
61 changes: 61 additions & 0 deletions config/composition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,64 @@ spec:
fromFieldPath: metadata.name
toFieldPath: metadata.name
...
---
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: provisioneddatasources
labels:
crossplane.io/xrd: provisioneddatasources.grafana.kanopy-platform.github.io
provider: grafana
spec:
compositeTypeRef:
apiVersion: grafana.kanopy-platform.github.io/v1beta1
kind: ProvisionedDataSource
writeConnectionSecretsToNamespace: crossplane-system
resources:
- name: datasource
base:
apiVersion: oss.grafana.crossplane.io/v1alpha1
kind: DataSource
patches:
- type: FromCompositeFieldPath
fromFieldPath: spec.accessMode
toFieldPath: spec.forProvider.accessMode
- type: FromCompositeFieldPath
fromFieldPath: spec.basicAuth
toFieldPath: spec.forProvider.basicAuthEnabled
- type: FromCompositeFieldPath
fromFieldPath: spec.basicAuthUsername
toFieldPath: spec.forProvider.basicAuthUsername
- type: FromCompositeFieldPath
fromFieldPath: spec.databaseName
toFieldPath: spec.forProvider.databaseName
- type: FromCompositeFieldPath
fromFieldPath: spec.default
toFieldPath: spec.forProvider.isDefault
- type: FromCompositeFieldPath
fromFieldPath: spec.type
toFieldPath: spec.forProvider.type
policy:
fromFieldPath: Required
- type: FromCompositeFieldPath
fromFieldPath: spec.config
toFieldPath: spec.forProvider.jsonDataEncoded
- type: FromCompositeFieldPath
fromFieldPath: spec.secureConfigRef
toFieldPath: spec.forProvider.secureJsonDataEncodedSecretRef
- type: FromCompositeFieldPath
fromFieldPath: spec.name
toFieldPath: spec.forProvider.name
policy:
fromFieldPath: Required
- type: FromCompositeFieldPath
fromFieldPath: spec.namespace
toFieldPath: spec.providerConfigRef.name
policy:
fromFieldPath: Required
- type: FromCompositeFieldPath
fromFieldPath: spec.url
toFieldPath: spec.forProvider.url
policy:
fromFieldPath: Required
...
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
apiVersion: apiextensions.crossplane.io/v1
kind: CompositeResourceDefinition
metadata:
creationTimestamp: null
name: provisioneddatasources.grafana.kanopy-platform.github.io
spec:
enforcedCompositionRef:
name: provisioneddatasources
group: grafana.kanopy-platform.github.io
names:
kind: ProvisionedDataSource
listKind: ProvisionedDataSourceList
plural: provisioneddatasources
singular: provisioneddatasource
versions:
- name: v1beta1
referenceable: true
schema:
openAPIV3Schema:
description: infrastructure resources.
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
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:
type: object
spec:
properties:
accessMode:
enum:
- proxy
- direct
type: string
basicAuth:
type: boolean
basicAuthUsername:
type: string
config:
type: string
databaseName:
type: string
default:
type: boolean
name:
type: string
namespace:
type: string
secureConfigRef:
properties:
key:
type: string
name:
type: string
namespace:
type: string
required:
- key
- name
- namespace
type: object
type:
type: string
url:
type: string
required:
- name
- namespace
- type
- url
type: object
type: object
served: true
70 changes: 70 additions & 0 deletions pkg/apis/grafana/v1beta1/datasource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// +groupName=grafana.kanopy-platform.github.io
// +versionName=v1beta1
// +kubebuilder:validation:Optional
package v1beta1

import (
xpapiext "github.com/crossplane/crossplane/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// infrastructure resources.
// +kubebuilder:object:root=true
// +kubebuilder:printcolumn:name="ESTABLISHED",type="string",JSONPath=".status.conditions[?(@.type=='Established')].status"
// +kubebuilder:printcolumn:name="OFFERED",type="string",JSONPath=".status.conditions[?(@.type=='Offered')].status"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:storageversion
// +kubebuilder:resource:scope=Cluster,categories=crossplane,shortName=xrd;xrds
// +kubebuilder:defaultcompositionref:name=provisioneddatasources,enforced=true
type ProvisionedDataSource struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ProvisionedDataSourceSpec `json:"spec,omitempty"`
Status xpapiext.CompositeResourceDefinitionStatus `json:"status,omitempty"`
}

// +kubebuilder:object:generate=true
type ProvisionedDataSourceSpec struct {
// +kubebuilder:validation:Enum=proxy;direct
AccessMode string `json:"accessMode,omitempty"`

BasicAuth *bool `json:"basicAuth,omitempty"`
BasicAuthUsername string `json:"basicAuthUsername,omitempty"`

DatabaseName string `json:"databaseName,omitempty"`

Default *bool `json:"default,omitempty"`

// +kubebuilder:validation:Required
Type string `json:"type,omitempty"`

Config string `json:"config,omitempty"`
SecureConfigRef *SecureConfigRef `json:"secureConfigRef,omitempty"`

// +kubebuilder:validation:Required
Name string `json:"name,omitempty"`

// +kubebuilder:validation:Required
Namespace string `json:"namespace,omitempty"`

// +kubebuilder:validation:Required
URL string `json:"url,omitempty"`
}

type SecureConfigRef struct {
// +kubebuilder:validation:Required
Key string `json:"key"`
// +kubebuilder:validation:Required
Name string `json:"name"`
// +kubebuilder:validation:Required
Namespace string `json:"namespace"`
}

// ProvisionedDataSourceList contains a list of ProvisionedDataSources.
// +kubebuilder:object:root=true
type ProvisionedDataSourceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ProvisionedDataSource `json:"items"`
}
9 changes: 9 additions & 0 deletions pkg/apis/grafana/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ var (
ProvisionedDashboardGroupVersionKind = SchemeGroupVersion.WithKind(ProvisionedDashboardKind)
)

// ProvisionedDataSource type metadata
var (
ProvisionedDataSourceKind = reflect.TypeOf(ProvisionedDataSource{}).Name()
ProvisionedDataSourceGroupKind = schema.GroupKind{Group: Group, Kind: ProvisionedDataSourceKind}.String()
ProvisionedDataSourceKindAPIVersion = ProvisionedDataSourceKind + "." + SchemeGroupVersion.String()
ProvisionedDataSourceGroupVersionKind = SchemeGroupVersion.WithKind(ProvisionedDataSourceKind)
)

func init() {
SchemeBuilder.Register(&ProvisionedFolder{}, &ProvisionedFolderList{})
SchemeBuilder.Register(&ProvisionedDashboard{}, &ProvisionedDashboardList{})
SchemeBuilder.Register(&ProvisionedDataSource{}, &ProvisionedDataSourceList{})
}
89 changes: 89 additions & 0 deletions pkg/apis/grafana/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c1c9718

Please sign in to comment.