mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-10-31 10:18:13 +00:00 
			
		
		
		
	add verify script to catch most validation mutations
This commit is contained in:
		| @@ -80,6 +80,7 @@ QUICK_PATTERNS+=( | ||||
|   "verify-vendor-licenses.sh" | ||||
|   "verify-gofmt.sh" | ||||
|   "verify-imports.sh" | ||||
|   "verify-non-mutating-validation.sh" | ||||
|   "verify-pkg-names.sh" | ||||
|   "verify-readonly-packages.sh" | ||||
|   "verify-spelling.sh" | ||||
|   | ||||
							
								
								
									
										45
									
								
								hack/verify-non-mutating-validation.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										45
									
								
								hack/verify-non-mutating-validation.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,45 @@ | ||||
| #!/usr/bin/env bash | ||||
|  | ||||
| # Copyright 2021 The Kubernetes Authors. | ||||
| # | ||||
| # 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. | ||||
|  | ||||
| # This script checks that validation files do not mutate their inputs. | ||||
| # Usage: `hack/verify-non-mutating-validation.sh`. | ||||
|  | ||||
| set -o errexit | ||||
| set -o nounset | ||||
| set -o pipefail | ||||
|  | ||||
| KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. | ||||
| source "${KUBE_ROOT}/hack/lib/init.sh" | ||||
|  | ||||
| mutationOutput=$(find . -name validation.go -print0 | xargs -0 egrep -n ' = old' | grep -v '// +k8s:verify-mutation:reason=clone' || true) | ||||
| foundMutation=${#mutationOutput} | ||||
| # when there's no match, there is a newline | ||||
| if [ "$foundMutation" -gt "1" ]; then | ||||
|   echo "${mutationOutput}" | ||||
|   echo "It looks like an assignment of a value using the old object.  This is a heuristic check.  If a mutation is happening in validation please fix it." | ||||
|   echo "If a mutation of arguments is not happening, you can exempt a line using '// +k8s:verify-mutation:reason=clone'." | ||||
|   exit 1 | ||||
| fi | ||||
|  | ||||
| mutationOutput=$(! find . -name validation.go -print0 | xargs -0 egrep -n 'old.* = ' | grep -v '// +k8s:verify-mutation:reason=clone' || true) | ||||
| foundMutation=${#mutationOutput} | ||||
| # when there's no match, there is a newline | ||||
| if [ "$foundMutation" -gt "1" ]; then | ||||
|   echo "${mutationOutput}" | ||||
|   echo "It looks like an assignment to the old object is happening.  This is a heuristic check.  If a mutation is happening in validation please fix it." | ||||
|   echo "If a mutation of arguments is not happening, you can exempt a line using '// +k8s:verify-mutation:reason=clone'." | ||||
|   exit 1 | ||||
| fi | ||||
		Reference in New Issue
	
	Block a user
	 David Eads
					David Eads