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

operator: Add Pod annotations with node topology labels to support zone aware scheduling #9503

Merged
merged 21 commits into from
Jul 14, 2023

Conversation

shwetaap
Copy link
Contributor

@shwetaap shwetaap commented May 23, 2023

What this PR does / why we need it:
This PR adds support to zone aware scheduling by adding zone specific node topology labels to loki component pods
Which issue(s) this PR fixes:
Fixes #LOG-3834
Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • CHANGELOG.md updated
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/upgrading/_index.md

@shwetaap shwetaap requested a review from a team as a code owner May 23, 2023 19:43
@shwetaap shwetaap force-pushed the Log3834 branch 5 times, most recently from 6ecdc1c to 5e7e16b Compare May 31, 2023 03:53
@shwetaap shwetaap force-pushed the Log3834 branch 5 times, most recently from f7d9dc9 to 062df3f Compare June 6, 2023 02:43
@shwetaap shwetaap changed the title [Draft] operator: Add Pod annotations with node topology labels to support zone aware scheduling operator: Add Pod annotations with node topology labels to support zone aware scheduling Jun 6, 2023
@shwetaap shwetaap force-pushed the Log3834 branch 2 times, most recently from 98f73e3 to 11e09b6 Compare June 6, 2023 04:38
operator/go.mod Outdated Show resolved Hide resolved
operator/internal/handlers/lokistack_podannotation.go Outdated Show resolved Hide resolved
operator/internal/handlers/lokistack_podannotation.go Outdated Show resolved Hide resolved
operator/internal/handlers/lokistack_podannotation.go Outdated Show resolved Hide resolved
operator/internal/manifests/config_test.go Outdated Show resolved Hide resolved
operator/internal/manifests/distributor.go Outdated Show resolved Hide resolved
operator/internal/manifests/internal/config/options.go Outdated Show resolved Hide resolved
operator/internal/manifests/var.go Outdated Show resolved Hide resolved
operator/internal/manifests/var.go Outdated Show resolved Hide resolved
@shwetaap shwetaap force-pushed the Log3834 branch 4 times, most recently from 4e6a70b to d2541b6 Compare June 12, 2023 19:18
Copy link
Collaborator

@JoaoBraveCoding JoaoBraveCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First pass, looking really good! Just some minor comments

operator/internal/manifests/config.go Outdated Show resolved Hide resolved
operator/main.go Show resolved Hide resolved
operator/internal/manifests/var.go Outdated Show resolved Hide resolved
operator/internal/manifests/var.go Outdated Show resolved Hide resolved
operator/internal/manifests/internal/config/options.go Outdated Show resolved Hide resolved
operator/internal/manifests/var.go Outdated Show resolved Hide resolved
operator/internal/manifests/config.go Outdated Show resolved Hide resolved
operator/internal/manifests/distributor.go Outdated Show resolved Hide resolved
@periklis
Copy link
Collaborator

periklis commented Jun 22, 2023

After doing some testing on this using an OpenShift cluster with worker nodes on three different AWS zones on the same AWS region, I noticed that our patching scheduled pods strategy does not always work as expected. All not so often but very likely to happen I see pods missing the annotations that the lokistack_zone_labeling_controller is supposed to enforced:

❯ kubectl get pod -l app.kubernetes.io/instance=lokistack-dev -ocustom-columns='NAME:.metadata.name,NODE:.spec.nodeName,AVAILABILITY-ZONE:.metadata.annotations.loki\.grafana\.com\/availability\-zone' --sort-by=".metadata.labels.app\.kubernetes\.io\/component"

NAME                                            NODE                                            AVAILABILITY-ZONE
lokistack-dev-distributor-695c6d77fc-m9jd5      ip-10-0-169-238.eu-central-1.compute.internal   eu-central-1_eu-central-1b
lokistack-dev-distributor-695c6d77fc-w5wmj      ip-10-0-155-166.eu-central-1.compute.internal   eu-central-1_eu-central-1a
lokistack-dev-index-gateway-0                   ip-10-0-205-76.eu-central-1.compute.internal    eu-central-1_eu-central-1c
lokistack-dev-index-gateway-1                   ip-10-0-169-238.eu-central-1.compute.internal   <none>
lokistack-dev-ingester-0                        ip-10-0-205-76.eu-central-1.compute.internal    <none>
lokistack-dev-ingester-1                        ip-10-0-169-238.eu-central-1.compute.internal   eu-central-1_eu-central-1b
lokistack-dev-querier-76f87c9d95-gz6qx          ip-10-0-155-166.eu-central-1.compute.internal   eu-central-1_eu-central-1a
lokistack-dev-querier-76f87c9d95-z85kw          ip-10-0-169-238.eu-central-1.compute.internal   eu-central-1_eu-central-1b
lokistack-dev-query-frontend-59d794c575-htgsr   ip-10-0-155-166.eu-central-1.compute.internal   eu-central-1_eu-central-1a
lokistack-dev-query-frontend-59d794c575-v6vlg   ip-10-0-169-238.eu-central-1.compute.internal   eu-central-1_eu-central-1b

For the sake of completeness, here is how my worker nodes look like after installing the cluster on AWS:

❯ kubectl get node -L topology.kubernetes.io/region -L topology.kubernetes.io/zone

NAME                                            STATUS   ROLES   AGE     VERSION           REGION         ZONE
ip-10-0-155-166.eu-central-1.compute.internal   Ready    worker  7h12m   v1.26.5+7d22122   eu-central-1   eu-central-1a
ip-10-0-169-238.eu-central-1.compute.internal   Ready    worker  7h9m    v1.26.5+7d22122   eu-central-1   eu-central-1b
ip-10-0-205-76.eu-central-1.compute.internal    Ready    worker  7h12m   v1.26.5+7d22122   eu-central-1   eu-central-1c

PTAL (cc @xperimental )

Signed-off-by: Shweta Padubidri <spadubid@redhat.com>
Copy link
Collaborator

@xperimental xperimental left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have prepared a branch containing all the changes I have commented on. Have a look.

The main changes are:

  • Filter Pod reconciliations by label
  • Move Pod changes to a single place (unfortunately needed to modify the existing code a bit, pulling out podTemplate)
  • Move constants for annotations and labels into the API package

Unfortunately it took a while to prepare this, I thought there was a timing issue in there when setting the annotation on the Pod, but I was not able to reproduce this today anymore.

operator/internal/manifests/memberlist.go Outdated Show resolved Hide resolved
operator/internal/manifests/proxy_env.go Outdated Show resolved Hide resolved
operator/internal/manifests/proxy_env.go Outdated Show resolved Hide resolved
operator/internal/manifests/var.go Outdated Show resolved Hide resolved
operator/main.go Show resolved Hide resolved
operator/internal/manifests/config.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@JoaoBraveCoding JoaoBraveCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, just some unit test missing. Still have to re-run it on my side

operator/internal/manifests/zone_aware_config.go Outdated Show resolved Hide resolved
Signed-off-by: Shweta Padubidri <spadubid@redhat.com>
Signed-off-by: Shweta Padubidri <spadubid@redhat.com>
Copy link
Collaborator

@periklis periklis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a branch to capture a couple of improvements for the comments below.

  • Using mergo.Merge for configureReplication
  • Add test for rendering the Loki Config with instance_availability_zone
  • Add Changelog entry

shwetaap/loki@Log3834...periklis:loki:zone_awareness

Comment on lines 44 to 51
for i := range podTemplate.Spec.Containers {
podTemplate.Spec.Containers[i].Env = append(podTemplate.Spec.Containers[i].Env, availabilityZoneEnvVar)
}

podTemplate.Labels = labels.Merge(podTemplate.Labels, map[string]string{
lokiv1.LabelZoneAwarePod: "enabled",
})
podTemplate.Annotations[lokiv1.AnnotationAvailabilityZoneLabels] = topologyKey
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to stick with mergo.Merge here as we do with the other configure patching functions.

@shwetaap
Copy link
Contributor Author

/retest

operator/CHANGELOG.md Outdated Show resolved Hide resolved
operator/internal/manifests/config.go Outdated Show resolved Hide resolved
operator/internal/manifests/node_placement.go Show resolved Hide resolved
operator/internal/manifests/node_placement_test.go Outdated Show resolved Hide resolved
Signed-off-by: Shweta Padubidri <spadubid@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants