-
Notifications
You must be signed in to change notification settings - Fork 153
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
base: master
Are you sure you want to change the base?
Conversation
…iveValue Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
if node.TypeX == nil { | ||
// The replicas field is not found in the old manifest. | ||
before = "" | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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. 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think one side of diff defines spec.replicas, and the other side does not; this occurs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ffjlabo
Without this check, this test case fails. (this test is pipedv1's, but it's same logic because this comment thread is on the backported line)
https://github.com/pipe-cd/pipecd/pull/5341/files#diff-4c74652886416486eb7b42cc641e5fd09672015dbaeeb19e3dddefaf81e913dbR1351-R1381
--- FAIL: TestCheckReplicasChange (0.00s)
--- FAIL: TestCheckReplicasChange/replicas_field_added (0.00s)
/Users/s01062/ghq/github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/deployment/determine_test.go:1394:
Error Trace: /Users/s01062/ghq/github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/deployment/determine_test.go:1394
Error: Not equal:
expected: ""
actual : "<invalid Value>"
Diff:
--- Expected
+++ Actual
@@ -1 +1 @@
-
+<invalid Value>
Test: TestCheckReplicasChange/replicas_field_added
Messages: before
FAIL
FAIL github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/deployment 0.954s
FAIL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think one side of diff defines spec.replicas, and the other side does not; this occurs.
I got your point. You are right. Sorry, I misunderstood. 🙏
We need it in such a case.
IMO, It might be better to init before
as empty first. I felt easy to guess the value.
before = ""
if node.TypeX != nil {
// found spec.replicas in the old manifests
before = node.StringX()
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I revised the whole, how about this code?
// checkReplicasChange checks if the replicas field is changed.
func checkReplicasChange(ns diff.Nodes) (before, after string, changed bool) {
const replicasQuery = `^spec\.replicas$`
node, err := ns.FindOne(replicasQuery)
if err != nil {
// no difference between the before and after manifests, or unknown error occurred.
return "", "", false
}
if node.TypeX == nil {
// The replicas field is not found in the before manifest.
// There is difference between the before and after manifests, So it means the replicas field is added in the after manifest.
return "", node.StringY(), true
}
if node.TypeY == nil {
// The replicas field is not found in the after manifest.
// There is difference between the before and after manifests, So it means the replicas field is removed in the after manifest.
return node.StringX(), "", true
}
return node.StringX(), node.StringY(), true
}
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5341 +/- ##
==========================================
+ Coverage 25.31% 25.34% +0.03%
==========================================
Files 444 444
Lines 47641 47671 +30
==========================================
+ Hits 12059 12081 +22
- Misses 34640 34646 +6
- Partials 942 944 +2 ☔ View full report in Codecov by Sentry. |
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