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

[profiles] Reduce patch frequency (#1317) #1329

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
45 changes: 30 additions & 15 deletions controllers/datadogagent/controller_reconcile_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,30 +283,45 @@ func (r *Reconciler) labelNodesWithProfiles(ctx context.Context, profilesByNode
return err
}

_, profileLabelExists := node.Labels[agentprofile.ProfileLabelKey]

newLabels := map[string]string{}
for k, v := range node.Labels {
// If the profile uses the old profile label key, it should be removed
if k != agentprofile.OldProfileLabelKey {
newLabels[k] = v
}
}
labelsToRemove := map[string]bool{}
labelsToAddOrChange := map[string]string{}

// If the profile is the default one and the label exists in the node,
// it should be removed.
if isDefaultProfile && profileLabelExists {
delete(newLabels, agentprofile.ProfileLabelKey)
if isDefaultProfile {
if _, profileLabelExists := node.Labels[agentprofile.ProfileLabelKey]; profileLabelExists {
labelsToRemove[agentprofile.ProfileLabelKey] = true
}
} else {
// If the profile is not the default one and the label does not exist in
// the node, it should be added. If the label value is outdated, it
// should be updated.
if profileLabelValue := node.Labels[agentprofile.ProfileLabelKey]; profileLabelValue != profileNamespacedName.Name {
labelsToAddOrChange[agentprofile.ProfileLabelKey] = profileNamespacedName.Name
}
}

// Remove old profile label key if it is present
if _, oldProfileLabelExists := node.Labels[agentprofile.OldProfileLabelKey]; oldProfileLabelExists {
labelsToRemove[agentprofile.OldProfileLabelKey] = true
}

// If the profile is not the default one and the label does not exist in
// the node, it should be added.
if !isDefaultProfile && !profileLabelExists {
newLabels[agentprofile.ProfileLabelKey] = profileNamespacedName.Name
if len(labelsToRemove) > 0 || len(labelsToAddOrChange) > 0 {
for k, v := range node.Labels {
if _, ok := labelsToRemove[k]; ok {
continue
}
newLabels[k] = v
}

for k, v := range labelsToAddOrChange {
newLabels[k] = v
}
}

if len(newLabels) == 0 {
return nil
continue
}

modifiedNode := node.DeepCopy()
Expand Down
Loading
Loading