Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catalog source affinity #2963

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
461 changes: 461 additions & 0 deletions deploy/chart/crds/0000_50_olm_00-catalogsources.crd.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/onsi/gomega v1.24.1
github.com/openshift/api v3.9.0+incompatible
github.com/openshift/client-go v0.0.0-20220525160904-9e1acff93e4a
github.com/operator-framework/api v0.17.5
github.com/operator-framework/api v0.17.6
github.com/operator-framework/operator-registry v1.17.5
github.com/otiai10/copy v1.2.0
github.com/pkg/errors v0.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1040,8 +1040,8 @@ github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c h1:CV76yFOTXmq
github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c/go.mod h1:lFMO8mLHXWFzSdYvGNo8ivF9SfF6zInA8ZGw4phRnUE=
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
github.com/operator-framework/api v0.7.1/go.mod h1:L7IvLd/ckxJEJg/t4oTTlnHKAJIP/p51AvEslW3wYdY=
github.com/operator-framework/api v0.17.5 h1:9d0pc6m1Vp4QeS8i5dhl/B0nifhKQdtw+iFsNx0An0Q=
github.com/operator-framework/api v0.17.5/go.mod h1:l/cuwtPxkVUY7fzYgdust2m9tlmb8I4pOvbsUufRb24=
github.com/operator-framework/api v0.17.6 h1:E6+vlvYUKafvoXYtCuHlDZrXX4vl8AT+r93OxNlzjpU=
github.com/operator-framework/api v0.17.6/go.mod h1:l/cuwtPxkVUY7fzYgdust2m9tlmb8I4pOvbsUufRb24=
github.com/operator-framework/operator-registry v1.17.5 h1:LR8m1rFz5Gcyje8WK6iYt+gIhtzqo52zMRALdmTYHT0=
github.com/operator-framework/operator-registry v1.17.5/go.mod h1:sRQIgDMZZdUcmHltzyCnM6RUoDF+WS8Arj1BQIARDS8=
github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k=
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/registry/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ func Pod(source *operatorsv1alpha1.CatalogSource, name string, img string, saNam
pod.Spec.Tolerations[index] = *toleration.DeepCopy()
}
}

// Override affinity
if grpcPodConfig.Affinity != nil {
pod.Spec.Affinity = grpcPodConfig.Affinity.DeepCopy()
}
}

// Set priorityclass if its annotation exists
Expand Down
50 changes: 50 additions & 0 deletions pkg/controller/registry/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,33 @@ func TestPodSchedulingOverrides(t *testing.T) {
},
}

var overriddenAffinity = &corev1.Affinity{
NodeAffinity: &corev1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{
NodeSelectorTerms: []corev1.NodeSelectorTerm{
{
MatchExpressions: []corev1.NodeSelectorRequirement{
{
Key: "kubernetes.io/arch",
Operator: corev1.NodeSelectorOpIn,
Values: []string{
"amd64",
"arm",
},
},
},
},
},
},
},
}

testCases := []struct {
title string
catalogSource *v1alpha1.CatalogSource
expectedNodeSelectors map[string]string
expectedTolerations []corev1.Toleration
expectedAffinity *corev1.Affinity
expectedPriorityClassName string
annotations map[string]string
}{
Expand All @@ -275,6 +297,7 @@ func TestPodSchedulingOverrides(t *testing.T) {
},
},
expectedTolerations: nil,
expectedAffinity: nil,
expectedPriorityClassName: defaultPriorityClassName,
expectedNodeSelectors: defaultNodeSelectors,
}, {
Expand All @@ -293,6 +316,7 @@ func TestPodSchedulingOverrides(t *testing.T) {
},
},
expectedTolerations: nil,
expectedAffinity: nil,
expectedPriorityClassName: defaultPriorityClassName,
expectedNodeSelectors: overriddenNodeSelectors,
}, {
Expand All @@ -311,6 +335,7 @@ func TestPodSchedulingOverrides(t *testing.T) {
},
},
expectedTolerations: nil,
expectedAffinity: nil,
expectedPriorityClassName: overriddenPriorityClassName,
expectedNodeSelectors: defaultNodeSelectors,
}, {
Expand All @@ -329,6 +354,7 @@ func TestPodSchedulingOverrides(t *testing.T) {
},
},
expectedTolerations: nil,
expectedAffinity: nil,
expectedPriorityClassName: defaultPriorityClassName,
expectedNodeSelectors: defaultNodeSelectors,
}, {
Expand All @@ -347,6 +373,26 @@ func TestPodSchedulingOverrides(t *testing.T) {
},
},
expectedTolerations: overriddenTolerations,
expectedAffinity: nil,
expectedPriorityClassName: defaultPriorityClassName,
expectedNodeSelectors: defaultNodeSelectors,
}, {
title: "Override affinity",
catalogSource: &v1alpha1.CatalogSource{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "testns",
},
Spec: v1alpha1.CatalogSourceSpec{
SourceType: v1alpha1.SourceTypeGrpc,
Image: "repo/image:tag",
GrpcPodConfig: &v1alpha1.GrpcPodConfig{
Affinity: overriddenAffinity,
},
},
},
expectedTolerations: nil,
expectedAffinity: overriddenAffinity,
expectedPriorityClassName: defaultPriorityClassName,
expectedNodeSelectors: defaultNodeSelectors,
}, {
Expand All @@ -363,10 +409,12 @@ func TestPodSchedulingOverrides(t *testing.T) {
NodeSelector: overriddenNodeSelectors,
PriorityClassName: &overriddenPriorityClassName,
Tolerations: overriddenTolerations,
Affinity: overriddenAffinity,
},
},
},
expectedTolerations: overriddenTolerations,
expectedAffinity: overriddenAffinity,
expectedPriorityClassName: overriddenPriorityClassName,
expectedNodeSelectors: overriddenNodeSelectors,
}, {
Expand All @@ -385,6 +433,7 @@ func TestPodSchedulingOverrides(t *testing.T) {
},
},
expectedTolerations: nil,
expectedAffinity: nil,
annotations: map[string]string{
CatalogPriorityClassKey: "some-OTHER-prio-class",
},
Expand All @@ -398,5 +447,6 @@ func TestPodSchedulingOverrides(t *testing.T) {
require.Equal(t, testCase.expectedNodeSelectors, pod.Spec.NodeSelector)
require.Equal(t, testCase.expectedPriorityClassName, pod.Spec.PriorityClassName)
require.Equal(t, testCase.expectedTolerations, pod.Spec.Tolerations)
require.Equal(t, testCase.expectedAffinity, pod.Spec.Affinity)
}
}
Loading