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

feat: retain pod spec containers resources when sync pod reource #311

Merged
merged 3 commits into from
Feb 1, 2024

Conversation

wy-lucky
Copy link
Collaborator

@wy-lucky wy-lucky commented Jan 18, 2024

Some cloud vendors, when creating pods, add resource or dnsConfig configurations through webhooks, causing continuous update failures during deployment. Therefore, when distributing pods, we retain the spec.containers.resources and spec.dnsConfig field.

Copy link

codecov bot commented Jan 18, 2024

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (75c155f) 33.06% compared to head (c8c5d84) 33.24%.

Files Patch % Lines
pkg/controllers/sync/dispatch/retain.go 43.75% 6 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #311      +/-   ##
==========================================
+ Coverage   33.06%   33.24%   +0.18%     
==========================================
  Files         155      155              
  Lines       17876    17892      +16     
==========================================
+ Hits         5910     5948      +38     
+ Misses      11471    11435      -36     
- Partials      495      509      +14     
Flag Coverage Δ
unittests 33.24% <43.75%> (+0.18%) ⬆️

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

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

@@ -470,6 +470,9 @@ func retainContainers(desiredContainers, clusterContainers []interface{}) error
}

func retainContainer(desiredContainer, clusterContainer map[string]interface{}) error {
resources, _, _ := unstructured.NestedFieldNoCopy(clusterContainer, "resources")
Copy link
Member

Choose a reason for hiding this comment

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

What if NestedFieldNoCopy returns error or !exists? Pls explicitly handle boundary cases.

Copy link
Collaborator Author

@wy-lucky wy-lucky Jan 19, 2024

Choose a reason for hiding this comment

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

This field is a non-pointer struct, and during parsing, it will be considered as existing whether it is empty or has a value. Therefore, I did not add this check. I have observed similar situations in other code as well. Please also help me check if it is necessary to add it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When I constructed an empty map, the unit test did fail. So I added the necessary check.

wantErr bool
}{
{
name: "nil retain test",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
name: "nil retain test",
name: "retain nil resources",

},
},
{
name: "empty retain test",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
name: "empty retain test",
name: "retain empty resources",

},
},
{
name: "normal retain test",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
name: "normal retain test",
name: "retain non-empty resources",

desiredContainer: map[string]interface{}{
"name": "container-1",
"resources": map[string]interface{}{
"cpu": "500m",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be requests or limits here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it has been updated.

@mrlihanbo mrlihanbo self-requested a review February 1, 2024 01:58
@mrlihanbo mrlihanbo merged commit eba0d26 into kubewharf:main Feb 1, 2024
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants