Skip to content

Commit

Permalink
Merge pull request #91 from chandankumar4/clone-0.8.0-RC1
Browse files Browse the repository at this point in the history
[Cherry-pick the changes to 0.8.0]
  • Loading branch information
Karthik Satchitanand authored Nov 13, 2019
2 parents 70dc933 + 03187ce commit e949f66
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 99 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
CHANGE_MINIKUBE_NONE_USER: true
REPONAME: litmuschaos
IMGNAME: chaos-operator
IMGTAG: latest
IMGTAG: ci
steps:
- checkout
- run:
Expand All @@ -41,7 +41,7 @@ jobs:
echo 'export PATH="$GOPATH/bin:$PATH"' >> workspace/env-vars
echo 'export REPONAME="litmuschaos"' >> workspace/env-vars
echo 'export IMGNAME="chaos-operator"' >> workspace/env-vars
echo 'export IMGTAG="latest"' >> workspace/env-vars
echo 'export IMGTAG="ci"' >> workspace/env-vars
cat workspace/env-vars >> $BASH_ENV
source $BASH_ENV
- run: make deps
Expand All @@ -61,7 +61,7 @@ jobs:
machine:
image: circleci/classic:201808-01
environment:
IMGTAG: latest
IMGTAG: ci
working_directory: ~/go/src/github.com/litmuschaos/chaos-operator
steps:
- attach_workspace:
Expand All @@ -77,7 +77,7 @@ jobs:
machine:
image: circleci/classic:201808-01
environment:
IMGTAG: latest
IMGTAG: ci
working_directory: ~/go/src/github.com/litmuschaos/chaos-operator
steps:
- attach_workspace:
Expand Down
3 changes: 3 additions & 0 deletions buildscripts/push
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ function push_release_image(){
echo "Pushing ${REPONAME}/${IMGNAME}:${CIRCLE_TAG} ..."
docker tag ${IMAGEID} ${REPONAME}/${IMGNAME}:${CIRCLE_TAG}
docker push ${REPONAME}/${IMGNAME}:${CIRCLE_TAG}
echo "Pushing ${REPONAME}/${IMGNAME}:latest ..."
docker tag ${IMAGEID} ${REPONAME}/${IMGNAME}:latest
docker push ${REPONAME}/${IMGNAME}:latest
fi;

}
Expand Down
4 changes: 2 additions & 2 deletions deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
serviceAccountName: litmus
containers:
- name: chaos-operator
image: litmuschaos/chaos-operator:latest
image: litmuschaos/chaos-operator:ci
command:
- chaos-operator
imagePullPolicy: IfNotPresent
Expand All @@ -28,4 +28,4 @@ spec:
fieldRef:
fieldPath: metadata.name
- name: OPERATOR_NAME
value: "chaos-operator"
value: "chaos-operator"
22 changes: 6 additions & 16 deletions pkg/controller/chaosengine/chaosengine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func getChaosRunnerENV(cr *litmuschaosv1alpha1.ChaosEngine, aExList []string) []
},
{
Name: "APP_NAMESPACE",
Value: cr.Namespace,
Value: cr.Spec.Appinfo.Appns,
},
{
Name: "EXPERIMENT_LIST",
Expand All @@ -282,7 +282,7 @@ func getChaosMonitorENV(cr *litmuschaosv1alpha1.ChaosEngine, aUUID types.UID) []
},
{
Name: "APP_NAMESPACE",
Value: cr.Namespace,
Value: cr.Spec.Appinfo.Appns,
},
}
}
Expand Down Expand Up @@ -333,7 +333,7 @@ func newMonitorPodForCR(engine chaosTypes.EngineInfo) (*corev1.Pod, error) {
return nil, errors.New("chaosengine got nil")
}
labels := map[string]string{
"app": engine.Instance.Name,
"app": "chaos-exporter",
"monitorFor": engine.Instance.Name,
}
monitorPod, err := pod.NewBuilder().
Expand All @@ -359,25 +359,15 @@ func newMonitorPodForCR(engine chaosTypes.EngineInfo) (*corev1.Pod, error) {

// 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")
}
labels := map[string]string{
"app": engine.Instance.Name,
"monitorFor": engine.Instance.Name,
}
serviceObj, err := service.NewBuilder().
WithName(engine.Instance.Name + "-monitor").
WithNamespace(engine.Instance.Namespace).
WithLabels(labels).
WithLabels(map[string]string{"app": "chaos-exporter"}).
WithPorts(getMonitoringENV()).
WithSelectorsNew(
map[string]string{
"app": engine.Instance.Name,
"monitorFor": engine.Instance.Name,
}).
Build()
WithSelectorsNew(map[string]string{"monitorFor": engine.Instance.Name}).Build()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -472,7 +462,7 @@ func (r *ReconcileChaosEngine) getChaosEngineInstance(request reconcile.Request)
}

// Get application details
func getApplicationDetail(ce *chaosTypes.EngineInfo) (*chaosTypes.EngineInfo , error) {
func getApplicationDetail(ce *chaosTypes.EngineInfo) (*chaosTypes.EngineInfo, error) {
applicationInfo := &chaosTypes.ApplicationInfo{}
appInfo, err := initializeApplicationInfo(ce.Instance, applicationInfo)
if err != nil {
Expand Down
141 changes: 73 additions & 68 deletions pkg/controller/chaosengine/chaosengine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package chaosengine

import (
"fmt"
"testing"
"strings"
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
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"
)
Expand Down Expand Up @@ -305,31 +306,32 @@ func TestInitializeApplicationInfo(t *testing.T) {
}
}
func TestGetChaosRunnerENV(t *testing.T) {
fakeEngineName := "Fake Engine"
fakeNameSpace := "Fake NameSpace"
fakeServiceAcc := "Fake Service Account"
fakeAppLabel := "Fake Label"
fakeAExList := []string{"fake string"}
fakeEngineName := "Fake Engine"
fakeNameSpace := "Fake NameSpace"
fakeServiceAcc := "Fake Service Account"
fakeAppLabel := "Fake Label"
fakeAExList := []string{"fake string"}

tests := map[string]struct {
instance *litmuschaosv1alpha1.ChaosEngine
aExList []string
expectedResult []corev1.EnvVar
instance *litmuschaosv1alpha1.ChaosEngine
aExList []string
expectedResult []corev1.EnvVar
}{
"Test Positive": {
instance: &litmuschaosv1alpha1.ChaosEngine{
ObjectMeta: metav1.ObjectMeta{
Name: fakeEngineName,
Namespace: fakeNameSpace,
},
Spec: litmuschaosv1alpha1.ChaosEngineSpec{
ChaosServiceAccount: fakeServiceAcc,
Appinfo: litmuschaosv1alpha1.ApplicationParams{
Applabel: fakeAppLabel,
},
ObjectMeta: metav1.ObjectMeta{
Name: fakeEngineName,
Namespace: fakeNameSpace,
},
Spec: litmuschaosv1alpha1.ChaosEngineSpec{
ChaosServiceAccount: fakeServiceAcc,
Appinfo: litmuschaosv1alpha1.ApplicationParams{
Applabel: fakeAppLabel,
Appns: fakeNameSpace,
},
},
aExList: fakeAExList,
},
aExList: fakeAExList,
expectedResult: []corev1.EnvVar{
{
Name: "CHAOSENGINE",
Expand Down Expand Up @@ -370,55 +372,58 @@ func TestGetChaosRunnerENV(t *testing.T) {
}
}


func TestGetChaosMonitorENV(t *testing.T) {
fakeEngineName := "Fake Engine"
fakeNameSpace := "fake NameSpace"
fakeAUUID := types.UID("fake UUID")
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,
},
},
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])
}
}
})
}
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])
}
}
})
}
}

5 changes: 3 additions & 2 deletions pkg/controller/resource/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package resource

import (
"fmt"
"k8s.io/api/apps/v1"

v1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"

Expand All @@ -24,7 +25,7 @@ func CheckDeploymentAnnotation(clientSet *kubernetes.Clientset, ce *chaosTypes.E
if err != nil {
return ce, err
}
chaosTypes.Log.Info("Deployment chaos candidate, appName:", ce.AppName," appUUID: ", ce.AppUUID)
chaosTypes.Log.Info("Deployment chaos candidate:", "appName: ", ce.AppName, " appUUID: ", ce.AppUUID)
}
return ce, nil
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/controller/resource/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package resource

import (
"fmt"
"k8s.io/api/apps/v1"

v1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"

Expand All @@ -24,7 +25,7 @@ func CheckStatefulSetAnnotation(clientSet *kubernetes.Clientset, ce *chaosTypes.
if err != nil {
return ce, err
}
chaosTypes.Log.Info("Statefulset chaos candidate, appName:", ce.AppName," appUUID: ", ce.AppUUID)
chaosTypes.Log.Info("Statefulset chaos candidate:", "appName: ", ce.AppName, " appUUID: ", ce.AppUUID)
}
return ce, nil
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ import (

var (
// AppLabelKey contains the application label key
AppLabelKey string
AppLabelKey string

// AppLabelValue contains the application label value
AppLabelValue string
AppLabelValue string

// Log with default name ie: controller_chaosengine
Log = logf.Log.WithName("controller_chaosengine")
Log = logf.Log.WithName("controller_chaosengine")

// DefaultRunnerImage contains the default value of runner resource
DefaultRunnerImage = "litmuschaos/ansible-runner:ci"
DefaultRunnerImage = "litmuschaos/ansible-runner:latest"

// DefaultMonitorImage contains the default value of monitor resource
DefaultMonitorImage = "litmuschaos/chaos-exporter:ci"
DefaultMonitorImage = "litmuschaos/chaos-exporter:latest"
)

// ApplicationInfo contains the chaos details for target application
Expand Down

0 comments on commit e949f66

Please sign in to comment.