-
Notifications
You must be signed in to change notification settings - Fork 829
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CRD OpenAPI Spec for ObjectMeta & PodTemplateSpec (#1956)
* CRD OpenAPI Spec for ObjectMeta & PodTemplateSpec This PR provides the mechanisms to pull core Kubernetes resource OpenAPI schemas out of the API, and customise and convert them into a format that is embeddable in our own CRD specifications. This has been used to extract OpenAPI schemas for `ObjectMeta`, and `PodTemplateSpec`, and then embedded in `GameServer` as well as parent CRDs, creating a layer of validation for Pods definitions that are implemented via a GameServer. Also included in a new helm config option of `gameservers.podPreserveUnknownFields` in case a user needs to escape the field pruning on a Pod, or if PR causes a bug of any kind. Also worth noting, this is not comprehensive validation, and therefore I have not closed the the referenced issue. Work on #1298 * Generated yaml for Schema improvements * Upgrade Helm to 3.5.0 Needed upgrade to fix bug wth upgrade. * Updates based on review - Fix for typo in license. - Fix comment in test to be more clear. - Rebase against master and regen index.yaml
- Loading branch information
1 parent
7488d80
commit 8b8bb34
Showing
18 changed files
with
14,719 additions
and
137 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright 2021 Google LLC All Rights Reserved. | ||
# | ||
# 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 code was autogenerated. Do not edit directly. | ||
|
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,85 @@ | ||
#!/usr/bin/env bash | ||
|
||
# | ||
# Copyright 2021 Google LLC All Rights Reserved. | ||
# | ||
# 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. | ||
# | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
do_expand() { | ||
echo "Processing $1" | ||
jq '.definitions."'"$1"'"' ./openapi.json >"$1.json" | ||
children=$(jq -r '..|objects|.["$ref"]|select (.!=null)' "$1.json" | sed 's!#/definitions/!!') | ||
if [ -n "$children" ]; then | ||
while IFS= read -r line; do | ||
do_expand "$line" | ||
done <<<"$children" | ||
fi | ||
} | ||
|
||
json_2_helm_yaml() { | ||
yaml="_$1.yaml" | ||
echo "Converting to YAML: $1" | ||
./yq eval -P "$1.json" >"$yaml" | ||
|
||
echo "{{- define \"$1\" }}" | cat ../boilerplate.yaml.txt - "$yaml" | sponge "$yaml" | ||
echo "{{- end }}" >>"$yaml" | ||
mv "$yaml" ../../install/helm/agones/templates/crds/k8s/ | ||
} | ||
|
||
rm -r ./tmp || true | ||
mkdir tmp | ||
cd tmp | ||
kubectl proxy & | ||
|
||
# install deps while waiting for kubectl proxy to startup | ||
wget https://github.com/mikefarah/yq/releases/download/v4.3.2/yq_linux_amd64 -O yq | ||
apt install -y moreutils | ||
chmod +x ./yq | ||
|
||
# cleanup and format | ||
curl http://127.0.0.1:8001/openapi/v2 | jq 'del(.. | .["x-kubernetes-patch-strategy"]?, .["x-kubernetes-patch-merge-key"]?, .["x-kubernetes-list-type"]?)' | | ||
jq 'del(.. | .["x-kubernetes-group-version-kind"]?, .["x-kubernetes-list-map-keys"]? )' >openapi.json | ||
do_expand "io.k8s.api.core.v1.PodTemplateSpec" | ||
|
||
# do any editing you need to do to any types here, before they are expanded. | ||
# creationTimestamp is defaulted to it's zero value, which gets serialised as "null", so we have to set it as nullable. | ||
jq '.properties.creationTimestamp.nullable = true' io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta.json | sponge io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta.json | ||
# Make IntOrString type have `x-kubernetes-int-or-string` member | ||
jq '.["x-kubernetes-int-or-string"] = true' io.k8s.apimachinery.pkg.util.intstr.IntOrString.json | jq 'del(.type)' | sponge io.k8s.apimachinery.pkg.util.intstr.IntOrString.json | ||
|
||
# easier debugging if something goes wrong, still have the original | ||
mkdir orig | ||
cp *.json orig | ||
rm openapi.json | ||
|
||
for f in *.json; do | ||
echo "Expanding $f" | ||
# remove description, because there is usually another description when at its replacement point | ||
# replace \" with \\" as it get re-unescaped somewhere in the pipe | ||
# any "foo\nbar" values need their \n escaped | ||
# remove top and bottom line to get rid of first { and last } (we know all are formatted because jq) | ||
# then format for multiline - replace real multilines breaks with \n | ||
contents=$(cat "$f" | jq 'del(.description)' | sed 's/\\n/\\\\n/g' | sed '$d' | sed '1d' | sed ':a;N;$!ba;s/\n/\\n/g' | sed 's/\$/\\$/g' | sed 's@\"@\\"@g') | ||
ref=$(basename "$f" .json) | ||
|
||
find -maxdepth 1 -name '*.json' | xargs sed -i 's@"$ref": "#/definitions/'"$ref"'"@'"$contents"'@g' | ||
done | ||
|
||
# convert the ones you want to include via helm to yaml | ||
json_2_helm_yaml "io.k8s.api.core.v1.PodTemplateSpec" | ||
json_2_helm_yaml "io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta" |
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
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
Oops, something went wrong.