nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: grafana/k6-operator
Pull request #215 (2023-04-18 08:36:04)

Assigning securityContext in k6 initializer
for https://github.com/grafana/k6-operator/issues/210


CLAassistant: [![CLA assistant check](https://cla-assistant.io/pull/badge/not_signed)](https://cla-assistant.io/grafana/k6-operator?pullRequest=215) <br/>Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla-assistant.io/grafana/k6-operator?pullRequest=215) before we can accept your contribution.<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla-assistant.io/check/grafana/k6-operator?pullRequest=215) it.</sub>
yorugac: Hi @mohamediag! Thank you for working on this one. We had a bit of funny timing as PR #175 was simultaneously updated and merged in :sweat_smile: Could you please rebase your branch on main and adjust your changes for the new names of vars? Thanks!
mohamediag: Hi @yorugac , ha great that the other one has been merged - thanks
Rebase done and PR amended

Patch:
diff --git a/pkg/resources/jobs/initializer.go b/pkg/resources/jobs/initializer.go
index 3fe3963..0b310c1 100644
--- a/pkg/resources/jobs/initializer.go
+++ b/pkg/resources/jobs/initializer.go
@@ -104,6 +104,7 @@ func NewInitializerJob(k6 *v1alpha1.K6, argLine string) (*batchv1.Job, error) {
 					Affinity:                     k6.Spec.Initializer.Affinity,
 					NodeSelector:                 k6.Spec.Initializer.NodeSelector,
 					Tolerations:                  k6.Spec.Initializer.Tolerations,
+					SecurityContext:              &k6.Spec.Initializer.SecurityContext,
 					RestartPolicy:                corev1.RestartPolicyNever,
 					ImagePullSecrets:             k6.Spec.Initializer.ImagePullSecrets,
 					Containers: []corev1.Container{


Test patch:
diff --git a/pkg/resources/jobs/initializer_test.go b/pkg/resources/jobs/initializer_test.go
index a1aa3fd..0654a0b 100644
--- a/pkg/resources/jobs/initializer_test.go
+++ b/pkg/resources/jobs/initializer_test.go
@@ -53,6 +53,7 @@ func TestNewInitializerJob(t *testing.T) {
 					Affinity:                     nil,
 					NodeSelector:                 nil,
 					RestartPolicy:                corev1.RestartPolicyNever,
+					SecurityContext:              &corev1.PodSecurityContext{},
 					Containers: []corev1.Container{
 						{
 							Image:           "ghcr.io/grafana/operator:latest-runner",
Repository: allegro/marathon-consul
Pull request #266 (2017-09-29 16:32:54)

Don't sync TASK_KILLING services
Please review.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/13499877/badge)](https://coveralls.io/builds/13499877)

Coverage remained the same at 90.066% when pulling **08e902c62fdc1d72e5e80769090b688cbb68574d on cynial:master** into **d9bfb8f005f64dec3ab5ed1ff57b16043108853a on allegro:master**.

cynial: I'll do it.
coveralls: 
[![Coverage Status](https://coveralls.io/builds/13507146/badge)](https://coveralls.io/builds/13507146)

Coverage remained the same at 90.066% when pulling **b5a348cfdd85218ae39192930e60545355bfd7fe on cynial:master** into **d9bfb8f005f64dec3ab5ed1ff57b16043108853a on allegro:master**.

janisz: LGTM. I'll test it manually and merge.

Patch:
diff --git a/apps/task.go b/apps/task.go
index 7f04d7b..c4a98ec 100644
--- a/apps/task.go
+++ b/apps/task.go
@@ -14,6 +14,7 @@ type Task struct {
 	// As well as for Marathon Task.
 	Timestamp          time.Timestamp      `json:"timestamp"`
 	TaskStatus         string              `json:"taskStatus"`
+	State              string              `json:"state"`
 	AppID              AppID               `json:"appId"`
 	Host               string              `json:"host"`
 	Ports              []int               `json:"ports"`
@@ -69,7 +70,7 @@ func (t Task) IsHealthy() bool {
 	}
 	register := true
 	for _, healthCheckResult := range t.HealthCheckResults {
-		register = register && healthCheckResult.Alive
+		register = register && healthCheckResult.Alive && t.State != "TASK_KILLING"
 	}
 	return register
 }


Test patch:
diff --git a/apps/task_test.go b/apps/task_test.go
index a1f1a0b..f2e18e1 100644
--- a/apps/task_test.go
+++ b/apps/task_test.go
@@ -105,6 +105,18 @@ func TestIsHealthy(t *testing.T) {
 
 	// then
 	assert.True(t, task.IsHealthy())
+
+        // when
+        task.State = "TASK_KILLING"
+
+        // then
+        assert.False(t, task.IsHealthy())
+
+        // when
+        task.State = "TASK_RUNNING"
+
+        // then
+        assert.True(t, task.IsHealthy())
 }
 
 func TestId_String(t *testing.T) {
Repository: allegro/marathon-consul
Pull request #283 (2018-01-30 20:22:14)

Support Marathon 1.5 Network API
I've manually tested this end-to-end with Marathon, Consul, and this new binary. This patch addresses issue #230 

I'm able to manually compile this code using native `go run`. But I'm not able to run `make build`, etc. So maybe someone (@janisz) can test this? 


Patch:
diff --git a/apps/app.go b/apps/app.go
index b36d1c8..9d62ccd 100644
--- a/apps/app.go
+++ b/apps/app.go
@@ -28,6 +28,10 @@ type PortDefinition struct {
 	Labels map[string]string `json:"labels"`
 }
 
+type Container struct {
+	PortMappings []PortDefinition `json:"portMappings"`
+}
+
 type appWrapper struct {
 	App App `json:"app"`
 }
@@ -37,6 +41,7 @@ type Apps struct {
 }
 
 type App struct {
+	Container       Container         `json:"container"`
 	Labels          map[string]string `json:"labels"`
 	HealthChecks    []HealthCheck     `json:"healthChecks"`
 	ID              AppID             `json:"id"`
@@ -163,7 +168,7 @@ type indexedPortDefinition struct {
 
 func (app App) findConsulPortDefinitions() []indexedPortDefinition {
 	var definitions []indexedPortDefinition
-	for i, d := range app.PortDefinitions {
+	for i, d := range app.extractPortDefinitions() {
 		if _, ok := d.Labels[MarathonConsulLabel]; ok {
 			definitions = append(definitions, indexedPortDefinition{
 				Index:  i,
@@ -171,5 +176,20 @@ func (app App) findConsulPortDefinitions() []indexedPortDefinition {
 			})
 		}
 	}
+
 	return definitions
 }
+
+// Deprecated: Allows for backward compatibility with Marathons' network API
+// PortDefinitions are deprecated in favor of Marathons' new PortMappings
+// see https://github.com/mesosphere/marathon/pull/5391
+func (app App) extractPortDefinitions() []PortDefinition {
+	var appPortDefinitions []PortDefinition
+	if len(app.Container.PortMappings) > 0 {
+		appPortDefinitions = app.Container.PortMappings
+	} else {
+		appPortDefinitions = app.PortDefinitions
+	}
+	
+	return appPortDefinitions
+}


Test patch:
diff --git a/apps/app_test.go b/apps/app_test.go
index b13a66b..1e89084 100644
--- a/apps/app_test.go
+++ b/apps/app_test.go
@@ -7,6 +7,27 @@ import (
 	"github.com/stretchr/testify/assert"
 )
 
+func TestExtractPortDefintions(t *testing.T) {
+	definitions := []PortDefinition{
+		{
+			Labels: map[string]string{"other": "tag"},
+		},
+		{},
+	}
+	app := App{
+		Container: Container{
+			PortMappings: definitions,
+		},
+	}
+
+	ports := app.extractPortDefinitions()
+	assert.Equal(t, app.Container.PortMappings[0].Labels["other"], ports[0].Labels["other"])
+
+	app = App{PortDefinitions: definitions}
+	ports = app.extractPortDefinitions()
+	assert.Equal(t, app.PortDefinitions[0].Labels["other"], ports[0].Labels["other"])
+}
+
 func TestParseApps(t *testing.T) {
 	t.Parallel()