From 8566329acdbddfde72b662aa332cbd39f92bdc65 Mon Sep 17 00:00:00 2001 From: Aaron Lunsford Date: Wed, 31 Jul 2024 15:24:57 -0400 Subject: [PATCH 1/6] redo branch from main --- api/v1alpha1/privateloadzone_types.go | 1 + api/v1alpha1/zz_generated.deepcopy.go | 7 +++++++ config/crd/bases/k6.io_privateloadzones.yaml | 16 ++++++++++++++++ pkg/testrun/plz.go | 2 ++ 4 files changed, 26 insertions(+) diff --git a/api/v1alpha1/privateloadzone_types.go b/api/v1alpha1/privateloadzone_types.go index fa033441..d827ba96 100644 --- a/api/v1alpha1/privateloadzone_types.go +++ b/api/v1alpha1/privateloadzone_types.go @@ -34,6 +34,7 @@ import ( type PrivateLoadZoneSpec struct { Token string `json:"token"` Resources corev1.ResourceRequirements `json:"resources"` + Tolerations []corev1.Toleration `json:tolerations` ServiceAccountName string `json:"serviceAccountName,omitempty"` NodeSelector map[string]string `json:"nodeSelector,omitempty"` Image string `json:"image,omitempty"` diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index e65a4851..8cae893f 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -380,6 +380,13 @@ func (in *PrivateLoadZoneList) DeepCopyObject() runtime.Object { func (in *PrivateLoadZoneSpec) DeepCopyInto(out *PrivateLoadZoneSpec) { *out = *in in.Resources.DeepCopyInto(&out.Resources) + if in.Tolerations != nil { + in, out := &in.Tolerations, &out.Tolerations + *out = make([]v1.Toleration, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } if in.NodeSelector != nil { in, out := &in.NodeSelector, &out.NodeSelector *out = make(map[string]string, len(*in)) diff --git a/config/crd/bases/k6.io_privateloadzones.yaml b/config/crd/bases/k6.io_privateloadzones.yaml index 3ce91732..ee08add9 100644 --- a/config/crd/bases/k6.io_privateloadzones.yaml +++ b/config/crd/bases/k6.io_privateloadzones.yaml @@ -71,6 +71,22 @@ spec: x-kubernetes-int-or-string: true type: object type: object + tolerations: + items: + properties: + effect: + type: string + key: + type: string + operator: + type: string + tolerationSeconds: + format: int64 + type: integer + value: + type: string + type: object + type: array serviceAccountName: type: string token: diff --git a/pkg/testrun/plz.go b/pkg/testrun/plz.go index bbe42ef7..95b716dc 100644 --- a/pkg/testrun/plz.go +++ b/pkg/testrun/plz.go @@ -51,6 +51,7 @@ func NewPLZTestRun(plz *v1alpha1.PrivateLoadZone, trData *cloud.TestRunData, ing ServiceAccountName: plz.Spec.ServiceAccountName, NodeSelector: plz.Spec.NodeSelector, Resources: plz.Spec.Resources, + Tolerations: plz.Spec.Tolerations, Volumes: []corev1.Volume{ volume, }, @@ -66,6 +67,7 @@ func NewPLZTestRun(plz *v1alpha1.PrivateLoadZone, trData *cloud.TestRunData, ing ServiceAccountName: plz.Spec.ServiceAccountName, NodeSelector: plz.Spec.NodeSelector, ImagePullSecrets: plz.Spec.ImagePullSecrets, + Tolerations: plz.Spec.Tolerations, }, Script: v1alpha1.K6Script{ LocalFile: "/test/archive.tar", From baeb2813a8b5781c52eafb082ef62ad98fdf8929 Mon Sep 17 00:00:00 2001 From: Aaron Lunsford Date: Wed, 31 Jul 2024 15:27:22 -0400 Subject: [PATCH 2/6] add missing quotes --- api/v1alpha1/privateloadzone_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v1alpha1/privateloadzone_types.go b/api/v1alpha1/privateloadzone_types.go index d827ba96..10319276 100644 --- a/api/v1alpha1/privateloadzone_types.go +++ b/api/v1alpha1/privateloadzone_types.go @@ -34,7 +34,7 @@ import ( type PrivateLoadZoneSpec struct { Token string `json:"token"` Resources corev1.ResourceRequirements `json:"resources"` - Tolerations []corev1.Toleration `json:tolerations` + Tolerations []corev1.Toleration `json:"tolerations"` ServiceAccountName string `json:"serviceAccountName,omitempty"` NodeSelector map[string]string `json:"nodeSelector,omitempty"` Image string `json:"image,omitempty"` From 3e0aa870b52c88c8672a941c1ced5ed49f653871 Mon Sep 17 00:00:00 2001 From: Aaron Lunsford Date: Thu, 1 Aug 2024 09:45:44 -0400 Subject: [PATCH 3/6] add tolerations to the plz tests --- pkg/testrun/plz_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/testrun/plz_test.go b/pkg/testrun/plz_test.go index 0cdebef7..07a7ccc2 100644 --- a/pkg/testrun/plz_test.go +++ b/pkg/testrun/plz_test.go @@ -2,6 +2,7 @@ package testrun import ( "fmt" + "log" "testing" "github.com/go-test/deep" @@ -69,6 +70,14 @@ func Test_NewPLZTestRun(t *testing.T) { corev1.ResourceCPU: resource.MustParse("200m"), corev1.ResourceMemory: resource.MustParse("1G"), } + tolerations = []corev1.Toleration{ + { + Key: "someKey", + Operator: corev1.TolerationOpEqual, + Value: "someValue", + Effect: corev1.TaintEffectNoSchedule, + }, + } someTestRunID = 6543 someRunnerImage = "grafana/k6:0.52.0" someInstances = 10 @@ -95,8 +104,10 @@ func Test_NewPLZTestRun(t *testing.T) { optionalFieldsTestRun.Namespace = someNS optionalFieldsTestRun.Spec.Runner.ServiceAccountName = someSA optionalFieldsTestRun.Spec.Runner.NodeSelector = someNodeSelector + optionalFieldsTestRun.Spec.Runner.Tolerations = tolerations optionalFieldsTestRun.Spec.Starter.ServiceAccountName = someSA optionalFieldsTestRun.Spec.Starter.NodeSelector = someNodeSelector + optionalFieldsTestRun.Spec.Starter.Tolerations = tolerations cloudFieldsTestRun = requiredFieldsTestRun // build up on top of required field case cloudFieldsTestRun.ObjectMeta.Name = TestName(fmt.Sprintf("%d", someTestRunID)) @@ -166,6 +177,7 @@ func Test_NewPLZTestRun(t *testing.T) { Resources: corev1.ResourceRequirements{ Limits: resourceLimits, }, + Tolerations: tolerations, ServiceAccountName: someSA, NodeSelector: someNodeSelector, }, @@ -225,6 +237,7 @@ func Test_NewPLZTestRun(t *testing.T) { t.Parallel() got := NewPLZTestRun(testCase.plz, testCase.cloudData, testCase.ingestUrl) if diff := deep.Equal(got, testCase.expected); diff != nil { + log.Println(testCase.name) t.Errorf("NewPLZTestRun returned unexpected data, diff: %s", diff) } }) From fa755f678c7beea1f9b8459adc58ee09c9b0db03 Mon Sep 17 00:00:00 2001 From: Aaron Lunsford Date: Thu, 1 Aug 2024 12:08:07 -0400 Subject: [PATCH 4/6] add tolerations to the helm chart PLZ crd --- charts/k6-operator/templates/crds/plz.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/charts/k6-operator/templates/crds/plz.yaml b/charts/k6-operator/templates/crds/plz.yaml index 65e1da9a..744130fb 100644 --- a/charts/k6-operator/templates/crds/plz.yaml +++ b/charts/k6-operator/templates/crds/plz.yaml @@ -76,6 +76,22 @@ spec: x-kubernetes-int-or-string: true type: object type: object + tolerations: + items: + properties: + effect: + type: string + key: + type: string + operator: + type: string + tolerationSeconds: + format: int64 + type: integer + value: + type: string + type: object + type: array serviceAccountName: type: string token: From cce85fac147004b11b69e138b6f64e49fc9724e8 Mon Sep 17 00:00:00 2001 From: Aaron Lunsford Date: Thu, 1 Aug 2024 13:05:56 -0400 Subject: [PATCH 5/6] remove extraneous log line --- pkg/testrun/plz_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/testrun/plz_test.go b/pkg/testrun/plz_test.go index 07a7ccc2..c3f1c21d 100644 --- a/pkg/testrun/plz_test.go +++ b/pkg/testrun/plz_test.go @@ -2,7 +2,6 @@ package testrun import ( "fmt" - "log" "testing" "github.com/go-test/deep" @@ -237,7 +236,6 @@ func Test_NewPLZTestRun(t *testing.T) { t.Parallel() got := NewPLZTestRun(testCase.plz, testCase.cloudData, testCase.ingestUrl) if diff := deep.Equal(got, testCase.expected); diff != nil { - log.Println(testCase.name) t.Errorf("NewPLZTestRun returned unexpected data, diff: %s", diff) } }) From 16ee5675589877c08b609b5175612d09ca973b97 Mon Sep 17 00:00:00 2001 From: Aaron Lunsford Date: Wed, 7 Aug 2024 10:01:55 -0400 Subject: [PATCH 6/6] add omitempty to make tolerations optional --- api/v1alpha1/privateloadzone_types.go | 2 +- config/crd/bases/k6.io_privateloadzones.yaml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/api/v1alpha1/privateloadzone_types.go b/api/v1alpha1/privateloadzone_types.go index 10319276..f4e0852e 100644 --- a/api/v1alpha1/privateloadzone_types.go +++ b/api/v1alpha1/privateloadzone_types.go @@ -34,7 +34,7 @@ import ( type PrivateLoadZoneSpec struct { Token string `json:"token"` Resources corev1.ResourceRequirements `json:"resources"` - Tolerations []corev1.Toleration `json:"tolerations"` + Tolerations []corev1.Toleration `json:"tolerations,omitempty"` ServiceAccountName string `json:"serviceAccountName,omitempty"` NodeSelector map[string]string `json:"nodeSelector,omitempty"` Image string `json:"image,omitempty"` diff --git a/config/crd/bases/k6.io_privateloadzones.yaml b/config/crd/bases/k6.io_privateloadzones.yaml index ee08add9..2b6a8dbc 100644 --- a/config/crd/bases/k6.io_privateloadzones.yaml +++ b/config/crd/bases/k6.io_privateloadzones.yaml @@ -71,6 +71,10 @@ spec: x-kubernetes-int-or-string: true type: object type: object + serviceAccountName: + type: string + token: + type: string tolerations: items: properties: @@ -87,10 +91,6 @@ spec: type: string type: object type: array - serviceAccountName: - type: string - token: - type: string required: - resources - token