From 1bf5bf0b31e1f7c6e733174a9f767c8fc6e2f9f0 Mon Sep 17 00:00:00 2001 From: nimrod-up9 <59927337+nimrod-up9@users.noreply.github.com> Date: Thu, 3 Jun 2021 19:48:12 +0300 Subject: [PATCH] TRA-3299 Reduce footprint and Add Tolerances(#65) * Use lib const for DNSClusterFirstWithHostNet. * Whitespace. * Break lines. * Added affinity to pod names. * Added tolerations to NoExecute and NoSchedule taints. --- cli/kubernetes/provider.go | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/cli/kubernetes/provider.go b/cli/kubernetes/provider.go index 20acd52f7..c8ddd8433 100644 --- a/cli/kubernetes/provider.go +++ b/cli/kubernetes/provider.go @@ -116,7 +116,7 @@ func (provider *Provider) CreateMizuAggregatorPod(ctx context.Context, namespace }, }, }, - DNSPolicy: "ClusterFirstWithHostNet", + DNSPolicy: core.DNSClusterFirstWithHostNet, TerminationGracePeriodSeconds: new(int64), // Affinity: TODO: define node selector for all relevant nodes for this mizu instance }, @@ -252,12 +252,40 @@ func (provider *Provider) ApplyMizuTapperDaemonSet(ctx context.Context, namespac ), ) - podSpec := applyconfcore.PodSpec().WithHostNetwork(true).WithDNSPolicy("ClusterFirstWithHostNet").WithTerminationGracePeriodSeconds(0) + nodeNames := make([]string, 0, len(nodeToTappedPodIPMap)) + for nodeName := range nodeToTappedPodIPMap { + nodeNames = append(nodeNames, nodeName) + } + nodeSelectorRequirement := applyconfcore.NodeSelectorRequirement() + nodeSelectorRequirement.WithKey("kubernetes.io/hostname") + nodeSelectorRequirement.WithOperator(core.NodeSelectorOpIn) + nodeSelectorRequirement.WithValues(nodeNames...) + nodeSelectorTerm := applyconfcore.NodeSelectorTerm() + nodeSelectorTerm.WithMatchExpressions(nodeSelectorRequirement) + nodeSelector := applyconfcore.NodeSelector() + nodeSelector.WithNodeSelectorTerms(nodeSelectorTerm) + nodeAffinity := applyconfcore.NodeAffinity() + nodeAffinity.WithRequiredDuringSchedulingIgnoredDuringExecution(nodeSelector) + affinity := applyconfcore.Affinity() + affinity.WithNodeAffinity(nodeAffinity) + + noExecuteToleration := applyconfcore.Toleration() + noExecuteToleration.WithOperator(core.TolerationOpExists) + noExecuteToleration.WithEffect(core.TaintEffectNoExecute) + noScheduleToleration := applyconfcore.Toleration() + noScheduleToleration.WithOperator(core.TolerationOpExists) + noScheduleToleration.WithEffect(core.TaintEffectNoSchedule) + + podSpec := applyconfcore.PodSpec() + podSpec.WithHostNetwork(true) + podSpec.WithDNSPolicy(core.DNSClusterFirstWithHostNet) + podSpec.WithTerminationGracePeriodSeconds(0) if linkServiceAccount { podSpec.WithServiceAccountName(serviceAccountName) } podSpec.WithContainers(agentContainer) - + podSpec.WithAffinity(affinity) + podSpec.WithTolerations(noExecuteToleration, noScheduleToleration) podTemplate := applyconfcore.PodTemplateSpec() podTemplate.WithLabels(map[string]string{"app": tapperPodName})