Skip to content

Commit

Permalink
Pod Node Affinity
Browse files Browse the repository at this point in the history
inv tidy
  • Loading branch information
jbartosik committed Dec 30, 2024
1 parent 892e6d2 commit 1110fd9
Show file tree
Hide file tree
Showing 27 changed files with 335 additions and 38 deletions.
2 changes: 1 addition & 1 deletion comp/otelcol/ddflareextension/impl/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ require (
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect
github.com/Code-Hex/go-generics-cache v1.5.1 // indirect
github.com/DataDog/agent-payload/v5 v5.0.138 // indirect
github.com/DataDog/agent-payload/v5 v5.0.139-0.20241227121136-afacfe086aee // indirect
github.com/DataDog/datadog-agent/comp/core/config v0.59.0 // indirect
github.com/DataDog/datadog-agent/comp/core/flare/builder v0.59.0 // indirect
github.com/DataDog/datadog-agent/comp/core/flare/types v0.59.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions comp/otelcol/ddflareextension/impl/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion comp/otelcol/logsagentpipeline/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ replace (
require github.com/DataDog/datadog-agent/pkg/logs/pipeline v0.56.0-rc.3

require (
github.com/DataDog/agent-payload/v5 v5.0.138 // indirect
github.com/DataDog/agent-payload/v5 v5.0.139-0.20241227121136-afacfe086aee // indirect
github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface v0.56.0-rc.3 // indirect
github.com/DataDog/datadog-agent/comp/core/secrets v0.59.0 // indirect
github.com/DataDog/datadog-agent/comp/core/telemetry v0.56.0-rc.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions comp/otelcol/logsagentpipeline/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ require (
)

require (
github.com/DataDog/agent-payload/v5 v5.0.138 // indirect
github.com/DataDog/agent-payload/v5 v5.0.139-0.20241227121136-afacfe086aee // indirect
github.com/DataDog/datadog-agent/comp/core/flare/builder v0.56.0-rc.3 // indirect
github.com/DataDog/datadog-agent/comp/core/flare/types v0.56.0-rc.3 // indirect
github.com/DataDog/datadog-agent/comp/core/secrets v0.59.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions comp/otelcol/logsagentpipeline/logsagentpipelineimpl/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ require (
)

require (
github.com/DataDog/agent-payload/v5 v5.0.138 // indirect
github.com/DataDog/agent-payload/v5 v5.0.139-0.20241227121136-afacfe086aee // indirect
github.com/DataDog/datadog-agent/comp/core/config v0.57.1 // indirect
github.com/DataDog/datadog-agent/comp/core/flare/builder v0.57.1 // indirect
github.com/DataDog/datadog-agent/comp/core/flare/types v0.57.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions comp/otelcol/otlp/components/exporter/datadogexporter/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ require (
)

require (
github.com/DataDog/agent-payload/v5 v5.0.138 // indirect
github.com/DataDog/agent-payload/v5 v5.0.139-0.20241227121136-afacfe086aee // indirect
github.com/DataDog/datadog-agent/comp/core/config v0.57.1 // indirect
github.com/DataDog/datadog-agent/comp/core/flare/builder v0.57.1 // indirect
github.com/DataDog/datadog-agent/comp/core/flare/types v0.57.1 // indirect
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,72 @@ func ExtractPod(p *corev1.Pod) *model.Pod {
}
}

if p.Spec.Affinity != nil && p.Spec.Affinity.NodeAffinity != nil {
podModel.NodeAffinity = &model.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: convertNodeSelector(p.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution),
PreferredDuringSchedulingIgnoredDuringExecution: convertPreferredSchedulingTerm(p.Spec.Affinity.NodeAffinity.PreferredDuringSchedulingIgnoredDuringExecution),
}
}

return &podModel
}

func convertNodeSelector(ns *corev1.NodeSelector) *model.NodeSelector {
if ns == nil {
return nil
}
return &model.NodeSelector{
NodeSelectorTerms: convertNodeSelectorTerms(ns.NodeSelectorTerms),
}
}

func convertPreferredSchedulingTerm(terms []corev1.PreferredSchedulingTerm) []*model.PreferredSchedulingTerm {
if len(terms) == 0 {
return nil
}
var preferredTerms []*model.PreferredSchedulingTerm
for _, term := range terms {
preferredTerms = append(preferredTerms, &model.PreferredSchedulingTerm{
Preference: convertNodeSelectorTerm(term.Preference),
Weight: term.Weight,
})
}
return preferredTerms
}

func convertNodeSelectorTerms(terms []corev1.NodeSelectorTerm) []*model.NodeSelectorTerm {
if len(terms) == 0 {
return nil
}
var nodeSelectorTerms []*model.NodeSelectorTerm
for _, term := range terms {
nodeSelectorTerms = append(nodeSelectorTerms, convertNodeSelectorTerm(term))
}
return nodeSelectorTerms
}

func convertNodeSelectorTerm(term corev1.NodeSelectorTerm) *model.NodeSelectorTerm {
return &model.NodeSelectorTerm{
MatchExpressions: convertNodeSelectorRequirements(term.MatchExpressions),
MatchFields: convertNodeSelectorRequirements(term.MatchFields),
}
}

func convertNodeSelectorRequirements(requirements []corev1.NodeSelectorRequirement) []*model.LabelSelectorRequirement {
if len(requirements) == 0 {
return nil
}
var nodeSelectorRequirements []*model.LabelSelectorRequirement
for _, req := range requirements {
nodeSelectorRequirements = append(nodeSelectorRequirements, &model.LabelSelectorRequirement{
Key: req.Key,
Operator: string(req.Operator),
Values: req.Values,
})
}
return nodeSelectorRequirements
}

// ExtractPodTemplateResourceRequirements extracts resource requirements of containers and initContainers into model.ResourceRequirements
func ExtractPodTemplateResourceRequirements(template corev1.PodTemplateSpec) []*model.ResourceRequirements {
return extractPodResourceRequirements(template.Spec.Containers, template.Spec.InitContainers)
Expand Down
Loading

0 comments on commit 1110fd9

Please sign in to comment.