[cherry-pick]: V1.8.x tracker (#279)

* chore(appinfo): Add ability to provide appinfo as optional (#273)

Signed-off-by: shubhamchaudhary <shubham.chaudhary@mayadata.io>

* chore(resourceRequirements): Adding resource requirements in chaos pod (#275)

Signed-off-by: shubhamchaudhary <shubham.chaudhary@mayadata.io>
This commit is contained in:
Shubham Chaudhary 2020-09-29 19:13:38 +05:30 committed by GitHub
parent c5e67ff56e
commit 8121b4fce2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 29 deletions

View File

@ -46,10 +46,10 @@ spec:
properties:
appkind:
type: string
pattern: ^(deployment|statefulset|daemonset|deploymentconfig)$
pattern: ^(^$|deployment|statefulset|daemonset|deploymentconfig)$
applabel:
type: string
pattern: ([a-z0-9A-Z_\.-/]+)=([a-z0-9A-Z_\.-/_]+)
pattern: (([a-z0-9A-Z_\.-/]+)=([a-z0-9A-Z_\.-/_]+)|^$)
appns:
type: string
auxiliaryAppInfo:

View File

@ -45,9 +45,9 @@ spec:
properties:
appkind:
type: string
pattern: ^(deployment|statefulset|daemonset|deploymentconfig)$
pattern: ^(^$|deployment|statefulset|daemonset|deploymentconfig)$
applabel:
pattern: ([a-z0-9A-Z_\.-/]+)=([a-z0-9A-Z_\.-/_]+)
pattern: (([a-z0-9A-Z_\.-/]+)=([a-z0-9A-Z_\.-/_]+)|^$)
type: string
appns:
type: string

View File

@ -27,7 +27,7 @@ import (
// to create a chaos profile
type ChaosEngineSpec struct {
//Appinfo contains deployment details of AUT
Appinfo ApplicationParams `json:"appinfo"`
Appinfo ApplicationParams `json:"appinfo,omitempty"`
//AnnotationCheck defines whether annotation check is allowed or not. It can be true or false
AnnotationCheck string `json:"annotationCheck,omitempty"`
//ChaosServiceAccount is the SvcAcc specified for chaos runner pods
@ -112,11 +112,11 @@ type ChaosEngineStatus struct {
// Controller expects AUT to be annotated with litmuschaos.io/chaos: "true" to run chaos
type ApplicationParams struct {
//Namespace of the AUT
Appns string `json:"appns"`
Appns string `json:"appns,omitempty"`
//Unique label of the AUT
Applabel string `json:"applabel"`
Applabel string `json:"applabel,omitempty"`
//kind of application
AppKind string `json:"appkind"`
AppKind string `json:"appkind,omitempty"`
}
// ComponentParams defines information about the runner
@ -262,13 +262,14 @@ type RunProperty struct {
// ExperimentComponents contains ENV, Configmaps and Secrets
type ExperimentComponents struct {
ENV []ExperimentENV `json:"env,omitempty"`
ConfigMaps []ConfigMap `json:"configMaps,omitempty"`
Secrets []Secret `json:"secrets,omitempty"`
ExperimentAnnotations map[string]string `json:"experimentannotation,omitempty"`
ExperimentImage string `json:"experimentImage,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
StatusCheckTimeouts StatusCheckTimeout `json:"statusCheckTimeouts,omitempty"`
ENV []ExperimentENV `json:"env,omitempty"`
ConfigMaps []ConfigMap `json:"configMaps,omitempty"`
Secrets []Secret `json:"secrets,omitempty"`
ExperimentAnnotations map[string]string `json:"experimentannotation,omitempty"`
ExperimentImage string `json:"experimentImage,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
StatusCheckTimeouts StatusCheckTimeout `json:"statusCheckTimeouts,omitempty"`
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
}
// StatusCheckTimeout contains Delay and timeouts for the status checks

View File

@ -486,6 +486,7 @@ func (in *ExperimentComponents) DeepCopyInto(out *ExperimentComponents) {
}
}
out.StatusCheckTimeouts = in.StatusCheckTimeouts
in.Resources.DeepCopyInto(&out.Resources)
return
}

View File

@ -176,10 +176,10 @@ func getChaosRunnerENV(cr *litmuschaosv1alpha1.ChaosEngine, aExList []string, Cl
var appNS string
if cr.Spec.Appinfo.Appns != "" {
appNS = cr.Spec.Appinfo.Appns
} else {
appNS = cr.Namespace
}
appNS = cr.Spec.Appinfo.Appns
} else {
appNS = cr.Namespace
}
return []corev1.EnvVar{
{
@ -252,21 +252,25 @@ func initializeApplicationInfo(instance *litmuschaosv1alpha1.ChaosEngine, appInf
if instance == nil {
return nil, errors.New("empty chaosengine")
}
appLabel := strings.Split(instance.Spec.Appinfo.Applabel, "=")
chaosTypes.AppLabelKey = appLabel[0]
chaosTypes.AppLabelValue = appLabel[1]
appInfo.Label = make(map[string]string)
appInfo.Label[chaosTypes.AppLabelKey] = chaosTypes.AppLabelValue
if instance.Spec.Appinfo.Applabel != "" {
appLabel := strings.Split(instance.Spec.Appinfo.Applabel, "=")
chaosTypes.AppLabelKey = appLabel[0]
chaosTypes.AppLabelValue = appLabel[1]
appInfo.Label = make(map[string]string)
appInfo.Label[chaosTypes.AppLabelKey] = chaosTypes.AppLabelValue
}
if instance.Spec.Appinfo.Appns != "" {
appInfo.Namespace = instance.Spec.Appinfo.Appns
} else {
appInfo.Namespace = instance.Namespace
}
appInfo.Kind = instance.Spec.Appinfo.AppKind
appInfo.ExperimentList = instance.Spec.Experiments
appInfo.ServiceAccountName = instance.Spec.ChaosServiceAccount
appInfo.Kind = instance.Spec.Appinfo.AppKind
return appInfo, nil
}
@ -400,7 +404,7 @@ func (r *ReconcileChaosEngine) reconcileForDelete(engine *chaosTypes.EngineInfo,
return reconcile.Result{}, err
}
if len(chaosPodList.Items)!= 0 {
if len(chaosPodList.Items) != 0 {
chaosTypes.Log.Info("Performing a force delete of chaos resources", "chaosengine", engine.Instance.Name)
err := r.forceRemoveChaosResources(engine, request)
if err != nil {
@ -412,9 +416,9 @@ func (r *ReconcileChaosEngine) reconcileForDelete(engine *chaosTypes.EngineInfo,
if engine.Instance.ObjectMeta.Finalizers != nil {
engine.Instance.ObjectMeta.Finalizers = utils.RemoveString(engine.Instance.ObjectMeta.Finalizers, "chaosengine.litmuschaos.io/finalizer")
//we are repeating this condition/check here as we want the events for 'ChaosEngineStopped'
//we are repeating this condition/check here as we want the events for 'ChaosEngineStopped'
//generated only after successful finalizer removal
if len(chaosPodList.Items)!= 0 {
if len(chaosPodList.Items) != 0 {
r.recorder.Eventf(engine.Instance, corev1.EventTypeNormal, "ChaosEngineStopped", "Chaos resources deleted successfully")
} else {
r.recorder.Eventf(engine.Instance, corev1.EventTypeWarning, "ChaosEngineStopped", "Chaos stopped due to failed app identification")
@ -651,7 +655,7 @@ func (r *ReconcileChaosEngine) validateAnnontatedApplication(engine *chaosTypes.
// Determine whether apps with matching labels have chaos annotation set to true
engine, err = resource.CheckChaosAnnotation(engine, clientSet, *dynamicClient)
if err != nil {
//using an event msg that indicates the app couldn't be identified. By this point in execution,
//using an event msg that indicates the app couldn't be identified. By this point in execution,
//if the engine could not be found or accessed, it would already be caught in r.initEngine & getApplicationDetail
r.recorder.Eventf(engine.Instance, corev1.EventTypeWarning, "ChaosResourcesOperationFailed", "Unable to filter app by specified info")
chaosTypes.Log.Info("Annotation check failed with", "error:", err)