Operator that helps to deploy relevant components to detect anomalies in the cluster.
We have created a setup that works to detect cluster anomalies using min/max as well as percentage change methods to start with. Currently, it works with metric data, in future we will incorporate logs/alerts as well. Currently, we are targeting OpenShift as the primary platform.
Also currently we are focusing on Openshift clusters.
Login into an OpenShift cluster using the login command, below is an example of a login command.
oc login --token=*** --server=https://example.com:6443
- Install the CRDs into the cluster:
make install
or
kubectl apply -f config/crd/bases/
- Once installed you can verify it on the cluster by running the following command.
kubectl get crd | grep anomaly
- Run your controller (this will run in the foreground, so switch to a new terminal if you want to leave it running):
make run
- Install Instances of Custom Resources:
kubectl apply -f config/samples/observability-analytics_v1alpha1_anomalyengine.yaml
-
The operator should create related resources like namespace/role/serviceaccount/rolebinding/cronjob etc for the given namespace in the 4th step sample file.
-
Based on the given configuration (Eg. configname
anomalyconfigmpname
given in the 4th step sample file), the cronjob will try to find anomalies and if anything comes up it will add anomaly data into CRD storage which can be queried like below.
oc get anomalydata -n osa-anomaly-detection
# you can see single anomaly data with the following command
oc describe anomalydata 2023-09-27-08-46-02-etcd-object-namespaces-namespaces -n osa-anomaly-detection
NOTE: You can also run this in one step by running: make install run
We have created e2e test script using which we can test operator is working as expected or not in an OpenShift cluster.
Prerequisite :
- You should have access to the container registry for pushing images to the registry.
- You should have an OpenShift cluster, login into the cluster using the following command from your terminal.
oc login --token=*** --server=https://example.com:6443
Then execute the below command to test your operator
sh tests/run-e2e.sh
This script performs the following operations to validate your operator works as expected in the OpenShift cluster.
- Build your operator image and push it to the registry.
- Deploy the operator into the OpenShift cluster using the created container.
- Create CR for the anomaly engine.
- Generate anomaly data and test whether the engine can detect an anomaly or not for Min/Max as well as Percentage Change type.
- Delete the operator and related resources from the cluster.
- Finally it should display the message "✅ All looks good :)" if everything works as expected.
If you are editing the API definitions, generate the manifests such as CRs or CRDs using:
make manifests
NOTE: Run make --help
for more information on all potential make
targets
More information can be found via the Kubebuilder Documentation
You can use the image from quay.io to deploy analytics-operator.
make deploy OPERATOR_IMG=quay.io/openshiftanalytics/observability-analytics-operator:0.0.1
kubectl apply -f config/samples/
Alternatively, if you like to build and use your own image,
make operator-build operator-push IMG_BASE=<some-registry>
make deploy OPERATOR_IMG=<some-registry>/observability-analytics-operator:0.0.1
kubectl apply -f config/samples/
To delete the CRDs from the cluster:
make uninstall
UnDeploy the controller from the cluster:
make undeploy
# run bundle -> creates an index image referencing your bundle image, create a catalog source,
# deploy your Operator to your cluster by creating an OperatorGroup, Subscription, InstallPlan,
# and all other required resources
operator-sdk run bundle quay.io/openshiftanalytics/observability-analytics-operator-bundle:0.1.0
# cleanup installed operator -> cleanup OperatorGroup, Subscription, InstallPlan, Catalog, etc
operator-sdk cleanup analytics-operator
# create catalog using a sample file
kubectl apply -f tests/sample/sample-catalog.yaml
# list available catalog sources
kubectl get catalogsource --all-namespaces
If the catalog source is created successfully, you can find "Sample Operator Catalog" in the Source list on the Operators -> OperatorHub page. Within this source, you can find the "Observability Analytics Operator" operator. You can install the operator from this page and create an AnomalyEngine instance once the operator is installed.
// TODO(user): Add detailed information on how you would like others to contribute to this project
This project aims to follow the Kubernetes Operator pattern.
It uses Controllers, which provides a reconcile function responsible for synchronizing resources until the desired state is reached on the cluster.
Copyright 2023 Redhat.
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.