Skip to content

Commit

Permalink
Merge branch 'master' into update-ga4-tag
Browse files Browse the repository at this point in the history
  • Loading branch information
neelanjan00 authored Mar 14, 2024
2 parents 43a845f + f1afe83 commit ba290f0
Show file tree
Hide file tree
Showing 20 changed files with 358 additions and 85 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
# Install golang
- uses: actions/setup-go@v2
with:
go-version: 1.19
go-version: 1.20.0

# Checkout to the latest commit
# On specific directory/path
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
# Install golang
- uses: actions/setup-go@v2
with:
go-version: 1.19
go-version: 1.20.0

# Checkout to the latest commit
# On specific directory/path
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions/setup-go@v2
with:
go-version: 1.19
go-version: 1.20.0

- name: Setting up GOPATH
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
# Install golang
- uses: actions/setup-go@v2
with:
go-version: 1.19
go-version: 1.20.0

# Checkout to the latest commit
# On specific directory/path
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
# Install golang
- uses: actions/setup-go@v2
with:
go-version: 1.19
go-version: 1.20.0

#Install and configure a kind cluster
- name: Installing Prerequisites (K3S Cluster)
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
# Install golang
- uses: actions/setup-go@v2
with:
go-version: 1.19
go-version: 1.20.0

# Checkout to the latest commit
# On specific directory/path
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
# Install golang
- uses: actions/setup-go@v2
with:
go-version: 1.19
go-version: 1.20.0

#Install and configure a kind cluster
- name: Installing Prerequisites (K3S Cluster)
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,21 @@ gofmt-check:
.PHONY: build-chaos-operator
build-chaos-operator:
@echo "-------------------------"
@echo "--> Build go-runner image"
@echo "--> Build go-runner image"
@echo "-------------------------"
@docker buildx build --file build/Dockerfile --progress plane --no-cache --platform linux/arm64,linux/amd64 --tag $(DOCKER_REGISTRY)/$(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) .
@docker buildx build --file build/Dockerfile --progress plain --no-cache --platform linux/arm64,linux/amd64 --tag $(DOCKER_REGISTRY)/$(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) .

.PHONY: push-chaos-operator
push-chaos-operator:
@echo "------------------------------"
@echo "--> Pushing image"
@echo "--> Pushing image"
@echo "------------------------------"
@docker buildx build --file build/Dockerfile --progress plane --no-cache --push --platform linux/arm64,linux/amd64 --tag $(DOCKER_REGISTRY)/$(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) .
@docker buildx build --file build/Dockerfile --progress plain --no-cache --push --platform linux/arm64,linux/amd64 --tag $(DOCKER_REGISTRY)/$(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) .

.PHONY: build-amd64
build-amd64:
@echo "-------------------------"
@echo "--> Build go-runner image"
@echo "--> Build go-runner image"
@echo "-------------------------"
@docker build -f build/Dockerfile --no-cache -t $(DOCKER_REGISTRY)/$(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) . --build-arg TARGETPLATFORM="linux/amd64"

Expand Down
4 changes: 4 additions & 0 deletions api/litmuschaos/v1alpha1/chaosengine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ type SourceDetails struct {
Privileged bool `json:"privileged,omitempty"`
// NodeSelector for the source pod
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// Tolerations for the source pod
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
// Volumes for the source pod
Volumes []corev1.Volume `json:"volumes,omitempty"`
// VolumesMount for the source pod
Expand Down Expand Up @@ -436,6 +438,8 @@ type RunProperty struct {
// EvaluationTimeout is the timeout window in which the SLO metrics
// will be fetched and will be evaluated
EvaluationTimeout string `json:"evaluationTimeout,omitempty"`
// Verbosity contains flags for type of logging while running the Continuous and onChaos Probes
Verbosity string `json:"verbosity,omitempty"`
// StopOnFailure contains flag to stop/continue experiment execution, if probe fails
// it will stop the experiment execution, if provided true
// it will continue the experiment execution, if provided false or not provided(default case)
Expand Down
7 changes: 7 additions & 0 deletions api/litmuschaos/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions controllers/chaosengine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ func getChaosRunnerLabels(cr *litmuschaosv1alpha1.ChaosEngine) map[string]string

// newGoRunnerPodForCR defines a new go-based Runner Pod
func (r *ChaosEngineReconciler) newGoRunnerPodForCR(engine *chaosTypes.EngineInfo) (*corev1.Pod, error) {
var experiment litmuschaosv1alpha1.ChaosExperiment
if err := r.Client.Get(context.TODO(), types.NamespacedName{Name: engine.Instance.Spec.Experiments[0].Name, Namespace: engine.Instance.Namespace}, &experiment); err != nil {
return nil, err
}

engine.VolumeOpts.VolumeOperations(engine.Instance.Spec.Components.Runner.ConfigMaps, engine.Instance.Spec.Components.Runner.Secrets)

containerForRunner := container.NewBuilder().
Expand Down Expand Up @@ -196,6 +201,10 @@ func (r *ChaosEngineReconciler) newGoRunnerPodForCR(engine *chaosTypes.EngineInf
containerForRunner.WithResourceRequirements(engine.Instance.Spec.Components.Runner.Resources)
}

if !reflect.DeepEqual(experiment.Spec.Definition.SecurityContext.ContainerSecurityContext, corev1.SecurityContext{}) {
containerForRunner.WithSecurityContext(experiment.Spec.Definition.SecurityContext.ContainerSecurityContext)
}

podForRunner := pod.NewBuilder().
WithName(engine.Instance.Name + "-runner").
WithNamespace(engine.Instance.Namespace).
Expand All @@ -221,6 +230,10 @@ func (r *ChaosEngineReconciler) newGoRunnerPodForCR(engine *chaosTypes.EngineInf
podForRunner.WithImagePullSecrets(engine.Instance.Spec.Components.Runner.ImagePullSecrets)
}

if !reflect.DeepEqual(experiment.Spec.Definition.SecurityContext.PodSecurityContext, corev1.PodSecurityContext{}) {
podForRunner.WithSecurityContext(experiment.Spec.Definition.SecurityContext.PodSecurityContext)
}

runnerPod, err := podForRunner.Build()
if err != nil {
return nil, err
Expand Down
110 changes: 109 additions & 1 deletion controllers/chaosengine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ func TestNewGoRunnerPodForCR(t *testing.T) {
},
},
},
Experiments: []v1alpha1.ExperimentList{
{
Name: "pod-delete",
},
},
},
},

Expand All @@ -355,6 +360,11 @@ func TestNewGoRunnerPodForCR(t *testing.T) {
},
},
},
Experiments: []v1alpha1.ExperimentList{
{
Name: "pod-delete",
},
},
},
},

Expand Down Expand Up @@ -382,6 +392,11 @@ func TestNewGoRunnerPodForCR(t *testing.T) {
},
},
},
Experiments: []v1alpha1.ExperimentList{
{
Name: "pod-delete",
},
},
},
},

Expand Down Expand Up @@ -409,6 +424,11 @@ func TestNewGoRunnerPodForCR(t *testing.T) {
},
},
},
Experiments: []v1alpha1.ExperimentList{
{
Name: "pod-delete",
},
},
},
},

Expand All @@ -421,6 +441,13 @@ func TestNewGoRunnerPodForCR(t *testing.T) {
engine: chaosTypes.EngineInfo{
Instance: &v1alpha1.ChaosEngine{
ObjectMeta: metav1.ObjectMeta{},
Spec: v1alpha1.ChaosEngineSpec{
Experiments: []v1alpha1.ExperimentList{
{
Name: "pod-delete",
},
},
},
},
AppExperiments: []string{"exp-1"},
},
Expand All @@ -435,6 +462,11 @@ func TestNewGoRunnerPodForCR(t *testing.T) {
},
Spec: v1alpha1.ChaosEngineSpec{
ChaosServiceAccount: "fake-serviceAccount",
Experiments: []v1alpha1.ExperimentList{
{
Name: "pod-delete",
},
},
},
},

Expand All @@ -451,6 +483,11 @@ func TestNewGoRunnerPodForCR(t *testing.T) {
},
Spec: v1alpha1.ChaosEngineSpec{
ChaosServiceAccount: "fake-serviceAccount",
Experiments: []v1alpha1.ExperimentList{
{
Name: "pod-delete",
},
},
},
},

Expand All @@ -472,6 +509,11 @@ func TestNewGoRunnerPodForCR(t *testing.T) {
Image: "",
},
},
Experiments: []v1alpha1.ExperimentList{
{
Name: "pod-delete",
},
},
},
},

Expand All @@ -483,6 +525,15 @@ func TestNewGoRunnerPodForCR(t *testing.T) {
for name, mock := range tests {
t.Run(name, func(t *testing.T) {
r := CreateFakeClient(t)
exp := v1alpha1.ChaosExperiment{
ObjectMeta: metav1.ObjectMeta{
Name: "pod-delete",
Namespace: "test",
},
}
if err := r.Client.Create(context.TODO(), &exp); err != nil {
t.Fatalf("Test %q failed: expected error not to be nil", name)
}
_, err := r.newGoRunnerPodForCR(&mock.engine)
if mock.isErr && err == nil {
t.Fatalf("Test %q failed: expected error not to be nil", name)
Expand Down Expand Up @@ -959,6 +1010,11 @@ func TestCheckEngineRunnerPod(t *testing.T) {
Image: "fake-runner-image",
},
},
Experiments: []v1alpha1.ExperimentList{
{
Name: "exp-1",
},
},
},
},

Expand All @@ -980,6 +1036,11 @@ func TestCheckEngineRunnerPod(t *testing.T) {
Image: "fake-runner-image",
},
},
Experiments: []v1alpha1.ExperimentList{
{
Name: "exp-1",
},
},
},
},

Expand All @@ -1002,6 +1063,11 @@ func TestCheckEngineRunnerPod(t *testing.T) {
Image: "fake-runner-image",
},
},
Experiments: []v1alpha1.ExperimentList{
{
Name: "exp-1",
},
},
},
},

Expand All @@ -1024,6 +1090,11 @@ func TestCheckEngineRunnerPod(t *testing.T) {
Image: "fake-runner-image",
},
},
Experiments: []v1alpha1.ExperimentList{
{
Name: "exp-1",
},
},
},
},

Expand All @@ -1036,6 +1107,13 @@ func TestCheckEngineRunnerPod(t *testing.T) {
engine: chaosTypes.EngineInfo{
Instance: &v1alpha1.ChaosEngine{
ObjectMeta: metav1.ObjectMeta{},
Spec: v1alpha1.ChaosEngineSpec{
Experiments: []v1alpha1.ExperimentList{
{
Name: "exp-1",
},
},
},
},

AppExperiments: []string{"exp-1"},
Expand All @@ -1051,6 +1129,11 @@ func TestCheckEngineRunnerPod(t *testing.T) {
},
Spec: v1alpha1.ChaosEngineSpec{
ChaosServiceAccount: "fake-serviceAccount",
Experiments: []v1alpha1.ExperimentList{
{
Name: "exp-1",
},
},
},
},

Expand Down Expand Up @@ -1099,6 +1182,15 @@ func TestCheckEngineRunnerPod(t *testing.T) {
for name, mock := range tests {
t.Run(name, func(t *testing.T) {
r := CreateFakeClient(t)
exp := v1alpha1.ChaosExperiment{
ObjectMeta: metav1.ObjectMeta{
Name: "exp-1",
Namespace: "test",
},
}
if err := r.Client.Create(context.TODO(), &exp); err != nil {
t.Fatalf("Test %q failed: expected error not to be nil", name)
}
reqLogger := chaosTypes.Log.WithValues()
err := r.checkEngineRunnerPod(&mock.engine, reqLogger)
if mock.isErr && err == nil {
Expand Down Expand Up @@ -1506,6 +1598,15 @@ func TestReconcileForCreationAndRunning(t *testing.T) {
for name, mock := range tests {
t.Run(name, func(t *testing.T) {
r := CreateFakeClient(t)
exp := v1alpha1.ChaosExperiment{
ObjectMeta: metav1.ObjectMeta{
Name: "exp-1",
Namespace: "test",
},
}
if err := r.Client.Create(context.TODO(), &exp); err != nil {
t.Fatalf("Test %q failed: expected error not to be nil", name)
}
reqLogger := chaosTypes.Log.WithValues()
_, err := r.reconcileForCreationAndRunning(&mock.engine, reqLogger)
if mock.isErr && err == nil {
Expand Down Expand Up @@ -1534,11 +1635,18 @@ func CreateFakeClient(t *testing.T) *ChaosEngineReconciler {
},
}

exp := &v1alpha1.ChaosExperiment{
ObjectMeta: metav1.ObjectMeta{
Labels: make(map[string]string),
Name: "dummyexp",
},
}

chaosResultList := &v1alpha1.ChaosResultList{
Items: []v1alpha1.ChaosResult{},
}

s.AddKnownTypes(v1alpha1.SchemeGroupVersion, engineR, chaosResultList)
s.AddKnownTypes(v1alpha1.SchemeGroupVersion, engineR, chaosResultList, exp)

recorder := record.NewFakeRecorder(1024)

Expand Down
Loading

0 comments on commit ba290f0

Please sign in to comment.