-
Notifications
You must be signed in to change notification settings - Fork 494
OCPBUGS-15934: use *resource.Quantity to not automatically set 0 #3815
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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
12 changes: 10 additions & 2 deletions
12
pkg/apis/machineconfiguration.openshift.io/v1/zz_generated.deepcopy.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package containerruntimeconfig | |
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "reflect" | ||
| "testing" | ||
|
|
@@ -494,10 +495,13 @@ func TestContainerRuntimeConfigCreate(t *testing.T) { | |
| f := newFixture(t) | ||
| f.newController() | ||
|
|
||
| logSizeMax := resource.MustParse("9k") | ||
| overlaySize := resource.MustParse("3G") | ||
|
|
||
| cc := newControllerConfig(ctrlcommon.ControllerConfigName, platform) | ||
| mcp := helpers.NewMachineConfigPool("master", nil, helpers.MasterSelector, "v0") | ||
| mcp2 := helpers.NewMachineConfigPool("worker", nil, helpers.WorkerSelector, "v0") | ||
| ctrcfg1 := newContainerRuntimeConfig("set-log-level", &mcfgv1.ContainerRuntimeConfiguration{LogLevel: "debug", LogSizeMax: resource.MustParse("9k"), OverlaySize: resource.MustParse("3G")}, metav1.AddLabelToSelector(&metav1.LabelSelector{}, "pools.operator.machineconfiguration.openshift.io/master", "")) | ||
| ctrcfg1 := newContainerRuntimeConfig("set-log-level", &mcfgv1.ContainerRuntimeConfiguration{LogLevel: "debug", LogSizeMax: &logSizeMax, OverlaySize: &overlaySize}, metav1.AddLabelToSelector(&metav1.LabelSelector{}, "pools.operator.machineconfiguration.openshift.io/master", "")) | ||
| ctrCfgKey, _ := getManagedKeyCtrCfg(mcp, f.client, ctrcfg1) | ||
| mcs1 := helpers.NewMachineConfig(getManagedKeyCtrCfgDeprecated(mcp), map[string]string{"node-role": "master"}, "dummy://", []ign3types.File{{}}) | ||
| mcs2 := mcs1.DeepCopy() | ||
|
|
@@ -531,10 +535,13 @@ func TestContainerRuntimeConfigUpdate(t *testing.T) { | |
| f := newFixture(t) | ||
| f.newController() | ||
|
|
||
| logSizeMax := resource.MustParse("9k") | ||
| overlaySize := resource.MustParse("3G") | ||
|
|
||
| cc := newControllerConfig(ctrlcommon.ControllerConfigName, platform) | ||
| mcp := helpers.NewMachineConfigPool("master", nil, helpers.MasterSelector, "v0") | ||
| mcp2 := helpers.NewMachineConfigPool("worker", nil, helpers.WorkerSelector, "v0") | ||
| ctrcfg1 := newContainerRuntimeConfig("set-log-level", &mcfgv1.ContainerRuntimeConfiguration{LogLevel: "debug", LogSizeMax: resource.MustParse("9k"), OverlaySize: resource.MustParse("3G")}, metav1.AddLabelToSelector(&metav1.LabelSelector{}, "pools.operator.machineconfiguration.openshift.io/master", "")) | ||
| ctrcfg1 := newContainerRuntimeConfig("set-log-level", &mcfgv1.ContainerRuntimeConfiguration{LogLevel: "debug", LogSizeMax: &logSizeMax, OverlaySize: &overlaySize}, metav1.AddLabelToSelector(&metav1.LabelSelector{}, "pools.operator.machineconfiguration.openshift.io/master", "")) | ||
| keyCtrCfg, _ := getManagedKeyCtrCfg(mcp, f.client, ctrcfg1) | ||
| mcs := helpers.NewMachineConfig(getManagedKeyCtrCfgDeprecated(mcp), map[string]string{"node-role": "master"}, "dummy://", []ign3types.File{{}}) | ||
| mcsUpdate := mcs.DeepCopy() | ||
|
|
@@ -1228,10 +1235,12 @@ func TestRegistriesValidation(t *testing.T) { | |
| // for the options in containerruntime config | ||
| func TestContainerRuntimeConfigOptions(t *testing.T) { | ||
| var ( | ||
| invalidPidsLimit int64 = 10 | ||
| validPidsLimit int64 = 2048 | ||
| validZerolimit int64 = 0 | ||
| invalidNegLimit int64 = -10 | ||
| invalidPidsLimit int64 = 10 | ||
| validPidsLimit int64 = 2048 | ||
| invalidLogSizeMax = resource.MustParse("3k") | ||
| validLogSizeMax = resource.MustParse("10k") | ||
| validZerolimit int64 = 0 | ||
| invalidNegLimit int64 = -10 | ||
| ) | ||
| failureTests := []struct { | ||
| name string | ||
|
|
@@ -1252,7 +1261,7 @@ func TestContainerRuntimeConfigOptions(t *testing.T) { | |
| { | ||
| name: "inalid value of max log size", | ||
| config: &mcfgv1.ContainerRuntimeConfiguration{ | ||
| LogSizeMax: resource.MustParse("3k"), | ||
| LogSizeMax: &invalidLogSizeMax, | ||
| }, | ||
| }, | ||
| { | ||
|
|
@@ -1288,7 +1297,7 @@ func TestContainerRuntimeConfigOptions(t *testing.T) { | |
| { | ||
| name: "valid max log size", | ||
| config: &mcfgv1.ContainerRuntimeConfiguration{ | ||
| LogSizeMax: resource.MustParse("10k"), | ||
| LogSizeMax: &validLogSizeMax, | ||
| }, | ||
| }, | ||
| { | ||
|
|
@@ -1324,6 +1333,74 @@ func TestContainerRuntimeConfigOptions(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestMarshalResourceQuantityOptionsJSON(t *testing.T) { | ||
| var ( | ||
| validLogSizeMax = resource.MustParse("10k") | ||
| validOverlaySize = resource.MustParse("10G") | ||
| ) | ||
|
|
||
| emptyValueTests := []struct { | ||
| name string | ||
| config *mcfgv1.ContainerRuntimeConfiguration | ||
| }{ | ||
| { | ||
| name: "valid log level, overlaySize/logsizeMax should not appear in json", | ||
| config: &mcfgv1.ContainerRuntimeConfiguration{ | ||
| LogLevel: "debug", | ||
| }, | ||
| }, | ||
| { | ||
| name: "valid value of default runtime, overlaySize/logsizeMax should not appear in json", | ||
| config: &mcfgv1.ContainerRuntimeConfiguration{ | ||
| DefaultRuntime: "crun", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| successTests := []struct { | ||
| name string | ||
| config *mcfgv1.ContainerRuntimeConfiguration | ||
| expectStr string | ||
| }{ | ||
| { | ||
| name: "valid max log size should appear in json", | ||
| config: &mcfgv1.ContainerRuntimeConfiguration{ | ||
| LogSizeMax: &validLogSizeMax, | ||
| LogLevel: "debug", | ||
| }, | ||
| expectStr: "\"logSizeMax\":\"10k\"", | ||
| }, | ||
| { | ||
| name: "valid max overlay size should appear in json", | ||
| config: &mcfgv1.ContainerRuntimeConfiguration{ | ||
| OverlaySize: &validOverlaySize, | ||
| LogLevel: "debug", | ||
| }, | ||
| expectStr: "\"overlaySize\":\"10G\"", | ||
| }, | ||
| } | ||
|
|
||
| // Successful Tests | ||
| for _, test := range successTests { | ||
| ctrcfg := newContainerRuntimeConfig(test.name, test.config, metav1.AddLabelToSelector(&metav1.LabelSelector{}, "", "")) | ||
| data, err := json.Marshal(ctrcfg) | ||
| if err != nil { | ||
| t.Errorf("%s: failed with %v. should have succeeded", test.name, err) | ||
| } | ||
| require.Contains(t, string(data), test.expectStr) | ||
| } | ||
|
|
||
| for _, test := range emptyValueTests { | ||
| ctrcfg := newContainerRuntimeConfig(test.name, test.config, metav1.AddLabelToSelector(&metav1.LabelSelector{}, "", "")) | ||
| data, err := json.Marshal(ctrcfg) | ||
| if err != nil { | ||
| t.Errorf("%s: failed with %v. should have succeeded", test.name, err) | ||
| } | ||
| require.NotContains(t, string(data), "\"overlaySize\"", "\"overlaySize\"") | ||
|
Contributor
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. Testing |
||
| require.NotContains(t, string(data), "\"logSizeMax\"", "\"logSizeMax\"") | ||
| } | ||
| } | ||
|
|
||
| func getKey(config *mcfgv1.ContainerRuntimeConfig, t *testing.T) string { | ||
| key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(config) | ||
| if err != nil { | ||
|
|
||
This file contains hidden or 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 hidden or 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
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.
Applies to all changes:
Doesn’t this change the semantics of previously-created CRs? If I understand the situation correctly, it’s possible that users create the CRs with these fields missing, and something (
patchContainerRuntimeConfigs??) updates them and adds"0"field values.In the old version, those 0 values were treated as missing, i.e. the system did exactly what the users wanted, just in a confusing way; with this PR, wouldn’t the
0values actually start being applied?I suppose one way to tell would be to add (uint? e2e?) tests with CRs of that kind, and ensure that both empty values and
"0"values are treated as missing. (Or maybe those tests already exist? I didn’t find them though a quick grep but I didn’t spend much time looking.)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.
0 values will not be applied in this PR. The drop-in files will not be created if
0values. https://github.com/openshift/machine-config-operator/pull/3815/files#diff-b2ef9db0d76c6145ec1bb5310134037bae64572ab47464d3223745c2a410d3e3R301There 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, my mistake, I didn’t notice that logic.
OverlaySizewill, AFAICS, still causemergeConfigChangesto be called, though with no edits. I guess that doesn’t make a difference.Aesthetically I’d prefer for the code to consistently use a single condition, so that we just have “set to a relevant value / not set to a relevant value”, not “unset / set to zero / set to non-zero” to track.
But that’s weak a code style preference, to be decided by MCO maintainers.