From 1c47a5c2c93dc9401b7ef1b6e73855c7e04a2e41 Mon Sep 17 00:00:00 2001 From: Chase Kiefer Date: Mon, 14 Jun 2021 15:41:43 -0500 Subject: [PATCH 1/2] add cassandraCreateSchema affinity Signed-off-by: Chase Kiefer --- deploy/crds/jaegertracing.io_jaegers_crd.yaml | 262 ++++++++++++++++++ pkg/apis/jaegertracing/v1/jaeger_types.go | 3 + .../jaegertracing/v1/zz_generated.deepcopy.go | 5 + .../jaegertracing/v1/zz_generated.openapi.go | 7 + pkg/controller/jaeger/configmap.go | 2 +- pkg/storage/cassandra_dependencies.go | 1 + pkg/storage/cassandra_dependencies_test.go | 12 + 7 files changed, 291 insertions(+), 1 deletion(-) diff --git a/deploy/crds/jaegertracing.io_jaegers_crd.yaml b/deploy/crds/jaegertracing.io_jaegers_crd.yaml index f803a4aaf..3f68ed1b9 100644 --- a/deploy/crds/jaegertracing.io_jaegers_crd.yaml +++ b/deploy/crds/jaegertracing.io_jaegers_crd.yaml @@ -7004,6 +7004,268 @@ spec: properties: cassandraCreateSchema: properties: + affinity: + properties: + nodeAffinity: + properties: + preferredDuringSchedulingIgnoredDuringExecution: + items: + properties: + preference: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchFields: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + type: object + weight: + format: int32 + type: integer + required: + - preference + - weight + type: object + type: array + requiredDuringSchedulingIgnoredDuringExecution: + properties: + nodeSelectorTerms: + items: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchFields: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + type: object + type: array + required: + - nodeSelectorTerms + type: object + type: object + podAffinity: + properties: + preferredDuringSchedulingIgnoredDuringExecution: + items: + properties: + podAffinityTerm: + properties: + labelSelector: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + type: object + type: object + namespaces: + items: + type: string + type: array + topologyKey: + type: string + required: + - topologyKey + type: object + weight: + format: int32 + type: integer + required: + - podAffinityTerm + - weight + type: object + type: array + requiredDuringSchedulingIgnoredDuringExecution: + items: + properties: + labelSelector: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + type: object + type: object + namespaces: + items: + type: string + type: array + topologyKey: + type: string + required: + - topologyKey + type: object + type: array + type: object + podAntiAffinity: + properties: + preferredDuringSchedulingIgnoredDuringExecution: + items: + properties: + podAffinityTerm: + properties: + labelSelector: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + type: object + type: object + namespaces: + items: + type: string + type: array + topologyKey: + type: string + required: + - topologyKey + type: object + weight: + format: int32 + type: integer + required: + - podAffinityTerm + - weight + type: object + type: array + requiredDuringSchedulingIgnoredDuringExecution: + items: + properties: + labelSelector: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + type: object + type: object + namespaces: + items: + type: string + type: array + topologyKey: + type: string + required: + - topologyKey + type: object + type: array + type: object + type: object datacenter: type: string enabled: diff --git a/pkg/apis/jaegertracing/v1/jaeger_types.go b/pkg/apis/jaegertracing/v1/jaeger_types.go index 23657364d..a4d7fe235 100644 --- a/pkg/apis/jaegertracing/v1/jaeger_types.go +++ b/pkg/apis/jaegertracing/v1/jaeger_types.go @@ -573,6 +573,9 @@ type JaegerCassandraCreateSchemaSpec struct { // +optional Timeout string `json:"timeout,omitempty"` + // +optional + Affinity *v1.Affinity `json:"affinity,omitempty"` + // +optional TTLSecondsAfterFinished *int32 `json:"ttlSecondsAfterFinished,omitempty"` } diff --git a/pkg/apis/jaegertracing/v1/zz_generated.deepcopy.go b/pkg/apis/jaegertracing/v1/zz_generated.deepcopy.go index ef5779b8b..7c53b0dda 100644 --- a/pkg/apis/jaegertracing/v1/zz_generated.deepcopy.go +++ b/pkg/apis/jaegertracing/v1/zz_generated.deepcopy.go @@ -195,6 +195,11 @@ func (in *JaegerCassandraCreateSchemaSpec) DeepCopyInto(out *JaegerCassandraCrea *out = new(bool) **out = **in } + if in.Affinity != nil { + in, out := &in.Affinity, &out.Affinity + *out = new(corev1.Affinity) + (*in).DeepCopyInto(*out) + } if in.TTLSecondsAfterFinished != nil { in, out := &in.TTLSecondsAfterFinished, &out.TTLSecondsAfterFinished *out = new(int32) diff --git a/pkg/apis/jaegertracing/v1/zz_generated.openapi.go b/pkg/apis/jaegertracing/v1/zz_generated.openapi.go index 86de985b6..1ba172f07 100644 --- a/pkg/apis/jaegertracing/v1/zz_generated.openapi.go +++ b/pkg/apis/jaegertracing/v1/zz_generated.openapi.go @@ -552,6 +552,11 @@ func schema_pkg_apis_jaegertracing_v1_JaegerCassandraCreateSchemaSpec(ref common Format: "", }, }, + "affinity": { + SchemaProps: spec.SchemaProps{ + Ref: ref("k8s.io/api/core/v1.Affinity"), + }, + }, "ttlSecondsAfterFinished": { SchemaProps: spec.SchemaProps{ Type: []string{"integer"}, @@ -561,6 +566,8 @@ func schema_pkg_apis_jaegertracing_v1_JaegerCassandraCreateSchemaSpec(ref common }, }, }, + Dependencies: []string{ + "k8s.io/api/core/v1.Affinity"}, } } diff --git a/pkg/controller/jaeger/configmap.go b/pkg/controller/jaeger/configmap.go index 0d63d4b38..68a5ba293 100644 --- a/pkg/controller/jaeger/configmap.go +++ b/pkg/controller/jaeger/configmap.go @@ -10,7 +10,7 @@ import ( "k8s.io/apimachinery/pkg/selection" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1" + v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1" "github.com/jaegertracing/jaeger-operator/pkg/inventory" "github.com/jaegertracing/jaeger-operator/pkg/tracing" "github.com/jaegertracing/jaeger-operator/pkg/util" diff --git a/pkg/storage/cassandra_dependencies.go b/pkg/storage/cassandra_dependencies.go index ba9f09f2e..5601f1f3a 100644 --- a/pkg/storage/cassandra_dependencies.go +++ b/pkg/storage/cassandra_dependencies.go @@ -140,6 +140,7 @@ func cassandraDeps(jaeger *v1.Jaeger) []batchv1.Job { }, Spec: corev1.PodSpec{ ActiveDeadlineSeconds: podTimeout, + Affinity: jaeger.Spec.Storage.CassandraCreateSchema.Affinity, SecurityContext: jaeger.Spec.SecurityContext, Containers: []corev1.Container{{ Image: util.ImageName(jaeger.Spec.Storage.CassandraCreateSchema.Image, "jaeger-cassandra-schema-image"), diff --git a/pkg/storage/cassandra_dependencies_test.go b/pkg/storage/cassandra_dependencies_test.go index 17d07dd81..4066c61b7 100644 --- a/pkg/storage/cassandra_dependencies_test.go +++ b/pkg/storage/cassandra_dependencies_test.go @@ -149,3 +149,15 @@ func TestCassandraCreateSchemaSecurityContext(t *testing.T) { assert.Len(t, b, 1) assert.Equal(t, b[0].Spec.Template.Spec.SecurityContext, expectedSecurityContext) } + +func TestCassandraCreateSchemaAffinity(t *testing.T) { + expectedAffinity := &corev1.Affinity{} + + jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestCassandraCreateSchemaAffinity"}) + jaeger.Spec.Storage.CassandraCreateSchema.Affinity = expectedAffinity + + b := cassandraDeps(jaeger) + + assert.Len(t, b, 1) + assert.Equal(t, expectedAffinity, b[0].Spec.Template.Spec.Affinity) +} From 8eb762b0f3955f00e85ca76c7ed5c46fbfa0325e Mon Sep 17 00:00:00 2001 From: Chase Kiefer Date: Mon, 14 Jun 2021 15:41:43 -0500 Subject: [PATCH 2/2] add cassandraCreateSchema affinity Signed-off-by: Chase Kiefer --- deploy/crds/jaegertracing.io_jaegers_crd.yaml | 262 ++++++++++++++++++ pkg/apis/jaegertracing/v1/jaeger_types.go | 3 + .../jaegertracing/v1/zz_generated.deepcopy.go | 5 + .../jaegertracing/v1/zz_generated.openapi.go | 7 + pkg/controller/jaeger/configmap.go | 2 +- pkg/storage/cassandra_dependencies.go | 1 + pkg/storage/cassandra_dependencies_test.go | 12 + 7 files changed, 291 insertions(+), 1 deletion(-) diff --git a/deploy/crds/jaegertracing.io_jaegers_crd.yaml b/deploy/crds/jaegertracing.io_jaegers_crd.yaml index f803a4aaf..3f68ed1b9 100644 --- a/deploy/crds/jaegertracing.io_jaegers_crd.yaml +++ b/deploy/crds/jaegertracing.io_jaegers_crd.yaml @@ -7004,6 +7004,268 @@ spec: properties: cassandraCreateSchema: properties: + affinity: + properties: + nodeAffinity: + properties: + preferredDuringSchedulingIgnoredDuringExecution: + items: + properties: + preference: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchFields: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + type: object + weight: + format: int32 + type: integer + required: + - preference + - weight + type: object + type: array + requiredDuringSchedulingIgnoredDuringExecution: + properties: + nodeSelectorTerms: + items: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchFields: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + type: object + type: array + required: + - nodeSelectorTerms + type: object + type: object + podAffinity: + properties: + preferredDuringSchedulingIgnoredDuringExecution: + items: + properties: + podAffinityTerm: + properties: + labelSelector: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + type: object + type: object + namespaces: + items: + type: string + type: array + topologyKey: + type: string + required: + - topologyKey + type: object + weight: + format: int32 + type: integer + required: + - podAffinityTerm + - weight + type: object + type: array + requiredDuringSchedulingIgnoredDuringExecution: + items: + properties: + labelSelector: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + type: object + type: object + namespaces: + items: + type: string + type: array + topologyKey: + type: string + required: + - topologyKey + type: object + type: array + type: object + podAntiAffinity: + properties: + preferredDuringSchedulingIgnoredDuringExecution: + items: + properties: + podAffinityTerm: + properties: + labelSelector: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + type: object + type: object + namespaces: + items: + type: string + type: array + topologyKey: + type: string + required: + - topologyKey + type: object + weight: + format: int32 + type: integer + required: + - podAffinityTerm + - weight + type: object + type: array + requiredDuringSchedulingIgnoredDuringExecution: + items: + properties: + labelSelector: + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + type: object + type: object + namespaces: + items: + type: string + type: array + topologyKey: + type: string + required: + - topologyKey + type: object + type: array + type: object + type: object datacenter: type: string enabled: diff --git a/pkg/apis/jaegertracing/v1/jaeger_types.go b/pkg/apis/jaegertracing/v1/jaeger_types.go index 23657364d..a4d7fe235 100644 --- a/pkg/apis/jaegertracing/v1/jaeger_types.go +++ b/pkg/apis/jaegertracing/v1/jaeger_types.go @@ -573,6 +573,9 @@ type JaegerCassandraCreateSchemaSpec struct { // +optional Timeout string `json:"timeout,omitempty"` + // +optional + Affinity *v1.Affinity `json:"affinity,omitempty"` + // +optional TTLSecondsAfterFinished *int32 `json:"ttlSecondsAfterFinished,omitempty"` } diff --git a/pkg/apis/jaegertracing/v1/zz_generated.deepcopy.go b/pkg/apis/jaegertracing/v1/zz_generated.deepcopy.go index ef5779b8b..7c53b0dda 100644 --- a/pkg/apis/jaegertracing/v1/zz_generated.deepcopy.go +++ b/pkg/apis/jaegertracing/v1/zz_generated.deepcopy.go @@ -195,6 +195,11 @@ func (in *JaegerCassandraCreateSchemaSpec) DeepCopyInto(out *JaegerCassandraCrea *out = new(bool) **out = **in } + if in.Affinity != nil { + in, out := &in.Affinity, &out.Affinity + *out = new(corev1.Affinity) + (*in).DeepCopyInto(*out) + } if in.TTLSecondsAfterFinished != nil { in, out := &in.TTLSecondsAfterFinished, &out.TTLSecondsAfterFinished *out = new(int32) diff --git a/pkg/apis/jaegertracing/v1/zz_generated.openapi.go b/pkg/apis/jaegertracing/v1/zz_generated.openapi.go index 86de985b6..1ba172f07 100644 --- a/pkg/apis/jaegertracing/v1/zz_generated.openapi.go +++ b/pkg/apis/jaegertracing/v1/zz_generated.openapi.go @@ -552,6 +552,11 @@ func schema_pkg_apis_jaegertracing_v1_JaegerCassandraCreateSchemaSpec(ref common Format: "", }, }, + "affinity": { + SchemaProps: spec.SchemaProps{ + Ref: ref("k8s.io/api/core/v1.Affinity"), + }, + }, "ttlSecondsAfterFinished": { SchemaProps: spec.SchemaProps{ Type: []string{"integer"}, @@ -561,6 +566,8 @@ func schema_pkg_apis_jaegertracing_v1_JaegerCassandraCreateSchemaSpec(ref common }, }, }, + Dependencies: []string{ + "k8s.io/api/core/v1.Affinity"}, } } diff --git a/pkg/controller/jaeger/configmap.go b/pkg/controller/jaeger/configmap.go index 0d63d4b38..68a5ba293 100644 --- a/pkg/controller/jaeger/configmap.go +++ b/pkg/controller/jaeger/configmap.go @@ -10,7 +10,7 @@ import ( "k8s.io/apimachinery/pkg/selection" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1" + v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1" "github.com/jaegertracing/jaeger-operator/pkg/inventory" "github.com/jaegertracing/jaeger-operator/pkg/tracing" "github.com/jaegertracing/jaeger-operator/pkg/util" diff --git a/pkg/storage/cassandra_dependencies.go b/pkg/storage/cassandra_dependencies.go index bb4d0a3b8..f6ba129cc 100644 --- a/pkg/storage/cassandra_dependencies.go +++ b/pkg/storage/cassandra_dependencies.go @@ -174,6 +174,7 @@ func cassandraDeps(jaeger *v1.Jaeger) []batchv1.Job { }, Spec: corev1.PodSpec{ ActiveDeadlineSeconds: podTimeout, + Affinity: jaeger.Spec.Storage.CassandraCreateSchema.Affinity, SecurityContext: jaeger.Spec.SecurityContext, Containers: []corev1.Container{{ Image: util.ImageName(jaeger.Spec.Storage.CassandraCreateSchema.Image, "jaeger-cassandra-schema-image"), diff --git a/pkg/storage/cassandra_dependencies_test.go b/pkg/storage/cassandra_dependencies_test.go index c03d0a009..b6b400a7b 100644 --- a/pkg/storage/cassandra_dependencies_test.go +++ b/pkg/storage/cassandra_dependencies_test.go @@ -160,3 +160,15 @@ func TestCassandraCreateSchemaSecret(t *testing.T) { assert.Len(t, b, 1) assert.Equal(t, secret, b[0].Spec.Template.Spec.Containers[0].EnvFrom[0].SecretRef.LocalObjectReference.Name) } + +func TestCassandraCreateSchemaAffinity(t *testing.T) { + expectedAffinity := &corev1.Affinity{} + + jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestCassandraCreateSchemaAffinity"}) + jaeger.Spec.Storage.CassandraCreateSchema.Affinity = expectedAffinity + + b := cassandraDeps(jaeger) + + assert.Len(t, b, 1) + assert.Equal(t, expectedAffinity, b[0].Spec.Template.Spec.Affinity) +}