diff --git a/Makefile b/Makefile index 94f15369d..d21c5bd98 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# Makefile for building Chaos Exporter +# Makefile for building Chaos Operator # Reference Guide - https://www.gnu.org/software/make/manual/make.html IS_DOCKER_INSTALLED = $(shell which docker >> /dev/null 2>&1; echo $$?) @@ -29,7 +29,7 @@ deps: _build_check_docker godeps .PHONY: godeps godeps: @echo "" - @echo "INFO:\tverifying dependencies for chaos exporter build ..." + @echo "INFO:\tverifying dependencies for chaos operator build ..." @go get -u -v golang.org/x/lint/golint @go get -u -v golang.org/x/tools/cmd/goimports diff --git a/README.md b/README.md index 724bcfb2a..590603cea 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,8 @@ which provides bootstrap support for new operator projects, allowing teams to fo The Litmus Chaos Operator helps reconcile the state of the ChaosEngine, a custom resource that holds the chaos intent specified by a developer/devops engineer against a particular stateless/stateful Kubernetes deployment. The operator performs -specific actions upon CRUD of the ChaosEngine, its primary resource. The operator also defines secondary resources (the engine -runner pod and engine monitor service), which are created & managed by it in order to implement the reconcile functions. +specific actions upon CRUD of the ChaosEngine, its primary resource. The operator also defines a secondary resource (the engine +runner pod), which is created & managed by it in order to implement the reconcile functions. ## What is a chaos engine? @@ -147,4 +147,4 @@ Head over to the [Contribution guide](CONTRIBUTING.md) ## License -[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Flitmuschaos%2Fchaos-operator.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Flitmuschaos%2Fchaos-operator?ref=badge_large) \ No newline at end of file +[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Flitmuschaos%2Fchaos-operator.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Flitmuschaos%2Fchaos-operator?ref=badge_large) diff --git a/deploy/01-chaos-operator.yaml b/deploy/01-chaos-operator.yaml index b34a90490..461e9cc4d 100644 --- a/deploy/01-chaos-operator.yaml +++ b/deploy/01-chaos-operator.yaml @@ -63,8 +63,6 @@ spec: env: - name: CHAOS_RUNNER_IMAGE value: "litmuschaos/chaos-runner:latest" - - name: CHAOS_MONITOR_IMAGE - value: "litmuschaos/chaos-exporter:latest" - name: WATCH_NAMESPACE value: - name: POD_NAME @@ -138,11 +136,6 @@ spec: components: type: object properties: - monitor: - type: object - properties: - image: - type: string runner: type: object properties: diff --git a/deploy/chaos_crds.yaml b/deploy/chaos_crds.yaml index f64c92385..0c2d4c185 100644 --- a/deploy/chaos_crds.yaml +++ b/deploy/chaos_crds.yaml @@ -62,11 +62,6 @@ spec: components: type: object properties: - monitor: - type: object - properties: - image: - type: string runner: type: object properties: diff --git a/deploy/crds/chaosengine_crd.yaml b/deploy/crds/chaosengine_crd.yaml index 07fd3659c..7ffa428e5 100644 --- a/deploy/crds/chaosengine_crd.yaml +++ b/deploy/crds/chaosengine_crd.yaml @@ -61,11 +61,6 @@ spec: components: type: object properties: - monitor: - type: object - properties: - image: - type: string runner: type: object properties: diff --git a/deploy/operator.yaml b/deploy/operator.yaml index e2b21ce48..31325d1d8 100644 --- a/deploy/operator.yaml +++ b/deploy/operator.yaml @@ -23,8 +23,6 @@ spec: env: #- name: CHAOS_RUNNER_IMAGE # value: "litmuschaos/chaos-runner:ci" - #- name: CHAOS_MONITOR_IMAGE - # value: "litmuschaos/chaos-exporter:ci" - name: WATCH_NAMESPACE value: - name: POD_NAME diff --git a/pkg/apis/litmuschaos/v1alpha1/chaosengine_types.go b/pkg/apis/litmuschaos/v1alpha1/chaosengine_types.go index 26f5eaa9c..2321ba908 100644 --- a/pkg/apis/litmuschaos/v1alpha1/chaosengine_types.go +++ b/pkg/apis/litmuschaos/v1alpha1/chaosengine_types.go @@ -32,7 +32,7 @@ type ChaosEngineSpec struct { AnnotationCheck string `json:"annotationCheck,omitempty"` //ChaosServiceAccount is the SvcAcc specified for chaos runner pods ChaosServiceAccount string `json:"chaosServiceAccount"` - //Components contains the image of runnner and monitor pod + //Components contains the image, imagePullPolicy, arguments, and commands of runner Components ComponentParams `json:"components"` //Consists of experiments executed by the engine Experiments []ExperimentList `json:"experiments"` @@ -112,20 +112,12 @@ type ApplicationParams struct { AppKind string `json:"appkind"` } -// ComponentParams defines information about the runner and monitor image +// ComponentParams defines information about the runner type ComponentParams struct { - //Contains informations of the monitor pod - Monitor MonitorInfo `json:"monitor"` //Contains informations of the the runner pod Runner RunnerInfo `json:"runner"` } -// MonitorInfo defines the information of the monitor pod -type MonitorInfo struct { - //Image of the monitor pod - Image string `json:"image"` -} - // RunnerInfo defines the information of the runnerinfo pod type RunnerInfo struct { //Image of the runner pod diff --git a/pkg/apis/litmuschaos/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/litmuschaos/v1alpha1/zz_generated.deepcopy.go index 165999c73..8e459502d 100644 --- a/pkg/apis/litmuschaos/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/litmuschaos/v1alpha1/zz_generated.deepcopy.go @@ -325,7 +325,6 @@ func (in *ChaosResultStatus) DeepCopy() *ChaosResultStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ComponentParams) DeepCopyInto(out *ComponentParams) { *out = *in - out.Monitor = in.Monitor in.Runner.DeepCopyInto(&out.Runner) return } @@ -536,22 +535,6 @@ func (in *ExperimentStatuses) DeepCopy() *ExperimentStatuses { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MonitorInfo) DeepCopyInto(out *MonitorInfo) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MonitorInfo. -func (in *MonitorInfo) DeepCopy() *MonitorInfo { - if in == nil { - return nil - } - out := new(MonitorInfo) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RunnerInfo) DeepCopyInto(out *RunnerInfo) { *out = *in diff --git a/pkg/controller/chaosengine/chaosengine_controller.go b/pkg/controller/chaosengine/chaosengine_controller.go index 9537976b1..3af70a88c 100644 --- a/pkg/controller/chaosengine/chaosengine_controller.go +++ b/pkg/controller/chaosengine/chaosengine_controller.go @@ -25,7 +25,6 @@ import ( "github.com/go-logr/logr" "github.com/litmuschaos/elves/kubernetes/container" "github.com/litmuschaos/elves/kubernetes/pod" - "github.com/litmuschaos/elves/kubernetes/service" "github.com/pkg/errors" appsv1 "k8s.io/api/apps/v1" batchv1 "k8s.io/api/batch/v1" @@ -77,20 +76,6 @@ type podEngineRunner struct { *reconcileEngine } -//serviceEngineMonitor contains informatiom of service -type serviceEngineMonitor struct { - service, engineMonitor *corev1.Service - *reconcileEngine - monitoring bool -} - -//podEngineMonitor contains the information of pod -type podEngineMonitor struct { - pod, engineMonitor *corev1.Pod - *reconcileEngine - monitoring bool -} - // Add creates a new ChaosEngine Controller and adds it to the Manager. The Manager will set fields on the Controller // and Start it when the Manager is Started. func Add(mgr manager.Manager) error { @@ -130,14 +115,6 @@ func watchChaosResources(clientSet client.Client, c controller.Controller) error if err != nil { return err } - err = watcher.WatchForMonitorPod(clientSet, c) - if err != nil { - return err - } - err = watcher.WatchForMonitorService(clientSet, c) - if err != nil { - return err - } return nil } @@ -193,56 +170,6 @@ func (r *ReconcileChaosEngine) Reconcile(request reconcile.Request) (reconcile.R return reconcile.Result{}, nil } -//MonitorServiceAndPod checks if the EngineMonitorPod And EngineMonitorService already exist or not -func MonitorServiceAndPod(monitorService *serviceEngineMonitor, monitorPod *podEngineMonitor) error { - // Check if the EngineMonitorService already exists, else create - if err := engineMonitorService(monitorService); err != nil { - return err - } - // Check if the EngineMonitorPod already exists, else create - if err := engineMonitorPod(monitorPod); err != nil { - return err - } - return nil -} - -// Creates engineMonitor pod and engineMonitor Service -// Also reconciles those resources -func createMonitoringResources(engine chaosTypes.EngineInfo, recEngine *reconcileEngine) error { - - // Define the engine-monitor service which is secondary-resource #3 - engineMonitorSvc, err := newMonitorServiceForCR(engine) - if err != nil { - return err - } - //Define an engine-monitor pod which is secondary-resource #2 - engineMonitorPod, err := newMonitorPodForCR(engine) - if err != nil { - return err - } - - // Creates an object of monitorService - monitorService := &serviceEngineMonitor{ - service: &corev1.Service{}, - engineMonitor: engineMonitorSvc, - reconcileEngine: recEngine, - monitoring: engine.Instance.Spec.Monitoring, - } - // Creates an object of monitorPod - monitorPod := &podEngineMonitor{ - pod: &corev1.Pod{}, - engineMonitor: engineMonitorPod, - reconcileEngine: recEngine, - monitoring: engine.Instance.Spec.Monitoring, - } - - // Check if the engineMonitorService already exists, else create - if err = MonitorServiceAndPod(monitorService, monitorPod); err != nil { - return err - } - return nil -} - // getChaosRunnerENV return the env required for chaos-runner func getChaosRunnerENV(cr *litmuschaosv1alpha1.ChaosEngine, aExList []string, ClientUUID string) []corev1.EnvVar { return []corev1.EnvVar{ @@ -281,15 +208,6 @@ func getChaosRunnerENV(cr *litmuschaosv1alpha1.ChaosEngine, aExList []string, Cl } } -// getChaosMonitorENV return the env required for chaos-Monitor -func getChaosMonitorENV(cr *litmuschaosv1alpha1.ChaosEngine, aUUID types.UID) []corev1.EnvVar { - return []corev1.EnvVar{ - {Name: "CHAOSENGINE", Value: cr.Name}, - {Name: "APP_UUID", Value: string(aUUID)}, - {Name: "APP_NAMESPACE", Value: cr.Spec.Appinfo.Appns}, - } -} - // newRunnerPodForCR defines secondary resource #1 in same namespace as CR func newRunnerPodForCR(engine *chaosTypes.EngineInfo) (*corev1.Pod, error) { if (len(engine.AppExperiments) == 0 || engine.AppUUID == "") && engine.Instance.Spec.AnnotationCheck == "true" { @@ -363,50 +281,6 @@ func newAnsibleRunnerPodForCR(engine *chaosTypes.EngineInfo) (*corev1.Pod, error Build() } -// newMonitorPodForCR defines secondary resource #2 in same namespace as CR */ -func newMonitorPodForCR(engine chaosTypes.EngineInfo) (*corev1.Pod, error) { - if engine.Instance == nil { - return nil, errors.New("chaosengine got nil") - } - labels := map[string]string{ - "app": engine.Instance.Name, - "chaosUID": string(engine.Instance.UID), - } - monitorPod, err := pod.NewBuilder(). - WithName(engine.Instance.Name + "-monitor"). - WithNamespace(engine.Instance.Namespace). - WithLabels(labels). - WithServiceAccountName(engine.Instance.Spec.ChaosServiceAccount). - WithRestartPolicy("OnFailure"). - WithContainerBuilder( - container.NewBuilder(). - WithName("chaos-monitor"). - WithImage(engine.Instance.Spec.Components.Monitor.Image). - WithPortsNew([]corev1.ContainerPort{{ContainerPort: 8080, Protocol: "TCP", Name: "metrics"}}). - WithEnvsNew(getChaosMonitorENV(engine.Instance, engine.AppUUID))).Build() - if err != nil { - return nil, err - } - return monitorPod, nil -} - -// newMonitorServiceForCR defines secondary resource #2 in same namespace as CR */ -func newMonitorServiceForCR(engine chaosTypes.EngineInfo) (*corev1.Service, error) { - if engine.Instance == nil { - return nil, errors.New("nil chaosengine object") - } - serviceObj, err := service.NewBuilder(). - WithName(engine.Instance.Name + "-monitor"). - WithNamespace(engine.Instance.Namespace). - WithLabels(map[string]string{"app": "chaos-exporter", "chaosUID": string(engine.Instance.UID)}). - WithPorts([]corev1.ServicePort{{Name: "metrics", Port: 8080}}). - WithSelectorsNew(map[string]string{"app": engine.Instance.Name, "chaosUID": string(engine.Instance.UID)}).Build() - if err != nil { - return nil, err - } - return serviceObj, nil -} - // initializeApplicationInfo to initialize application info func initializeApplicationInfo(instance *litmuschaosv1alpha1.ChaosEngine, appInfo *chaosTypes.ApplicationInfo) (*chaosTypes.ApplicationInfo, error) { if instance == nil { @@ -443,42 +317,6 @@ func engineRunnerPod(runnerPod *podEngineRunner) error { return nil } -// Check if the engineMonitorService already exists, else create -func engineMonitorService(monitorService *serviceEngineMonitor) error { - err := monitorService.r.client.Get(context.TODO(), types.NamespacedName{Name: monitorService.engineMonitor.Name, Namespace: monitorService.engineMonitor.Namespace}, monitorService.service) - if err != nil && k8serrors.IsNotFound(err) { - monitorService.reqLogger.Info("Creating a new engineMonitor Service", "Service.Namespace", monitorService.engineMonitor.Namespace, "Service.Name", monitorService.engineMonitor.Name) - err = monitorService.r.client.Create(context.TODO(), monitorService.engineMonitor) - if err != nil { - return err - } - - // Service created successfully - don't requeue - } else if err != nil { - return err - } - monitorService.reqLogger.Info("Skip reconcile: engineMonitor Service already exists", "Service.Namespace", monitorService.engineMonitor.Namespace, "Service.Name", monitorService.engineMonitor.Name) - return nil /*You can return now, both sec resources are existing */ -} - -// engineMonitorPod to Check if the engineMonitor Pod is already exists, else create -func engineMonitorPod(monitorPod *podEngineMonitor) error { - coreV1Pod := &corev1.Pod{} - err := monitorPod.r.client.Get(context.TODO(), types.NamespacedName{Name: monitorPod.engineMonitor.Name, Namespace: monitorPod.engineMonitor.Namespace}, coreV1Pod) - if err != nil && k8serrors.IsNotFound(err) { - monitorPod.reqLogger.Info("Creating a new engineMonitor Pod", "Pod.Namespace", monitorPod.engineMonitor.Namespace, "Pod.Name", monitorPod.engineMonitor.Name) - if err = monitorPod.r.client.Create(context.TODO(), monitorPod.engineMonitor); err != nil { - return err - } - - monitorPod.reqLogger.Info("engineMonitor Pod created successfully") - } else if err != nil { - return err - } - monitorPod.reqLogger.Info("Skip reconcile: engineMonitor Pod already exists", "Pod.Namespace", coreV1Pod.Namespace, "Pod.Name", coreV1Pod.Name) - return nil -} - // Fetch the ChaosEngine instance func (r *ReconcileChaosEngine) getChaosEngineInstance(request reconcile.Request) error { instance := &litmuschaosv1alpha1.ChaosEngine{} @@ -514,7 +352,6 @@ func getApplicationDetail(engine *chaosTypes.EngineInfo) error { chaosTypes.Log.Info("Exp list derived from chaosengine is ", "appExpirements", appExperiments) chaosTypes.Log.Info("Monitoring Status derived from chaosengine is", "monitoringStatus", engine.Instance.Spec.Monitoring) chaosTypes.Log.Info("Runner image derived from chaosengine is", "runnerImage", engine.Instance.Spec.Components.Runner.Image) - chaosTypes.Log.Info("exporter image derived from chaosengine is", "exporterImage", engine.Instance.Spec.Components.Monitor.Image) chaosTypes.Log.Info("Annotation check is ", "annotationCheck", engine.Instance.Spec.AnnotationCheck) return nil } @@ -555,37 +392,13 @@ func (r *ReconcileChaosEngine) checkEngineRunnerPod(engine *chaosTypes.EngineInf return nil } -// check monitoring status -func (r *ReconcileChaosEngine) checkMonitoringPodAndSvc(reqLogger logr.Logger) error { - // Create an object of engine reconcile. - engineReconcile := &reconcileEngine{ - r: r, - reqLogger: reqLogger, - } - if engine.Instance.Spec.Monitoring { - err := createMonitoringResources(*engine, engineReconcile) - if err != nil { - return err - } - } else { - reqLogger.Info("Monitoring is disabled") - } - return nil -} - -//setChaosResourceImage take the runner and monitor image from engine spec +//setChaosResourceImage take the runner image from engine spec //if it is not there then it will take from chaos-operator env //at last if it is not able to find image in engine spec and operator env then it will take default images func setChaosResourceImage() { - ChaosMonitorImage := os.Getenv("CHAOS_MONITOR_IMAGE") ChaosRunnerImage := os.Getenv("CHAOS_RUNNER_IMAGE") - if engine.Instance.Spec.Components.Monitor.Image == "" && ChaosMonitorImage == "" { - engine.Instance.Spec.Components.Monitor.Image = chaosTypes.DefaultChaosMonitorImage - } else if engine.Instance.Spec.Components.Monitor.Image == "" { - engine.Instance.Spec.Components.Monitor.Image = ChaosMonitorImage - } if engine.Instance.Spec.Components.Runner.Image == "" && ChaosRunnerImage == "" { engine.Instance.Spec.Components.Runner.Image = chaosTypes.DefaultChaosRunnerImage } else if engine.Instance.Spec.Components.Runner.Image == "" { @@ -631,24 +444,6 @@ func (r *ReconcileChaosEngine) reconcileForDelete(request reconcile.Request) (re } -// removeChaosServices removes chaos services -func (r *ReconcileChaosEngine) removeChaosServices(engine *chaosTypes.EngineInfo, request reconcile.Request) error { - optsList := []client.ListOption{ - client.InNamespace(request.NamespacedName.Namespace), - client.MatchingLabels{"app": "chaos-exporter", "chaosUID": string(engine.Instance.UID)}, - } - var serviceList corev1.ServiceList - if errList := r.client.List(context.TODO(), &serviceList, optsList...); errList != nil { - return errList - } - for _, v := range serviceList.Items { - if errDel := r.client.Delete(context.TODO(), &v, []client.DeleteOption{}...); errDel != nil { - return errDel - } - } - return nil -} - // forceRemoveAllChaosPods force removes all chaos-related pods func (r *ReconcileChaosEngine) forceRemoveAllChaosPods(engine *chaosTypes.EngineInfo, request reconcile.Request) error { optsDelete := []client.DeleteAllOfOption{client.InNamespace(request.NamespacedName.Namespace), client.MatchingLabels{"chaosUID": string(engine.Instance.UID)}, client.PropagationPolicy(metav1.DeletePropagationBackground), client.GracePeriodSeconds(int64(0))} @@ -702,9 +497,6 @@ func (r *ReconcileChaosEngine) gracefullyRemoveDefaultChaosResources(request rec if err := r.gracefullyRemoveChaosPods(engine, request); err != nil { return reconcile.Result{}, err } - if err := r.removeChaosServices(engine, request); err != nil { - return reconcile.Result{}, err - } } return reconcile.Result{}, nil } @@ -790,15 +582,6 @@ func (r *ReconcileChaosEngine) reconcileForCreationAndRunning(engine *chaosTypes r.recorder.Eventf(engine.Instance, corev1.EventTypeWarning, "ChaosResourcesOperationFailed", "Unable to get chaos resources") return reconcile.Result{}, err } - // If monitoring is set to true, - // Define an engineMonitor pod which is secondary-resource #2 and - // Define an engineMonitor service which is secondary-resource #3 - // in the same namespace as CR - err = r.checkMonitoringPodAndSvc(reqLogger) - if err != nil { - r.recorder.Eventf(engine.Instance, corev1.EventTypeWarning, "ChaosResourcesOperationFailed", "Unable to get chaos resources") - return reconcile.Result{}, err - } isCompleted := r.checkRunnerPodCompletedStatus(engine) if isCompleted { @@ -829,7 +612,7 @@ func startReqLogger(request reconcile.Request) logr.Logger { } func (r *ReconcileChaosEngine) validateAnnontatedApplication(engine *chaosTypes.EngineInfo) error { - // Get the image for runner and monitor pod from chaosengine spec,operator env or default values. + // Get the image for runner pod from chaosengine spec,operator env or default values. setChaosResourceImage() //getAnnotationCheck fetch the annotationCheck from engine spec @@ -885,9 +668,5 @@ func (r *ReconcileChaosEngine) forceRemoveChaosResources(engine *chaosTypes.Engi if err != nil { return err } - err = r.removeChaosServices(engine, request) - if err != nil { - return err - } return nil } diff --git a/pkg/controller/chaosengine/chaosengine_controller_test.go b/pkg/controller/chaosengine/chaosengine_controller_test.go index 9b10454c9..9b0bb297b 100644 --- a/pkg/controller/chaosengine/chaosengine_controller_test.go +++ b/pkg/controller/chaosengine/chaosengine_controller_test.go @@ -23,7 +23,6 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" litmuschaosv1alpha1 "github.com/litmuschaos/chaos-operator/pkg/apis/litmuschaos/v1alpha1" chaosTypes "github.com/litmuschaos/chaos-operator/pkg/controller/types" @@ -45,9 +44,6 @@ func TestNewRunnerPodForCR(t *testing.T) { ChaosServiceAccount: "fake-serviceAccount", Monitoring: true, Components: litmuschaosv1alpha1.ComponentParams{ - Monitor: litmuschaosv1alpha1.MonitorInfo{ - Image: "fake-monitor-image", - }, Runner: litmuschaosv1alpha1.RunnerInfo{ Image: "fake-runner-image", }, @@ -70,9 +66,6 @@ func TestNewRunnerPodForCR(t *testing.T) { ChaosServiceAccount: "fake-serviceAccount", Monitoring: false, Components: litmuschaosv1alpha1.ComponentParams{ - Monitor: litmuschaosv1alpha1.MonitorInfo{ - Image: "fake-monitor-image", - }, Runner: litmuschaosv1alpha1.RunnerInfo{ Image: "fake-runner-image", }, @@ -137,9 +130,6 @@ func TestNewRunnerPodForCR(t *testing.T) { Spec: litmuschaosv1alpha1.ChaosEngineSpec{ ChaosServiceAccount: "fake-serviceAccount", Components: litmuschaosv1alpha1.ComponentParams{ - Monitor: litmuschaosv1alpha1.MonitorInfo{ - Image: "", - }, Runner: litmuschaosv1alpha1.RunnerInfo{ Image: "", }, @@ -165,114 +155,6 @@ func TestNewRunnerPodForCR(t *testing.T) { }) } } -func TestNewMonitorServiceForCR(t *testing.T) { - tests := map[string]struct { - engine chaosTypes.EngineInfo - isErr bool - }{ - "Test Positive": { - engine: chaosTypes.EngineInfo{ - Instance: &litmuschaosv1alpha1.ChaosEngine{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-monitor", - Namespace: "test", - }, - Spec: litmuschaosv1alpha1.ChaosEngineSpec{ - ChaosServiceAccount: "fake-serviceAccount", - Monitoring: false, - Components: litmuschaosv1alpha1.ComponentParams{ - Monitor: litmuschaosv1alpha1.MonitorInfo{ - Image: "fake-monitor-image", - }, - Runner: litmuschaosv1alpha1.RunnerInfo{ - Image: "fake-runner-image", - }, - }, - }, - }, - }, - isErr: false, - }, - "Test Negative": { - engine: chaosTypes.EngineInfo{ - Instance: &litmuschaosv1alpha1.ChaosEngine{ - ObjectMeta: metav1.ObjectMeta{}, - Spec: litmuschaosv1alpha1.ChaosEngineSpec{ - Monitoring: true, - }, - }, - }, - isErr: true, - }, - } - for name, mock := range tests { - name, mock := name, mock - t.Run(name, func(t *testing.T) { - - _, err := newMonitorServiceForCR(mock.engine) - if mock.isErr && err == nil { - t.Fatalf("Test %q failed: expected error not to be nil", name) - } - if !mock.isErr && err != nil { - t.Fatalf("Test %q failed: expected error to be nil", name) - } - }) - } -} -func TestNewMonitorPodForCR(t *testing.T) { - tests := map[string]struct { - engine chaosTypes.EngineInfo - isErr bool - }{ - "Test Positive": { - engine: chaosTypes.EngineInfo{ - Instance: &litmuschaosv1alpha1.ChaosEngine{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-monitor", - Namespace: "test", - }, - Spec: litmuschaosv1alpha1.ChaosEngineSpec{ - ChaosServiceAccount: "fake-serviceAccount", - Monitoring: false, - Components: litmuschaosv1alpha1.ComponentParams{ - Monitor: litmuschaosv1alpha1.MonitorInfo{ - Image: "fake-monitor-image", - }, - Runner: litmuschaosv1alpha1.RunnerInfo{ - Image: "fake-runner-image", - }, - }, - }, - }, - }, - isErr: false, - }, - "Test Negative": { - engine: chaosTypes.EngineInfo{ - Instance: &litmuschaosv1alpha1.ChaosEngine{ - ObjectMeta: metav1.ObjectMeta{}, - Spec: litmuschaosv1alpha1.ChaosEngineSpec{ - Monitoring: true, - }, - }, - }, - isErr: true, - }, - } - for name, mock := range tests { - name, mock := name, mock - t.Run(name, func(t *testing.T) { - - _, err := newMonitorPodForCR(mock.engine) - if mock.isErr && err == nil { - t.Fatalf("Test %q failed: expected error not to be nil", name) - } - if !mock.isErr && err != nil { - t.Fatalf("Test %q failed: expected error to be nil", name) - } - }) - } -} func TestInitializeApplicationInfo(t *testing.T) { tests := map[string]struct { instance *litmuschaosv1alpha1.ChaosEngine @@ -403,59 +285,3 @@ func TestGetChaosRunnerENV(t *testing.T) { }) } } - -func TestGetChaosMonitorENV(t *testing.T) { - fakeEngineName := "Fake Engine" - fakeNameSpace := "fake NameSpace" - fakeAUUID := types.UID("fake UUID") - - tests := map[string]struct { - instance *litmuschaosv1alpha1.ChaosEngine - aUUID types.UID - expectedResult []corev1.EnvVar - }{ - "Test Positive": { - instance: &litmuschaosv1alpha1.ChaosEngine{ - ObjectMeta: metav1.ObjectMeta{ - Name: fakeEngineName, - Namespace: fakeNameSpace, - }, - Spec: litmuschaosv1alpha1.ChaosEngineSpec{ - Appinfo: litmuschaosv1alpha1.ApplicationParams{ - Appns: fakeNameSpace, - }, - }, - }, - - aUUID: fakeAUUID, - expectedResult: []corev1.EnvVar{ - { - Name: "CHAOSENGINE", - Value: fakeEngineName, - }, - { - Name: "APP_UUID", - Value: string(fakeAUUID), - }, - { - Name: "APP_NAMESPACE", - Value: fakeNameSpace, - }, - }, - }, - } - for name, mock := range tests { - name, mock := name, mock - t.Run(name, func(t *testing.T) { - actualResult := getChaosMonitorENV(mock.instance, mock.aUUID) - if len(actualResult) != 3 { - t.Fatalf("Test %q failed: expected array length to be 3", name) - } - for index, result := range actualResult { - if result.Value != mock.expectedResult[index].Value { - t.Fatalf("Test %q failed: actual result %q, received result %q", name, result, mock.expectedResult[index]) - } - } - }) - } -} diff --git a/pkg/controller/types/types.go b/pkg/controller/types/types.go index 4e8e4718d..83f756184 100644 --- a/pkg/controller/types/types.go +++ b/pkg/controller/types/types.go @@ -51,9 +51,6 @@ var ( // Log with default name ie: controller_chaosengine Log = logf.Log.WithName("controller_chaosengine") - // DefaultChaosMonitorImage contains the default value of monitor resource - DefaultChaosMonitorImage = "litmuschaos/chaos-exporter:latest" - // DefaultChaosRunnerImage contains the default value of runner resource DefaultChaosRunnerImage = "litmuschaos/chaos-runner:latest" ) diff --git a/pkg/controller/watcher/watcher.go b/pkg/controller/watcher/watcher.go index 868ad65dd..1a2af2b67 100644 --- a/pkg/controller/watcher/watcher.go +++ b/pkg/controller/watcher/watcher.go @@ -33,14 +33,6 @@ import ( chaosTypes "github.com/litmuschaos/chaos-operator/pkg/controller/types" ) -// WatchForMonitorService creates a watcher for Chaos MonitorService -func WatchForMonitorService(client client.Client, c controller.Controller) error { - - monitorServiceHandler := handlerForMonitorService(client) - - return c.Watch(&source.Kind{Type: &corev1.Service{}}, &monitorServiceHandler) -} - // WatchForRunnerPod creates watcher for Chaos Runner Pod func WatchForRunnerPod(client client.Client, c controller.Controller) error { @@ -49,61 +41,6 @@ func WatchForRunnerPod(client client.Client, c controller.Controller) error { return c.Watch(&source.Kind{Type: &corev1.Pod{}}, &runnerPodHandler) } -// WatchForMonitorPod creates watcher for Chaos Monitor Pod -func WatchForMonitorPod(client client.Client, c controller.Controller) error { - - monitorPodHandler := handlerForMonitorPod(client) - - return c.Watch(&source.Kind{Type: &corev1.Pod{}}, &monitorPodHandler) -} - -// handlerForMonitorService creates a event handler for Monitor Service -func handlerForMonitorService(clientSet client.Client) handler.EnqueueRequestsFromMapFunc { - reqLogger := chaosTypes.Log.WithName("Chaos Resources Watch") - var monitorServiceRequest []reconcile.Request - var err error - - handlerForMonitorService := handler.EnqueueRequestsFromMapFunc{ - ToRequests: handler.ToRequestsFunc(func(a handler.MapObject) []reconcile.Request { - monitorServiceCheck := strings.HasSuffix(a.Meta.GetName(), "-monitor") - if monitorServiceCheck { - monitorServiceRequest, err = createHandlerRequestForEngine(a, clientSet) - if err != nil { - reqLogger.Error(err, "Unable to get the ChaosEngine Resources", "namespace", a.Meta.GetNamespace()) - return nil - } - } - return monitorServiceRequest - - }), - } - return handlerForMonitorService - -} - -// handlerForMonitorPod creates a event Handler for Chaos Monitor Pod -func handlerForMonitorPod(clientSet client.Client) handler.EnqueueRequestsFromMapFunc { - reqLogger := chaosTypes.Log.WithName("Chaos Resources Watch") - var monitorPodRequest []reconcile.Request - var err error - - handlerForMonitorPod := handler.EnqueueRequestsFromMapFunc{ - ToRequests: handler.ToRequestsFunc(func(a handler.MapObject) []reconcile.Request { - monitorNameCheck := strings.HasSuffix(a.Meta.GetName(), "-monitor") - if monitorNameCheck { - monitorPodRequest, err = createHandlerRequestForEngine(a, clientSet) - if err != nil { - reqLogger.Error(err, "Unable to get the ChaosEngine Resources", "namespace", a.Meta.GetNamespace()) - return nil - } - - } - return monitorPodRequest - }), - } - return handlerForMonitorPod -} - // handlerForRunnerPod creates a event Handler for Chaos Runner Pod func handlerForRunnerPod(clientSet client.Client) handler.EnqueueRequestsFromMapFunc { reqLogger := chaosTypes.Log.WithName("Chaos Resources Watch") @@ -179,6 +116,6 @@ func createHandlerRequestForEngine(a handler.MapObject, clientSet client.Client) if err != nil { return nil, fmt.Errorf("Unable to get the ChaosEngine Resources in namespace: %v", a.Meta.GetNamespace()) } - monitorServiceRequest := handlerRequestFromEngineList(listChaosEngine, chaosUID) - return monitorServiceRequest, nil + chaosEngineListRequest := handlerRequestFromEngineList(listChaosEngine, chaosUID) + return chaosEngineListRequest, nil } diff --git a/tests/bdd/bdd_test.go b/tests/bdd/bdd_test.go index 50bed0442..e56e4c30a 100644 --- a/tests/bdd/bdd_test.go +++ b/tests/bdd/bdd_test.go @@ -242,19 +242,16 @@ var _ = Describe("BDD on chaos-operator", func() { fmt.Println("Chaosengine created successfully...") - //Wait till the creation of runner pod and monitor svc + //Wait till the creation of runner pod time.Sleep(50 * time.Second) //Fetching engine-nginx-runner pod runner, err := client.CoreV1().Pods("litmus").Get("engine-nginx-runner", metav1.GetOptions{}) - //Fetching engine-nginx-exporter pod - exporter, err := client.CoreV1().Pods("litmus").Get("engine-nginx-monitor", metav1.GetOptions{}) //Check for the Availabilty and status of the runner pod - fmt.Println("name : ", runner.Name) + //fmt.Println("name : ", runner.Name) Expect(err).To(BeNil()) Expect(string(runner.Status.Phase)).To(Or(Equal("Running"), Equal("Succeeded"))) - Expect(string(exporter.Status.Phase)).To(Equal("Running")) // Check for EngineStatus engine, err := clientSet.ChaosEngines("litmus").Get("engine-nginx", metav1.GetOptions{}) @@ -265,17 +262,6 @@ var _ = Describe("BDD on chaos-operator", func() { }) }) - // BDD TEST CASE 2 - Context("check for the custom resources", func() { - - It("Should check for creation of monitor service", func() { - _, err := client.CoreV1().Services("litmus").Get("engine-nginx-monitor", metav1.GetOptions{}) - Expect(err).To(BeNil()) - - }) - - }) - Context("Setting the EngineState of ChaosEngine as Stop", func() { It("Should delete chaos-resources", func() { @@ -291,7 +277,7 @@ var _ = Describe("BDD on chaos-operator", func() { fmt.Println("Chaosengine updated successfully...") - //Wait till the creation of runner pod and monitor svc + //Wait till the creation of runner pod time.Sleep(50 * time.Second) }) @@ -311,28 +297,6 @@ var _ = Describe("BDD on chaos-operator", func() { }) - It("Should delete chaos-monitor pod ", func() { - - //Fetching engine-nginx-exporter pod - _, err := client.CoreV1().Pods("litmus").Get("engine-nginx-monitor", metav1.GetOptions{}) - fmt.Printf("%v", err) - isNotFound := errors.IsNotFound(err) - Expect(isNotFound).To(BeTrue()) - fmt.Println("chaos-monitor pod deletion verified") - - }) - - It("Should delete chaos-monitor service ", func() { - - //Fetching engine-nginx-exporter pod - _, err := client.CoreV1().Services("litmus").Get("engine-nginx-monitor", metav1.GetOptions{}) - fmt.Printf("%v", err) - isNotFound := errors.IsNotFound(err) - Expect(isNotFound).To(BeTrue()) - fmt.Println("chaos-monitor service deletion verified") - - }) - It("Should change the engineStatus ", func() { //Fetching engineStatus @@ -413,28 +377,6 @@ var _ = Describe("BDD on chaos-operator", func() { }) - It("Should delete chaos-monitor pod ", func() { - - //Fetching engine-nginx-exporter pod - _, err := client.CoreV1().Pods("litmus").Get("engine-nginx-monitor", metav1.GetOptions{}) - fmt.Printf("%v", err) - isNotFound := errors.IsNotFound(err) - Expect(isNotFound).To(BeTrue()) - fmt.Println("chaos-monitor pod deletion verified") - - }) - - It("Should delete chaos-monitor service ", func() { - - //Fetching engine-nginx-exporter pod - _, err := client.CoreV1().Services("litmus").Get("engine-nginx-monitor", metav1.GetOptions{}) - fmt.Printf("%v\n", err) - isNotFound := errors.IsNotFound(err) - Expect(isNotFound).To(BeTrue()) - fmt.Println("chaos-monitor service deletion verified") - - }) - It("Should change EngineStatus ", func() { //Fetching engineStatus