Skip to content

Commit

Permalink
Add contactpoint resource (#1474)
Browse files Browse the repository at this point in the history
* feat(alerting): add contactpoint resource

* Update controllers/grafanacontactpoint_controller.go

Co-authored-by: Dominik Süß <dominik@suess.wtf>

* use k8s uid

* remove trailing whitespace

* add newlines

---------

Co-authored-by: Edvin N <edvin.norling@kognic.com>
Co-authored-by: Dominik Süß <dominik@suess.wtf>
Co-authored-by: Hubert Stefanski <35736504+HubertStefanski@users.noreply.github.com>
  • Loading branch information
4 people committed Apr 3, 2024
1 parent db260b8 commit 6855819
Show file tree
Hide file tree
Showing 22 changed files with 1,179 additions and 0 deletions.
13 changes: 13 additions & 0 deletions PROJECT
@@ -1,3 +1,7 @@
# Code generated by tool. DO NOT EDIT.
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: integreatly.org
layout:
- go.kubebuilder.io/v3
Expand Down Expand Up @@ -51,4 +55,13 @@ resources:
kind: GrafanaAlertRuleGroup
path: github.com/grafana/grafana-operator/api/v1beta1
version: v1beta1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: integreatly.org
group: grafana
kind: GrafanaContactPoint
path: github.com/grafana/grafana-operator/api/v1beta1
version: v1beta1
version: "3"
84 changes: 84 additions & 0 deletions api/v1beta1/grafanacontactpoint_types.go
@@ -0,0 +1,84 @@
/*
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 v1beta1

import (
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
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.

// GrafanaContactPointSpec defines the desired state of GrafanaContactPoint
type GrafanaContactPointSpec struct {
// +optional
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=duration
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
// +kubebuilder:default="10m"
ResyncPeriod metav1.Duration `json:"resyncPeriod,omitempty"`

// selects Grafanas for import
InstanceSelector *metav1.LabelSelector `json:"instanceSelector"`

// +optional
DisableResolveMessage bool `json:"disableResolveMessage,omitempty"`

// +kubebuilder:validation:type=string
Name string `json:"name"`

Settings *apiextensions.JSON `json:"settings"`

// +kubebuilder:validation:Enum=alertmanager;dingding;discord;email;googlechat;kafka;line;opsgenie;pagerduty;pushover;sensugo;slack;teams;telegram;threema;victorops;webhook;wecom
Type string `json:"type,omitempty"`

// +optional
AllowCrossNamespaceImport *bool `json:"allowCrossNamespaceImport,omitempty"`
}

// GrafanaContactPointStatus defines the observed state of GrafanaContactPoint
type GrafanaContactPointStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Conditions []metav1.Condition `json:"conditions"`
}

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

// GrafanaContactPoint is the Schema for the grafanacontactpoints API
type GrafanaContactPoint struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec GrafanaContactPointSpec `json:"spec,omitempty"`
Status GrafanaContactPointStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&GrafanaContactPoint{}, &GrafanaContactPointList{})
}
112 changes: 112 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

137 changes: 137 additions & 0 deletions config/crd/bases/grafana.integreatly.org_grafanacontactpoints.yaml
@@ -0,0 +1,137 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.12.0
name: grafanacontactpoints.grafana.integreatly.org
spec:
group: grafana.integreatly.org
names:
kind: GrafanaContactPoint
listKind: GrafanaContactPointList
plural: grafanacontactpoints
singular: grafanacontactpoint
scope: Namespaced
versions:
- name: v1beta1
schema:
openAPIV3Schema:
properties:
apiVersion:
type: string
kind:
type: string
metadata:
type: object
spec:
properties:
allowCrossNamespaceImport:
type: boolean
disableResolveMessage:
type: boolean
instanceSelector:
properties:
matchExpressions:
items:
properties:
key:
type: string
operator:
type: string
values:
items:
type: string
type: array
required:
- key
- operator
type: object
type: array
matchLabels:
additionalProperties:
type: string
type: object
type: object
x-kubernetes-map-type: atomic
name:
type: string
resyncPeriod:
default: 10m
format: duration
pattern: ^([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$
type: string
settings:
x-kubernetes-preserve-unknown-fields: true
type:
enum:
- alertmanager
- dingding
- discord
- email
- googlechat
- kafka
- line
- opsgenie
- pagerduty
- pushover
- sensugo
- slack
- teams
- telegram
- threema
- victorops
- webhook
- wecom
type: string
required:
- instanceSelector
- name
- settings
type: object
status:
properties:
conditions:
items:
properties:
lastTransitionTime:
format: date-time
type: string
message:
maxLength: 32768
type: string
observedGeneration:
format: int64
minimum: 0
type: integer
reason:
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
enum:
- "True"
- "False"
- Unknown
type: string
type:
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
required:
- conditions
type: object
type: object
served: true
storage: true
subresources:
status: {}
3 changes: 3 additions & 0 deletions config/crd/kustomization.yaml
Expand Up @@ -7,6 +7,7 @@ resources:
- bases/grafana.integreatly.org_grafanadatasources.yaml
- bases/grafana.integreatly.org_grafanafolders.yaml
- bases/grafana.integreatly.org_grafanaalertrulegroups.yaml
- bases/grafana.integreatly.org_grafanacontactpoints.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
Expand All @@ -17,6 +18,7 @@ patchesStrategicMerge:
#- patches/webhook_in_grafanadatasources.yaml
#- patches/webhook_in_grafanafolders.yaml
#- patches/webhook_in_grafanaalertrulegroups.yaml
#- patches/webhook_in_grafanacontactpoints.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
Expand All @@ -26,6 +28,7 @@ patchesStrategicMerge:
#- patches/cainjection_in_grafanadatasources.yaml
#- patches/cainjection_in_grafanafolders.yaml
#- patches/cainjection_in_grafanaalertrulegroups.yaml
#- patches/cainjection_in_grafanacontactpoints.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
7 changes: 7 additions & 0 deletions config/crd/patches/cainjection_in_grafanacontactpoints.yaml
@@ -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: grafanacontactpoints.grafana.integreatly.org

0 comments on commit 6855819

Please sign in to comment.