Skip to content

Commit

Permalink
Merge pull request #605 from jhadvig/bzantiAffinity
Browse files Browse the repository at this point in the history
Bug 2016654: Use hard requirements for antiaffinity rules
  • Loading branch information
openshift-merge-robot committed Nov 8, 2021
2 parents 44a0308 + 1b6eac2 commit fe5bcfa
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 16 deletions.
15 changes: 15 additions & 0 deletions manifests/07-downloads-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,28 @@ spec:
matchLabels:
app: console
component: downloads
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 3
template:
metadata:
name: downloads
labels:
app: console
component: downloads
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: component
operator: In
values:
- downloads
topologyKey: kubernetes.io/hostname
nodeSelector:
kubernetes.io/os: "linux"
tolerations:
Expand Down
27 changes: 20 additions & 7 deletions pkg/console/subresource/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ func DefaultDeployment(operatorConfig *operatorv1.Console, cm *corev1.ConfigMap,
Selector: &metav1.LabelSelector{
MatchLabels: labels,
},
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
RollingUpdate: &appsv1.RollingUpdateDeployment{
MaxSurge: &intstr.IntOrString{
IntVal: int32(3),
},
MaxUnavailable: &intstr.IntOrString{
IntVal: int32(1),
},
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: api.OpenShiftConsoleName,
Expand All @@ -107,16 +118,18 @@ func DefaultDeployment(operatorConfig *operatorv1.Console, cm *corev1.ConfigMap,
"node-role.kubernetes.io/master": "",
},
Affinity: &corev1.Affinity{
// spread out across master nodes rather than congregate on one
PodAntiAffinity: &corev1.PodAntiAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{{
Weight: 100,
PodAffinityTerm: corev1.PodAffinityTerm{
LabelSelector: &metav1.LabelSelector{
MatchLabels: util.SharedLabels(),
RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{{
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "component",
Operator: metav1.LabelSelectorOpIn,
Values: []string{"ui"},
},
},
TopologyKey: "topology.kubernetes.io/zone",
},
TopologyKey: "kubernetes.io/hostname",
}},
},
},
Expand Down
41 changes: 32 additions & 9 deletions pkg/console/subresource/deployment/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"

configv1 "github.com/openshift/api/config/v1"
operatorsv1 "github.com/openshift/api/operator/v1"
"github.com/openshift/console-operator/pkg/api"
"github.com/openshift/console-operator/pkg/console/subresource/configmap"
"github.com/openshift/console-operator/pkg/console/subresource/util"
)

func TestDefaultDeployment(t *testing.T) {
Expand Down Expand Up @@ -126,14 +126,17 @@ func TestDefaultDeployment(t *testing.T) {
consoleDeploymentAffinity := &corev1.Affinity{
// spread out across master nodes rather than congregate on one
PodAntiAffinity: &corev1.PodAntiAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{{
Weight: 100,
PodAffinityTerm: corev1.PodAffinityTerm{
LabelSelector: &metav1.LabelSelector{
MatchLabels: util.SharedLabels(),
RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{{
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "component",
Operator: metav1.LabelSelectorOpIn,
Values: []string{"ui"},
},
},
TopologyKey: "topology.kubernetes.io/zone",
},
TopologyKey: "kubernetes.io/hostname",
}},
},
}
Expand Down Expand Up @@ -210,7 +213,17 @@ func TestDefaultDeployment(t *testing.T) {
Volumes: consoleVolumes(defaultVolumeConfig()),
},
},
Strategy: appsv1.DeploymentStrategy{},
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
RollingUpdate: &appsv1.RollingUpdateDeployment{
MaxSurge: &intstr.IntOrString{
IntVal: int32(3),
},
MaxUnavailable: &intstr.IntOrString{
IntVal: int32(1),
},
},
},
MinReadySeconds: 0,
RevisionHistoryLimit: nil,
Paused: false,
Expand Down Expand Up @@ -272,7 +285,17 @@ func TestDefaultDeployment(t *testing.T) {
Volumes: consoleVolumes(append(defaultVolumeConfig(), trustedCAVolume())),
},
},
Strategy: appsv1.DeploymentStrategy{},
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
RollingUpdate: &appsv1.RollingUpdateDeployment{
MaxSurge: &intstr.IntOrString{
IntVal: int32(3),
},
MaxUnavailable: &intstr.IntOrString{
IntVal: int32(1),
},
},
},
MinReadySeconds: 0,
RevisionHistoryLimit: nil,
Paused: false,
Expand Down

0 comments on commit fe5bcfa

Please sign in to comment.