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

Bug 1975379: Use hard requirement for anti-affinity rules on both console's deployments #560

Merged
merged 2 commits into from Jul 14, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
83 changes: 68 additions & 15 deletions pkg/console/subresource/deployment/deployment.go
Expand Up @@ -83,6 +83,7 @@ func DefaultDeployment(operatorConfig *operatorv1.Console, cm *corev1.ConfigMap,
meta.Annotations = deploymentAnnotations
replicas := Replicas(infrastructureConfig)
affinity := consolePodAffinity(infrastructureConfig)
rollingUpdateParams := rollingUpdateParams(infrastructureConfig)
gracePeriod := int64(40)
volumeConfig := defaultVolumeConfig()
caBundle, caBundleExists := trustedCAConfigMap.Data["ca-bundle.crt"]
Expand All @@ -106,6 +107,10 @@ func DefaultDeployment(operatorConfig *operatorv1.Console, cm *corev1.ConfigMap,
Selector: &metav1.LabelSelector{
MatchLabels: labels,
},
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
RollingUpdate: rollingUpdateParams,
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: api.OpenShiftConsoleName,
Expand Down Expand Up @@ -146,15 +151,19 @@ func DefaultDownloadsDeployment(operatorConfig *operatorv1.Console, infrastructu
meta.Name = api.OpenShiftConsoleDownloadsDeploymentName
replicas := Replicas(infrastructureConfig)
affinity := downloadsPodAffinity(infrastructureConfig)
rollingUpdateParams := rollingUpdateParams(infrastructureConfig)
gracePeriod := int64(0)

downloadsDeployment := &appsv1.Deployment{
ObjectMeta: meta,
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,
Selector: &metav1.LabelSelector{
MatchLabels: labels,
},
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
RollingUpdate: rollingUpdateParams,
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: api.OpenShiftConsoleDownloadsDeploymentName,
Expand Down Expand Up @@ -229,6 +238,20 @@ func LogDeploymentAnnotationChanges(client appsclientv1.DeploymentsGetter, updat
}
}

func rollingUpdateParams(infrastructureConfig *configv1.Infrastructure) *appsv1.RollingUpdateDeployment {
if infrastructureConfig.Status.InfrastructureTopology == configv1.SingleReplicaTopologyMode {
return &appsv1.RollingUpdateDeployment{}
}
return &appsv1.RollingUpdateDeployment{
MaxSurge: &intstr.IntOrString{
IntVal: int32(3),
},
MaxUnavailable: &intstr.IntOrString{
IntVal: int32(1),
},
}
}

func tolerations() []corev1.Toleration {
return []corev1.Toleration{
{
Expand Down Expand Up @@ -257,15 +280,30 @@ func consolePodAffinity(infrastructureConfig *configv1.Infrastructure) *corev1.A
}
return &corev1.Affinity{
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: "kubernetes.io/hostname",
}, {
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "component",
Operator: metav1.LabelSelectorOpIn,
Values: []string{"ui"},
},
},
TopologyKey: "topology.kubernetes.io/zone",
},
}},
TopologyKey: "topology.kubernetes.io/zone",
},
},
},
}
}
Expand All @@ -277,15 +315,30 @@ func downloadsPodAffinity(infrastructureConfig *configv1.Infrastructure) *corev1
}
return &corev1.Affinity{
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{"downloads"},
},
},
TopologyKey: "topology.kubernetes.io/zone",
},
}},
TopologyKey: "kubernetes.io/hostname",
}, {
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "component",
Operator: metav1.LabelSelectorOpIn,
Values: []string{"downloads"},
},
},
},
TopologyKey: "topology.kubernetes.io/zone",
},
},
},
}
}
Expand Down
120 changes: 94 additions & 26 deletions pkg/console/subresource/deployment/deployment_test.go
Expand Up @@ -130,17 +130,31 @@ 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: "kubernetes.io/hostname",
}, {
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "component",
Operator: metav1.LabelSelectorOpIn,
Values: []string{"ui"},
},
},
TopologyKey: "topology.kubernetes.io/zone",
},
}},
TopologyKey: "topology.kubernetes.io/zone",
},
},
},
}

Expand All @@ -162,6 +176,9 @@ func TestDefaultDeployment(t *testing.T) {
infrastructureConfigHighlyAvailable := infrastructureConfigWithTopology(configv1.HighlyAvailableTopologyMode)
infrastructureConfigSingleReplica := infrastructureConfigWithTopology(configv1.SingleReplicaTopologyMode)

rollingUpdateParamsForSingleReplica := rollingUpdateParams(infrastructureConfigSingleReplica)
rollingUpdateParamsForHighAvail := rollingUpdateParams(infrastructureConfigHighlyAvailable)

tests := []struct {
name string
args args
Expand Down Expand Up @@ -192,6 +209,7 @@ func TestDefaultDeployment(t *testing.T) {
ObjectMeta: consoleDeploymentObjectMeta,
Spec: appsv1.DeploymentSpec{
Replicas: &defaultReplicaCount,

Selector: &metav1.LabelSelector{
MatchLabels: labels,
},
Expand Down Expand Up @@ -221,7 +239,10 @@ func TestDefaultDeployment(t *testing.T) {
Volumes: consoleVolumes(defaultVolumeConfig()),
},
},
Strategy: appsv1.DeploymentStrategy{},
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
RollingUpdate: rollingUpdateParamsForHighAvail,
},
MinReadySeconds: 0,
RevisionHistoryLimit: nil,
Paused: false,
Expand Down Expand Up @@ -284,7 +305,10 @@ func TestDefaultDeployment(t *testing.T) {
Volumes: consoleVolumes(append(defaultVolumeConfig(), trustedCAVolume())),
},
},
Strategy: appsv1.DeploymentStrategy{},
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
RollingUpdate: rollingUpdateParamsForHighAvail,
},
MinReadySeconds: 0,
RevisionHistoryLimit: nil,
Paused: false,
Expand Down Expand Up @@ -347,7 +371,10 @@ func TestDefaultDeployment(t *testing.T) {
Volumes: consoleVolumes(defaultVolumeConfig()),
},
},
Strategy: appsv1.DeploymentStrategy{},
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
RollingUpdate: rollingUpdateParamsForSingleReplica,
},
MinReadySeconds: 0,
RevisionHistoryLimit: nil,
Paused: false,
Expand Down Expand Up @@ -447,6 +474,9 @@ func TestDefaultDownloadsDeployment(t *testing.T) {
downloadsDeploymentPodSpecHighAvail := downloadsDeploymentPodSpecSingleReplica
downloadsDeploymentPodSpecHighAvail.Affinity = downloadsPodAffinity(infrastructureConfigHighlyAvailable)

rollingUpdateParamsForSingleReplica := rollingUpdateParams(infrastructureConfigSingleReplica)
rollingUpdateParamsForHighAvail := rollingUpdateParams(infrastructureConfigHighlyAvailable)

tests := []struct {
name string
args args
Expand All @@ -463,6 +493,10 @@ func TestDefaultDownloadsDeployment(t *testing.T) {
ObjectMeta: downloadsDeploymentObjectMeta,
Spec: appsv1.DeploymentSpec{
Replicas: &singleNodeReplicaCount,
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
RollingUpdate: rollingUpdateParamsForSingleReplica,
},
Selector: &metav1.LabelSelector{
MatchLabels: labels,
},
Expand Down Expand Up @@ -491,6 +525,10 @@ func TestDefaultDownloadsDeployment(t *testing.T) {
ObjectMeta: downloadsDeploymentObjectMeta,
Spec: appsv1.DeploymentSpec{
Replicas: &defaultReplicaCount,
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
RollingUpdate: rollingUpdateParamsForHighAvail,
},
Selector: &metav1.LabelSelector{
MatchLabels: labels,
},
Expand Down Expand Up @@ -585,15 +623,30 @@ func TestConsolePodAffinity(t *testing.T) {
},
want: &corev1.Affinity{
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: "kubernetes.io/hostname",
}, {
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "component",
Operator: metav1.LabelSelectorOpIn,
Values: []string{"ui"},
},
},
TopologyKey: "topology.kubernetes.io/zone",
},
}},
TopologyKey: "topology.kubernetes.io/zone",
},
},
},
},
},
Expand All @@ -607,7 +660,7 @@ func TestConsolePodAffinity(t *testing.T) {
}
}

func TestDownalodsPodAffinity(t *testing.T) {
func TestDownloadsPodAffinity(t *testing.T) {
tests := []struct {
name string
infraConfig *configv1.Infrastructure
Expand Down Expand Up @@ -635,15 +688,30 @@ func TestDownalodsPodAffinity(t *testing.T) {
},
want: &corev1.Affinity{
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{"downloads"},
},
},
TopologyKey: "topology.kubernetes.io/zone",
},
}},
TopologyKey: "kubernetes.io/hostname",
}, {
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "component",
Operator: metav1.LabelSelectorOpIn,
Values: []string{"downloads"},
},
},
},
TopologyKey: "topology.kubernetes.io/zone",
},
},
},
},
},
Expand Down