Skip to content

Commit

Permalink
add/grafana-user-controller (#30)
Browse files Browse the repository at this point in the history
* add grafana user controller

* fix pipleline error

* fix pipleline error1

* fix pipleline error2

* fix logical structure
  • Loading branch information
Sinamcp authored Jul 18, 2022
1 parent b129d71 commit b030c5b
Show file tree
Hide file tree
Showing 21 changed files with 724 additions and 7 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ COPY go.sum go.sum
RUN go mod download

# Copy the go source
COPY apis/ apis/
COPY main.go main.go
COPY controllers/ controllers/

Expand Down
10 changes: 10 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
domain: snappcloud.io
layout:
- go.kubebuilder.io/v3
multigroup: true
plugins:
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
Expand All @@ -12,4 +13,13 @@ resources:
kind: Namespace
path: k8s.io/api/core/v1
version: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: snappcloud.io
group: grafanauser
kind: GrafanaUser
path: github.com/snapp-cab/grafana-complementary-operator/apis/grafanauser/v1alpha1
version: v1alpha1
version: "3"
57 changes: 57 additions & 0 deletions apis/grafanauser/v1alpha1/grafanauser_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright 2022.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// GrafanaUserSpec defines the desired state of GrafanaUser
type GrafanaUserSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

Admin []string `json:"admin,omitempty"`
Edit []string `json:"edit,omitempty"`
View []string `json:"view,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// GrafanaUser is the Schema for the grafanausers API
type GrafanaUser struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec GrafanaUserSpec `json:"spec,omitempty"`
}

//+kubebuilder:object:root=true

// GrafanaUserList contains a list of GrafanaUser
type GrafanaUserList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []GrafanaUser `json:"items"`
}

func init() {
SchemeBuilder.Register(&GrafanaUser{}, &GrafanaUserList{})
}
36 changes: 36 additions & 0 deletions apis/grafanauser/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2022.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the grafanauser v1alpha1 API group
//+kubebuilder:object:generate=true
//+groupName=grafanauser.snappcloud.io
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "grafanauser.snappcloud.io", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
114 changes: 114 additions & 0 deletions apis/grafanauser/v1alpha1/zz_generated.deepcopy.go

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

61 changes: 61 additions & 0 deletions config/crd/bases/grafanauser.snappcloud.io_grafanausers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
creationTimestamp: null
name: grafanausers.grafanauser.snappcloud.io
spec:
group: grafanauser.snappcloud.io
names:
kind: GrafanaUser
listKind: GrafanaUserList
plural: grafanausers
singular: grafanauser
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: GrafanaUser is the Schema for the grafanausers API
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:
description: GrafanaUserSpec defines the desired state of GrafanaUser
properties:
admin:
items:
type: string
type: array
edit:
items:
type: string
type: array
view:
items:
type: string
type: array
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
21 changes: 21 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This kustomization.yaml is not intended to be run by itself,
# since it depends on service name and namespace that are out of this kustomize package.
# It should be run by config/default
resources:
- bases/grafanauser.snappcloud.io_grafanausers.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#- patches/webhook_in_grafanausers.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- patches/cainjection_in_grafanausers.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
configurations:
- kustomizeconfig.yaml
19 changes: 19 additions & 0 deletions config/crd/kustomizeconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file is for teaching kustomize how to substitute name and namespace reference in CRD
nameReference:
- kind: Service
version: v1
fieldSpecs:
- kind: CustomResourceDefinition
version: v1
group: apiextensions.k8s.io
path: spec/conversion/webhook/clientConfig/service/name

namespace:
- kind: CustomResourceDefinition
version: v1
group: apiextensions.k8s.io
path: spec/conversion/webhook/clientConfig/service/namespace
create: false

varReference:
- path: metadata/annotations
7 changes: 7 additions & 0 deletions config/crd/patches/cainjection_in_grafanausers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: grafanausers.grafanauser.snappcloud.io
16 changes: 16 additions & 0 deletions config/crd/patches/webhook_in_grafanausers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# The following patch enables a conversion webhook for the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: grafanausers.grafanauser.snappcloud.io
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
conversionReviewVersions:
- v1
24 changes: 24 additions & 0 deletions config/rbac/grafanauser_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# permissions for end users to edit grafanausers.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: grafanauser-editor-role
rules:
- apiGroups:
- grafanauser.snappcloud.io
resources:
- grafanausers
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- grafanauser.snappcloud.io
resources:
- grafanausers/status
verbs:
- get
Loading

0 comments on commit b030c5b

Please sign in to comment.