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

Add profile label key to node affinity (#1302) #1324

Merged
merged 1 commit into from
Jul 26, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions controllers/datadogagent_controller_v2_profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ var _ = Describe("V2 Controller - DatadogAgentProfile", func() {
Operator: v1.NodeSelectorOpIn,
Values: []string{"3"},
},
{
Key: agentprofile.ProfileLabelKey,
Operator: v1.NodeSelectorOpIn,
Values: []string{profile.Name},
},
},
},
},
Expand Down Expand Up @@ -291,6 +296,11 @@ var _ = Describe("V2 Controller - DatadogAgentProfile", func() {
Operator: v1.NodeSelectorOpIn,
Values: []string{"1", "2"},
},
{
Key: agentprofile.ProfileLabelKey,
Operator: v1.NodeSelectorOpIn,
Values: []string{profile.Name},
},
},
},
},
Expand Down Expand Up @@ -418,6 +428,11 @@ var _ = Describe("V2 Controller - DatadogAgentProfile", func() {
Operator: v1.NodeSelectorOpIn,
Values: []string{"1"},
},
{
Key: agentprofile.ProfileLabelKey,
Operator: v1.NodeSelectorOpIn,
Values: []string{profile.Name},
},
},
},
},
Expand Down Expand Up @@ -577,6 +592,11 @@ var _ = Describe("V2 Controller - DatadogAgentProfile", func() {
Operator: v1.NodeSelectorOpIn,
Values: []string{"1"},
},
{
Key: agentprofile.ProfileLabelKey,
Operator: v1.NodeSelectorOpIn,
Values: []string{profiles[0].Name},
},
},
},
},
Expand Down Expand Up @@ -609,6 +629,11 @@ var _ = Describe("V2 Controller - DatadogAgentProfile", func() {
Operator: v1.NodeSelectorOpIn,
Values: []string{"2"},
},
{
Key: agentprofile.ProfileLabelKey,
Operator: v1.NodeSelectorOpIn,
Values: []string{profiles[1].Name},
},
},
},
},
Expand Down Expand Up @@ -762,6 +787,11 @@ var _ = Describe("V2 Controller - DatadogAgentProfile", func() {
Operator: v1.NodeSelectorOpIn,
Values: []string{"1"},
},
{
Key: agentprofile.ProfileLabelKey,
Operator: v1.NodeSelectorOpIn,
Values: []string{profiles[0].Name},
},
},
},
},
Expand Down Expand Up @@ -903,6 +933,11 @@ var _ = Describe("V2 Controller - DatadogAgentProfile", func() {
Operator: v1.NodeSelectorOpIn,
Values: []string{"1"},
},
{
Key: agentprofile.ProfileLabelKey,
Operator: v1.NodeSelectorOpIn,
Values: []string{profile.Name},
},
},
},
},
Expand Down Expand Up @@ -1027,6 +1062,11 @@ var _ = Describe("V2 Controller - DatadogAgentProfile", func() {
Operator: v1.NodeSelectorOpIn,
Values: []string{"2"},
},
{
Key: agentprofile.ProfileLabelKey,
Operator: v1.NodeSelectorOpIn,
Values: []string{profile.Name},
},
},
},
},
Expand Down
13 changes: 12 additions & 1 deletion pkg/agentprofile/agent_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func affinityOverride(profile *datadoghqv1alpha1.DatadogAgentProfile) *v1.Affini
RequiredDuringSchedulingIgnoredDuringExecution: &v1.NodeSelector{
NodeSelectorTerms: []v1.NodeSelectorTerm{
{
MatchExpressions: profile.Spec.ProfileAffinity.ProfileNodeAffinity,
MatchExpressions: append(profile.Spec.ProfileAffinity.ProfileNodeAffinity, profileLabelKeyNSR(profile.Name)),
},
},
},
Expand All @@ -199,6 +199,17 @@ func affinityOverride(profile *datadoghqv1alpha1.DatadogAgentProfile) *v1.Affini
return affinity
}

// profileLabelKeyNSR returns the NodeSelectorRequirement for a profile to be
// applied to nodes with the following label:
// agent.datadoghq.com/datadogagentprofile:<profile-name>
func profileLabelKeyNSR(profileName string) v1.NodeSelectorRequirement {
return v1.NodeSelectorRequirement{
Key: ProfileLabelKey,
Operator: v1.NodeSelectorOpIn,
Values: []string{profileName},
}
}

// affinityOverrideForDefaultProfile returns the affinity override that should
// be applied to the default profile. The default profile should be applied to
// all nodes that don't have the agent.datadoghq.com/datadogagentprofile label.
Expand Down
8 changes: 7 additions & 1 deletion pkg/agentprofile/agent_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ func TestOverrideFromProfile(t *testing.T) {
Operator: v1.NodeSelectorOpIn,
Values: []string{"linux"},
},
{
Key: ProfileLabelKey,
Operator: v1.NodeSelectorOpIn,
Values: []string{"linux"},
},
},
},
},
Expand Down Expand Up @@ -396,7 +401,7 @@ func TestDaemonSetName(t *testing.T) {
}
}

func TestPriorityClassNameOverride(t *testing.T) {
func Test_priorityClassNameOverride(t *testing.T) {
tests := []struct {
name string
profile v1alpha1.DatadogAgentProfile
Expand Down Expand Up @@ -474,6 +479,7 @@ func TestPriorityClassNameOverride(t *testing.T) {
})
}
}

func Test_labelsOverride(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading