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

DDA "refactor": moving functions to helpers to make the main reconcile loop leaner #1727

Open
wants to merge 1 commit into
base: ddai
Choose a base branch
from

Conversation

tbavelier
Copy link
Member

What does this PR do?

A brief description of the change being made with this pull request.

Motivation

What inspired you to submit this pull request?

Additional Notes

Anything else we should know when reviewing?

Minimum Agent Versions

Are there minimum versions of the Datadog Agent and/or Cluster Agent required?

  • Agent: vX.Y.Z
  • Cluster Agent: vX.Y.Z

Describe your test plan

Write there any instructions and details you may have to test your PR.

Checklist

  • PR has at least one valid label: bug, enhancement, refactoring, documentation, tooling, and/or dependencies
  • PR has a milestone or the qa/skip-qa label

// applyAndCleanupDependencies applies pending changes and cleans up unused dependencies.
func (r *Reconciler) applyAndCleanupDependencies(ctx context.Context, logger logr.Logger, depsStore *store.Store) error {
var errs []error
errs = append(errs, depsStore.Apply(ctx, r.client)...)

Choose a reason for hiding this comment

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

🔵 Code Quality Violation

Combine assignment with declaration (...read more)

In Go, it is recommended to avoid using separate variable declaration and assignment statements and instead prefer initializing variables directly in the declaration.

Here are a few reasons why:

  1. Simplicity and readability: Initializing a variable in the declaration with var x uint = 1 provides a clear and concise way to express the intent of assigning an initial value to the variable. It reduces unnecessary lines of code, making the code more readable and easier to understand.
  2. Avoiding empty initial values: If you declare a variable with var x uint and then assign it a value of 1 separately, it might initially have an undesired default value (in this case, 0) before you assign the actual desired value. By initializing the variable directly in the declaration, you ensure it starts with the desired initial value.
  3. Encouraging good practice: Initializing variables in the declaration is a recommended coding practice in Go. It follows the principle of declaring variables closer to their usage, promotes legible code, and is widely accepted in the Go community.

Therefore, it is preferable to use var x uint = 1 rather than declaring the variable on one line and assigning it on another. This approach improves code clarity, reduces unnecessary lines, and ensures variables start with the desired initial value.

View in Datadog  Leave us feedback  Documentation

@codecov-commenter
Copy link

codecov-commenter commented Feb 25, 2025

Codecov Report

Attention: Patch coverage is 46.87500% with 85 lines in your changes missing coverage. Please review.

Project coverage is 49.25%. Comparing base (661ccc9) to head (ecba638).

Files with missing lines Patch % Lines
...er/datadogagent/controller_reconcile_v2_helpers.go 45.92% 56 Missing and 17 partials ⚠️
...controller/datadogagent/controller_reconcile_v2.go 52.00% 6 Missing and 6 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             ddai    #1727      +/-   ##
==========================================
- Coverage   49.25%   49.25%   -0.01%     
==========================================
  Files         221      222       +1     
  Lines       21357    21420      +63     
==========================================
+ Hits        10520    10550      +30     
- Misses      10290    10317      +27     
- Partials      547      553       +6     
Flag Coverage Δ
unittests 49.25% <46.87%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...controller/datadogagent/controller_reconcile_v2.go 55.15% <52.00%> (+3.25%) ⬆️
...er/datadogagent/controller_reconcile_v2_helpers.go 45.92% <45.92%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 661ccc9...ecba638. Read the comment docs.

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.

2 participants