Skip to content

Commit

Permalink
Implement Alert Configuration API (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Knappek authored Oct 23, 2019
1 parent 92b8b7f commit b0bec67
Show file tree
Hide file tree
Showing 20 changed files with 1,764 additions and 151 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ generate-openapi:
operator-sdk generate openapi

api:
operator-sdk add api --api-version=knappek.com/$(API_VERSION) --kind=$(KIND)
operator-sdk add api --api-version knappek.com/$(API_VERSION) --kind $(KIND)

controller:
./code-generation/controller-gen.sh --api-version v1alpha1 -k $(KIND) && gofmt -w $(GOFMT_FILES)
Expand Down Expand Up @@ -107,4 +107,4 @@ lint:
@which golint > /dev/null; if [ $$? -ne 0 ]; then \
$(GO) get -u golang.org/x/lint/golint; \
fi
$(GO) list ./... | grep -v /vendor/ | xargs golint -set_exit_status
$(GO) list ./... | grep -v /vendor/ | xargs golint -set_exit_status
3 changes: 3 additions & 0 deletions code-generation/controller-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ check_input_vars
KIND_LOWERCASE=$(echo $KIND | tr '[:upper:]' '[:lower:]')
KIND_SHORT=$(echo $KIND | sed 's/MongoDBAtlas//g')

# create controller dir
[[ ! -d pkg/controller/${KIND_LOWERCASE} ]] && mkdir pkg/controller/${KIND_LOWERCASE}

# handle add_kind.go.tmpl
return_add_kind=$(check_if_already_substitued pkg/controller/add_${KIND_LOWERCASE}.go)
if [[ ${return_add_kind} == "y" ]];then
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: knappek.com/v1alpha1
kind: MongoDBAtlasAlertConfiguration
metadata:
name: example-mongodbatlasalertconfiguration
spec:
# Add fields here
projectName: "example-project"
eventTypeName: "OUTSIDE_METRIC_THRESHOLD"
enabled: true
notifications:
- typeName: "GROUP"
intervalMin: 5
delayMin: 0
smsEnabled: false
emailEnabled: true
metricThreshold:
metricName: "QUERY_TARGETING_SCANNED_OBJECTS_PER_RETURNED"
mode: "AVERAGE"
operator: "GREATER_THAN"
threshold: 500.0
units: "RAW"
221 changes: 221 additions & 0 deletions deploy/crds/knappek_v1alpha1_mongodbatlasalertconfiguration_crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: mongodbatlasalertconfigurations.knappek.com
spec:
additionalPrinterColumns:
- JSONPath: .status.id
description: The ID of the Alert Configuration
name: ID
type: string
- JSONPath: .spec.projectName
description: The MongoDB Atlas Project to which the Alert Configuration is applied
name: Project Name
type: string
- JSONPath: .status.enabled
description: Whether the Alert Configuration is enabled or disabled
name: Enabled
type: string
- JSONPath: .metadata.creationTimestamp
name: Age
type: date
group: knappek.com
names:
categories:
- all
- mongodbatlas
kind: MongoDBAtlasAlertConfiguration
listKind: MongoDBAtlasAlertConfigurationList
plural: mongodbatlasalertconfigurations
shortNames:
- maalertconfig
singular: mongodbatlasalertconfiguration
scope: Namespaced
subresources:
status: {}
validation:
openAPIV3Schema:
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/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/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
properties:
enabled:
type: boolean
eventTypeName:
type: string
matchers:
items:
properties:
fieldName:
type: string
operator:
type: string
value:
type: string
type: object
type: array
metricThreshold:
properties:
metricName:
type: string
mode:
type: string
operator:
type: string
threshold:
format: double
type: number
units:
type: string
type: object
notifications:
items:
properties:
apiToken:
type: string
channelName:
type: string
delayMin:
format: int64
type: integer
emailAddress:
type: string
emailEnabled:
type: boolean
flowName:
type: string
flowdockApiToken:
type: string
intervalMin:
format: int64
type: integer
mobileNumber:
type: string
notificationToken:
type: string
opsGenieApiKey:
type: string
orgName:
type: string
roomName:
type: string
serviceKey:
type: string
smsEnabled:
type: boolean
teamId:
type: string
typeName:
type: string
username:
type: string
victorOpsApiKey:
type: string
victorOpsRoutingKey:
type: string
type: object
type: array
projectName:
type: string
required:
- projectName
type: object
status:
properties:
enabled:
type: boolean
eventTypeName:
type: string
groupID:
type: string
id:
type: string
matchers:
items:
properties:
fieldName:
type: string
operator:
type: string
value:
type: string
type: object
type: array
metricThreshold:
properties:
metricName:
type: string
mode:
type: string
operator:
type: string
threshold:
format: double
type: number
units:
type: string
type: object
notifications:
items:
properties:
apiToken:
type: string
channelName:
type: string
delayMin:
format: int64
type: integer
emailAddress:
type: string
emailEnabled:
type: boolean
flowName:
type: string
flowdockApiToken:
type: string
intervalMin:
format: int64
type: integer
mobileNumber:
type: string
notificationToken:
type: string
opsGenieApiKey:
type: string
orgName:
type: string
roomName:
type: string
serviceKey:
type: string
smsEnabled:
type: boolean
teamId:
type: string
typeName:
type: string
username:
type: string
victorOpsApiKey:
type: string
victorOpsRoutingKey:
type: string
type: object
type: array
type: object
version: v1alpha1
versions:
- name: v1alpha1
served: true
storage: true
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ spec:
description: The MongoDB Atlas Project to which the database user has access to
name: Project Name
type: string
- JSONPath: .metadata.creationTimestamp
name: Age
type: date
group: knappek.com
names:
categories:
Expand Down
1 change: 1 addition & 0 deletions deploy/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ rules:
- '*'
- mongodbatlasclusters
- mongodbatlasdatabaseusers
- mongodbatlasalertconfigurations
verbs:
- '*'
19 changes: 9 additions & 10 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Contributing


<!-- vim-markdown-toc GFM -->

* [Develop Locally](#develop-locally)
Expand All @@ -9,7 +8,6 @@
* [E2E Tests](#e2e-tests)
* [Create new API](#create-new-api)
* [Create new Controller for the API](#create-new-controller-for-the-api)
* [Create CRDs](#create-crds)
* [Create a new Release](#create-a-new-release)

<!-- vim-markdown-toc -->
Expand Down Expand Up @@ -95,18 +93,20 @@ This example creates a new MongoDBAtlasCluster API:
make api KIND=MongoDBAtlasCluster
```

## Create new Controller for the API

To create a controller for the recently created API, run:
Afterwards adapt the corresponding `./pkg/apis/knappek/v1alpha1/mongodbatlascluster_types.go`.
Then create the CRD and the generated OpenAPI Spec with

```shell
make controller KIND=MongoDBAtlasCluster
make generate-openapi
make generate-k8s
```

## Create CRDs
## Create new Controller for the API

To create a controller for the recently created API, run:

```shell
make generate-openapi
make controller KIND=MongoDBAtlasCluster
```

## Create a new Release
Expand All @@ -115,7 +115,7 @@ make generate-openapi
A new release will

* create a new release on the Github [release page](https://github.com/Knappek/mongodbatlas-operator/releases)
* create a new release on the Github [release page](https://github.com/Knappek/mongodbatlas-operator/releases)
* push a new tagged Docker image to [Dockerhub](https://cloud.docker.com/repository/docker/knappek/mongodbatlas-operator/tags)

In order to do this, follow these steps:
Expand All @@ -129,4 +129,3 @@ In order to do this, follow these steps:
```

This will kick the CI pipeline and create a new Github Release with the version tag `v<major.minor.patch>`.

Loading

0 comments on commit b0bec67

Please sign in to comment.