-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add --threshold flag to nomos vet
- Added a new `--threshold[=MAX]` option to the `nomos vet` command that allows specifying a maximum number of objects. If set, it will enable validation that will error if the number of objects exceeds the specified value, after rendering and cluster selectors. By default, this validation is disabled. If you pass the option without a value, the default value of 1000 is used. - The value 1000 was chosen as a compromise between scale and safety. Technically we know form e2e tests that the inventory can actually hold at least 5000 objects without needing to disable the status, however, this is unsafe to do in production because each of those objects could error, which adds error conditions to the inventory status, which can significantly increase the size of the inventory. - Unlike other options, this option has an optional value and different defaults when specified than when not specified. This requires the flag and value to be sent in the same argument, like `--threshold=1000`, instead of as two different arguments, like `--threshold 1000`. - If the option is specified with a value of zero or lower, the validation will be disabled, the same as if the option was not specified.
- Loading branch information
Showing
7 changed files
with
145 additions
and
9 deletions.
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
50 changes: 50 additions & 0 deletions
50
pkg/importer/analyzer/validation/system/max_object_count_validator.go
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,50 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package system | ||
|
||
import ( | ||
"kpt.dev/configsync/pkg/status" | ||
) | ||
|
||
// DefaultMaxObjectCount is the default maximum number of objects allowed in a | ||
// single inventory, if the validator is enabled. | ||
// | ||
// This is only used by nomos vet, not the reconciler. It will not block syncing. | ||
// | ||
// The value 1000 was chosen as a compromise between scale and safety. | ||
// Technically we know form e2e tests that the inventory can actually hold at | ||
// least 5000 objects without needing to disable the status, however, this is | ||
// unsafe to do in production because each of those objects could error, which | ||
// adds error conditions to the inventory status, which can significantly | ||
// increase the size of the inventory. | ||
const DefaultMaxObjectCount int = 1000 | ||
|
||
// MaxObjectCountCode is the error code for MaxObjectCount | ||
const MaxObjectCountCode = "1070" | ||
|
||
var maxObjectCountErrorBuilder = status.NewErrorBuilder(MaxObjectCountCode) | ||
|
||
// MaxObjectCountError reports that the source includes more than the maximum | ||
// number of objects. | ||
func MaxObjectCountError(max, found int) status.Error { | ||
return maxObjectCountErrorBuilder. | ||
Sprintf(`Maximum number of objects exceeded. Found %d, but expected no more than %d. `+ | ||
`Reduce the number of objects being synced to this cluster in your source of truth `+ | ||
`to prevent your ResourceGroup inventory object from exceeding the etcd object size limit. `+ | ||
`For instructions on how to break up a repository into multiple repositories, see `+ | ||
`https://cloud.google.com/kubernetes-engine/enterprise/config-sync/docs/how-to/breaking-up-repo`, | ||
found, max). | ||
Build() | ||
} |
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,40 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package validate | ||
|
||
import ( | ||
"kpt.dev/configsync/pkg/importer/analyzer/ast" | ||
"kpt.dev/configsync/pkg/importer/analyzer/validation/system" | ||
"kpt.dev/configsync/pkg/status" | ||
) | ||
|
||
// MaxObjectCount verifies that the number of managed resources does not exceed | ||
// the specified maximum. | ||
func MaxObjectCount(max int) func([]ast.FileObject) status.MultiError { | ||
if max <= 0 { | ||
return noOpValidator | ||
} | ||
return func(objs []ast.FileObject) status.MultiError { | ||
found := len(objs) | ||
if found > max { | ||
return system.MaxObjectCountError(max, found) | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func noOpValidator([]ast.FileObject) status.MultiError { | ||
return nil | ||
} |
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