diff --git a/NOTICE.md b/NOTICE.md new file mode 100644 index 00000000..981efaa0 --- /dev/null +++ b/NOTICE.md @@ -0,0 +1,5 @@ +The source code developed for the LitmusChaos Project is licensed under Apache 2.0. + +However, the LitmusChaos project contains unmodified subcomponents from other Open Source Projects with separate copyright notices and license terms. + +Your use of the source code for these subcomponents is subject to the terms and conditions as defined by those source projects. diff --git a/README.md b/README.md index 2cf6035e..193d95ab 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ [![Go Report Card](https://goreportcard.com/badge/github.com/litmuschaos/chaos-runner)](https://goreportcard.com/report/github.com/litmuschaos/chaos-runner) [![BCH compliance](https://bettercodehub.com/edge/badge/litmuschaos/chaos-runner?branch=master)](https://bettercodehub.com/) [![Docker Pulls](https://img.shields.io/docker/pulls/litmuschaos/chaos-runner.svg)](https://hub.docker.com/r/litmuschaos/chaos-runner) +[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Flitmuschaos%2Fchaos-runner.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Flitmuschaos%2Fchaos-runner?ref=badge_shield) # CHAOS RUNNER @@ -62,3 +63,6 @@ spec: ## Further Improvements - The Go Chaos Runner is in beta stage with further improvements coming soon!! + +## License +[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Flitmuschaos%2Fchaos-runner.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Flitmuschaos%2Fchaos-runner?ref=badge_large) diff --git a/bin/runner.go b/bin/runner.go index cef380c9..322bde2d 100644 --- a/bin/runner.go +++ b/bin/runner.go @@ -1,8 +1,6 @@ package main import ( - "time" - "k8s.io/klog" "github.com/litmuschaos/chaos-runner/pkg/utils" @@ -41,6 +39,7 @@ func main() { if err := experiment.SetENV(engineDetails, clients); err != nil { klog.V(0).Infof("Unable to patch ENV due to error: %v", err) + recorder.ExperimentSkipped(engineDetails.Experiments[i], utils.ExperimentEnvParseErrorReason) break } experimentStatus := utils.ExperimentStatus{} @@ -53,6 +52,7 @@ func main() { if err := experiment.HandleChaosExperimentExistence(engineDetails, clients); err != nil { klog.V(0).Infof("Unable to get ChaosExperiment Name: %v, in namespace: %v, due to error: %v", experiment.Name, experiment.Namespace, err) + recorder.ExperimentSkipped(engineDetails.Experiments[i], utils.ExperimentNotFoundErrorReason) break } @@ -65,15 +65,16 @@ func main() { // Creation of PodTemplateSpec, and Final Job if err := utils.BuildingAndLaunchJob(experiment, clients); err != nil { klog.V(0).Infof("Unable to construct chaos experiment job due to: %v", err) + recorder.ExperimentSkipped(engineDetails.Experiments[i], utils.ExperimentJobCreationErrorReason) break } recorder.ExperimentJobCreate(engineDetails.Experiments[i], experiment.JobName) - time.Sleep(5 * time.Second) klog.V(0).Infof("Started Chaos Experiment Name: %v, with Job Name: %v", experiment.Name, experiment.JobName) // Watching the Job till Completion if err := engineDetails.WatchJobForCompletion(experiment, clients); err != nil { klog.V(0).Infof("Unable to Watch the Job, error: %v", err) + recorder.ExperimentSkipped(engineDetails.Experiments[i], utils.ExperimentJobWatchErrorReason) break } @@ -88,6 +89,5 @@ func main() { klog.V(0).Infof("Unable to Delete ChaosExperiment Job due to: %v", err) } recorder.ExperimentJobCleanUp(experiment, jobCleanUpPolicy) - time.Sleep(5 * time.Second) } } diff --git a/pkg/utils/recorder.go b/pkg/utils/recorder.go index 141a9c84..6eadac2a 100644 --- a/pkg/utils/recorder.go +++ b/pkg/utils/recorder.go @@ -6,6 +6,7 @@ import ( "k8s.io/client-go/kubernetes/scheme" typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1" "k8s.io/client-go/tools/record" + "time" litmuschaosScheme "github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned/scheme" ) @@ -37,37 +38,35 @@ func NewEventRecorder(clients ClientSets, engineDetails EngineDetails) (*Recorde }, nil } -const ( - experimentDependencyCheck string = "ExperimentDependencyCheck" - experimentJobCreate string = "ExperimentJobCreate" - experimentJobCleanUp string = "ExperimentJobCleanUp" - experimentSkipped string = "ExperimentSkipped" -) - // ExperimentDepedencyCheck is an standard event spawned just after validating // experiment dependent resources such as ChaosExperiment, ConfigMaps and Secrets. func (r Recorder) ExperimentDepedencyCheck(experimentName string) { - r.EventRecorder.Eventf(r.EventResource, corev1.EventTypeNormal, experimentDependencyCheck, "Experiment resources validated for Chaos Experiment: '%s'", experimentName) + r.EventRecorder.Eventf(r.EventResource, corev1.EventTypeNormal, ExperimentDependencyCheckReason, "Experiment resources validated for Chaos Experiment: '%s'", experimentName) + time.Sleep(5 * time.Second) } // ExperimentJobCreate is an standard event spawned just after // starting chaosExperiment Job func (r Recorder) ExperimentJobCreate(experimentName string, jobName string) { - r.EventRecorder.Eventf(r.EventResource, corev1.EventTypeNormal, experimentJobCreate, "Experiment Job '%s' created for Chaos Experiment '%s'", jobName, experimentName) + r.EventRecorder.Eventf(r.EventResource, corev1.EventTypeNormal, ExperimentJobCreateReason, "Experiment Job '%s' created for Chaos Experiment '%s'", jobName, experimentName) + time.Sleep(5 * time.Second) } // ExperimentJobCleanUp is an standard event spawned just after // starting ChaosExperiment Job func (r Recorder) ExperimentJobCleanUp(experiment *ExperimentDetails, jobCleanUpPolicy string) { if jobCleanUpPolicy == "delete" { - r.EventRecorder.Eventf(r.EventResource, corev1.EventTypeNormal, experimentJobCleanUp, "Experiment Job '%s' is deleted", experiment.JobName) + r.EventRecorder.Eventf(r.EventResource, corev1.EventTypeNormal, ExperimentJobCleanUpReason, "Experiment Job '%s' is deleted", experiment.JobName) + time.Sleep(5 * time.Second) } else { - r.EventRecorder.Eventf(r.EventResource, corev1.EventTypeNormal, experimentJobCleanUp, "Experiment Job '%s' will be retained", experiment.JobName) + r.EventRecorder.Eventf(r.EventResource, corev1.EventTypeNormal, ExperimentJobCleanUpReason, "Experiment Job '%s' will be retained", experiment.JobName) + time.Sleep(5 * time.Second) } } // ExperimentSkipped is an standard event spawned just after // an experiment is skipped -func (r Recorder) ExperimentSkipped(experimentName string) { - r.EventRecorder.Eventf(r.EventResource, corev1.EventTypeNormal, experimentSkipped, "Experiment Job creation failed, skipping Chaos Experiment: '%s'", experimentName) +func (r Recorder) ExperimentSkipped(experimentName string, reason string) { + r.EventRecorder.Eventf(r.EventResource, corev1.EventTypeWarning, reason, "Experiment Job creation failed, skipping Chaos Experiment: '%s'", experimentName) + time.Sleep(5 * time.Second) } diff --git a/pkg/utils/types.go b/pkg/utils/types.go index 578910b0..0e5f095d 100644 --- a/pkg/utils/types.go +++ b/pkg/utils/types.go @@ -63,6 +63,17 @@ type Recorder struct { EventResource runtime.Object } +const ( + ExperimentDependencyCheckReason string = "ExperimentDependencyCheck" + ExperimentJobCreateReason string = "ExperimentJobCreate" + ExperimentJobCleanUpReason string = "ExperimentJobCleanUp" + ExperimentSkippedReason string = "ExperimentSkipped" + ExperimentEnvParseErrorReason string = "EnvParseError" + ExperimentNotFoundErrorReason string = "ExperimentNotFound" + ExperimentJobCreationErrorReason string = "JobCreationError" + ExperimentJobWatchErrorReason string = "JobWatchNotPermitted" +) + // GenerateClientSetFromKubeConfig will generation both ClientSets (k8s, and Litmus) func (clientSets *ClientSets) GenerateClientSetFromKubeConfig() error { config, err := getKubeConfig()