Skip to content

Commit

Permalink
feat(alertchannels): Add AlertChannels resources (#24)
Browse files Browse the repository at this point in the history
AlertChannels can be added to groups, they currently support OpsGenie
and Email configuration.
  • Loading branch information
akosveres authored Jul 24, 2022
1 parent 86b3883 commit 92e146b
Show file tree
Hide file tree
Showing 25 changed files with 1,192 additions and 9 deletions.
8 changes: 8 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ resources:
kind: Group
path: github.com/checkly/checkly-operator/apis/checkly/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
controller: true
domain: checklyhq.com
group: k8s
kind: AlertChannel
path: github.com/checkly/checkly-operator/apis/checkly/v1alpha1
version: v1alpha1
version: "3"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# checkly-operator

[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=checkly_checkly-operator&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=checkly_checkly-operator) [![Build and push](https://github.com/checkly/checkly-operator/actions/workflows/main-merge.yaml/badge.svg)](https://github.com/checkly/checkly-operator/actions/workflows/main-merge.yaml) [![Code Coverage](https://sonarcloud.io/api/project_badges/measure?project=checkly_checkly-operator&metric=coverage)](https://sonarcloud.io/summary/new_code?id=checkly_checkly-operator)
[![Build and push](https://github.com/checkly/checkly-operator/actions/workflows/main-merge.yaml/badge.svg)](https://github.com/checkly/checkly-operator/actions/workflows/main-merge.yaml)

A kubernetes operator for [checklyhq.com](https://checklyhq.com).

The operator can create checklyhq.com checks and groups based of kubernetes CRDs and Ingress object annotations.
The operator can create checklyhq.com checks, groups and alert channels based of kubernetes CRDs and Ingress object annotations.

## Development

Expand Down
85 changes: 85 additions & 0 deletions apis/checkly/v1alpha1/alertchannel_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
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 (
"github.com/checkly/checkly-go-sdk"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

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

// SendRecovery determines if the Recovery event should be sent to the alert channel
SendRecovery bool `json:"sendrecovery,omitempty"`

// SendFailure determines if the Failure event should be sent to the alerting channel
SendFailure bool `json:"sendfailure,omitempty"`

// OpsGenie holds information about the Opsgenie alert configuration
OpsGenie AlertChannelOpsGenie `json:"opsgenie,omitempty"`

// Email holds information about the Email alert configuration
Email checkly.AlertChannelEmail `json:"email,omitempty"`
}

type AlertChannelOpsGenie struct {
// APISecret determines where the secret ref is to pull the OpsGenie API key from
APISecret corev1.ObjectReference `json:"apisecret"`

// Region holds information about the OpsGenie region (EU or US)
Region string `json:"region,omitempty"`

// Priority assigned to the alerts sent from checklyhq.com
Priority string `json:"priority,omitempty"`
}

// AlertChannelStatus defines the observed state of AlertChannel
type AlertChannelStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
ID int64 `json:"id"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster

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

Spec AlertChannelSpec `json:"spec,omitempty"`
Status AlertChannelStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&AlertChannel{}, &AlertChannelList{})
}
2 changes: 1 addition & 1 deletion apis/checkly/v1alpha1/group_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type GroupSpec struct {
// Activated determines if the created group is muted or not, default false
Activated bool `json:"muted,omitempty"`

// AlertChannel determines where to send alerts
// AlertChannels determines where to send alerts
AlertChannels []string `json:"alertchannel,omitempty"`
}

Expand Down
107 changes: 107 additions & 0 deletions apis/checkly/v1alpha1/zz_generated.deepcopy.go

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

121 changes: 121 additions & 0 deletions config/crd/bases/k8s.checklyhq.com_alertchannels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.0
creationTimestamp: null
name: alertchannels.k8s.checklyhq.com
spec:
group: k8s.checklyhq.com
names:
kind: AlertChannel
listKind: AlertChannelList
plural: alertchannels
singular: alertchannel
scope: Cluster
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: AlertChannel is the Schema for the alertchannels 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: AlertChannelSpec defines the desired state of AlertChannel
properties:
email:
description: Email holds information about the Email alert configuration
properties:
address:
type: string
required:
- address
type: object
opsgenie:
description: OpsGenie holds information about the Opsgenie alert configuration
properties:
apisecret:
description: APISecret determines where the secret ref is to pull
the OpsGenie API key from
properties:
apiVersion:
description: API version of the referent.
type: string
fieldPath:
description: 'If referring to a piece of an object instead
of an entire object, this string should contain a valid
JSON/Go field access statement, such as desiredState.manifest.containers[2].
For example, if the object reference is to a container within
a pod, this would take on a value like: "spec.containers{name}"
(where "name" refers to the name of the container that triggered
the event) or if no container name is specified "spec.containers[2]"
(container with index 2 in this pod). This syntax is chosen
only to have some well-defined way of referencing a part
of an object. TODO: this design is not final and this field
is subject to change in the future.'
type: string
kind:
description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
type: string
namespace:
description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
type: string
resourceVersion:
description: 'Specific resourceVersion to which this reference
is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
type: string
uid:
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
type: string
type: object
priority:
description: Priority assigned to the alerts sent from checklyhq.com
type: string
region:
description: Region holds information about the OpsGenie region
(EU or US)
type: string
required:
- apisecret
type: object
sendfailure:
description: SendFailure determines if the Failure event should be
sent to the alerting channel
type: boolean
sendrecovery:
description: SendRecovery determines if the Recovery event should
be sent to the alert channel
type: boolean
type: object
status:
description: AlertChannelStatus defines the observed state of AlertChannel
properties:
id:
description: 'INSERT ADDITIONAL STATUS FIELD - define observed state
of cluster Important: Run "make" to regenerate code after modifying
this file'
format: int64
type: integer
required:
- id
type: object
type: object
served: true
storage: true
subresources:
status: {}
2 changes: 1 addition & 1 deletion config/crd/bases/k8s.checklyhq.com_groups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ spec:
description: GroupSpec defines the desired state of Group
properties:
alertchannel:
description: AlertChannel determines where to send alerts
description: AlertChannels determines where to send alerts
items:
type: string
type: array
Expand Down
3 changes: 3 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ resources:
# - bases/check.checklyhq.com_apis.yaml
- bases/k8s.checklyhq.com_apichecks.yaml
- bases/k8s.checklyhq.com_groups.yaml
- bases/k8s.checklyhq.com_alertchannels.yaml
#+kubebuilder:scaffold:crdkustomizeresource

# patchesStrategicMerge:
Expand All @@ -13,13 +14,15 @@ resources:
#- patches/webhook_in_apis.yaml
#- patches/webhook_in_apichecks.yaml
#- patches/webhook_in_groups.yaml
#- patches/webhook_in_alertchannels.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_apis.yaml
#- patches/cainjection_in_apichecks.yaml
#- patches/cainjection_in_groups.yaml
#- patches/cainjection_in_alertchannels.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_checkly_alertchannels.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: alertchannels.checkly.checklyhq.com
Loading

0 comments on commit 92e146b

Please sign in to comment.