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 checkReplicasChange function to detect changes in replicas field #5341

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Warashi
Copy link
Contributor

@Warashi Warashi commented Nov 15, 2024

What this PR does:

Why we need it:

We chose a quick sync strategy when the diffs are only replicas.
We must build a summary message with the workload changed, so we must check it.

Which issue(s) this PR fixes:

Part of #4980

Does this PR introduce a user-facing change?: Yes

  • How are users affected by this change:
    When users delete or add the spec.replicas field on the Deployment manifest, they can view the plan summary as expected. Without this PR, they will see an invalid value.

  • Is this breaking change: No

  • How to migrate (if breaking change): N/A

Comment on lines 434 to 437
if node.TypeX == nil {
// The replicas field is not found in the old manifest.
before = ""
}
Copy link
Contributor Author

@Warashi Warashi Nov 15, 2024

Choose a reason for hiding this comment

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

🤔 oops, we should put this before as "nil"?
I could not determine whether the empty string or "nil" is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@khanhtc1202 @t-kikuc @ffjlabo
WDYT about this?

Copy link
Member

Choose a reason for hiding this comment

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

@Warashi
When does node.TypeX == nil occur?
I think we should clarify the situation to determine it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ffjlabo Sorry for forgetting to write it.
When the replicas field is not found in the old manifests, node.TypeX becomes nil and node.ValueX becomes invalid value.

Copy link
Member

Choose a reason for hiding this comment

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

@Warashi

@ffjlabo Sorry for forgetting to write it.
When the replicas field is not found in the old manifests, node.TypeX becomes nil and node.ValueX becomes invalid value.

Thanks.

When the replicas field is not found in the old manifests,

It seems that the node is the one that has spec.replicas extracting by the logic before.
So we might not need to check it.

	const replicasQuery = `^spec\.replicas$`
	node, err := ns.FindOne(replicasQuery)

I'm sorry if I misunderstood. 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks 👍🏻

BTW, I realized it's better to return "<nil>" instead of an empty string because the before and after are used in this context.

if before, after, changed := checkReplicasChange(d); changed {
scales = append(scales, fmt.Sprintf("%s/%s from %s to %s", k.Kind, k.Name, before, after))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed on this commit
13625ca

Copy link
Member

Choose a reason for hiding this comment

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

@Warashi
Nice catch! I agree with it! The case is when there is nothing spec.replicas.

I think the <nil> value should be defined as const value. WDYT?
We might use it to express the same situation. e.g. checkImageTags.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ffjlabo
I think it's too early to make "<nil>" as constant because we use this only two places in one function, and we should use "<nil>" carefully because whether the "<nil>" or an empty string should be used is case-by-case.

For example, I think the image nginx should be just nginx, not nginx:<nil>.

Copy link
Member

Choose a reason for hiding this comment

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

@Warashi
I agree with it. Thanks. So let's rethink it when the same situation will occur. 👌

Copy link

codecov bot commented Nov 15, 2024

Codecov Report

Attention: Patch coverage is 67.56757% with 12 lines in your changes missing coverage. Please review.

Project coverage is 25.32%. Comparing base (00463a6) to head (13625ca).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
pkg/app/piped/planner/kubernetes/kubernetes.go 20.00% 10 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5341   +/-   ##
=======================================
  Coverage   25.31%   25.32%           
=======================================
  Files         444      444           
  Lines       47641    47688   +47     
=======================================
+ Hits        12059    12075   +16     
- Misses      34640    34668   +28     
- Partials      942      945    +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

…s field in manifests

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Copy link
Member

@ffjlabo ffjlabo left a comment

Choose a reason for hiding this comment

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

LGTM 🆗

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