-
Notifications
You must be signed in to change notification settings - Fork 148
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
fix(support-bundle): agent doesn't respect node-selector and taint-toleration #1798
Merged
innobead
merged 5 commits into
longhorn:master
from
c3y1huang:fix-support-bundle-agent-missing-nodeselector-taintolerate
Apr 8, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b8cc0fc
fix(support-bundle): pass node-selector to agent
c3y1huang 7f4ac37
fix(support-bundle): pass taint-toleration to agent
c3y1huang c701184
refactor(setting): unmarshal tolerations
c3y1huang 7c9ce22
test(types): UnmarshalTolerations
c3y1huang 099e24e
Merge branch 'master' into fix-support-bundle-agent-missing-nodeselec…
innobead File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func TestParseToleration(t *testing.T) { | ||
type testCase struct { | ||
input string | ||
|
||
expectedToleration []corev1.Toleration | ||
expectError bool | ||
} | ||
testCases := map[string]testCase{ | ||
"valid empty setting": { | ||
input: "", | ||
expectedToleration: []corev1.Toleration{}, | ||
expectError: false, | ||
}, | ||
"valid key:NoSchedule": { | ||
input: "key:NoSchedule", | ||
expectedToleration: []corev1.Toleration{ | ||
{ | ||
Key: "key", | ||
Value: "", | ||
Operator: corev1.TolerationOpExists, | ||
Effect: corev1.TaintEffectNoSchedule, | ||
}, | ||
}, | ||
expectError: false, | ||
}, | ||
"valid key=value:NoExecute": { | ||
input: "key=value:NoExecute", | ||
expectedToleration: []corev1.Toleration{ | ||
{ | ||
Key: "key", | ||
Value: "value", | ||
Operator: corev1.TolerationOpEqual, | ||
Effect: corev1.TaintEffectNoExecute, | ||
}, | ||
}, | ||
expectError: false, | ||
}, | ||
"valid key=value:PreferNoSchedule": { | ||
input: "key=value:PreferNoSchedule", | ||
expectedToleration: []corev1.Toleration{ | ||
{ | ||
Key: "key", | ||
Value: "value", | ||
Operator: corev1.TolerationOpEqual, | ||
Effect: corev1.TaintEffectPreferNoSchedule, | ||
}, | ||
}, | ||
expectError: false, | ||
}, | ||
"valid key0:NoSchedule;key1=value:NoExecute": { | ||
input: "key0:NoSchedule;key1=value:NoExecute", | ||
expectedToleration: []corev1.Toleration{ | ||
{ | ||
Key: "key0", | ||
Value: "", | ||
Operator: corev1.TolerationOpExists, | ||
Effect: corev1.TaintEffectNoSchedule, | ||
}, | ||
{ | ||
Key: "key1", | ||
Value: "value", | ||
Operator: corev1.TolerationOpEqual, | ||
Effect: corev1.TaintEffectNoExecute, | ||
}, | ||
}, | ||
expectError: false, | ||
}, | ||
"invalid key:InvalidEffect": { | ||
input: "key:InvalidEffect", | ||
expectedToleration: nil, | ||
expectError: true, | ||
}, | ||
"invalid key=value=NoSchedule": { | ||
input: "key=value=NoSchedule", | ||
expectedToleration: nil, | ||
expectError: true, | ||
}, | ||
} | ||
|
||
for name, test := range testCases { | ||
fmt.Printf("testing %v\n", name) | ||
|
||
toleration, err := UnmarshalTolerations(test.input) | ||
if !reflect.DeepEqual(toleration, test.expectedToleration) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: There should be some assert functions able to use? |
||
t.Errorf("unexpected toleration:\nGot: %v\nWant: %v", toleration, test.expectedToleration) | ||
} | ||
|
||
if test.expectError && err == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: The same. Suggest using assert like https://pkg.go.dev/github.com/stretchr/testify/assert. |
||
t.Errorf("unexpected error: %v", err) | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 mean you can use
tolerations []corev1.Toleration
instead of querying the setting again.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.
Got it, I was confused because
toleration []corev1.Toleration
is unmarshalled from the setting, directly using it needs to be put back to a string again.I've moved the unmarshalling into the same method so it won't be called again. PTAL, thank you.