Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cab5d61

Browse files
committed
Use kubernetes-client/gen generators to generate python client
1 parent 3595278 commit cab5d61

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

scripts/update-client.sh

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,24 @@ pushd "${CLIENT_ROOT}" > /dev/null
4040
CLIENT_ROOT=`pwd`
4141
popd > /dev/null
4242

43-
echo "--- Downloading and processing OpenAPI spec"
44-
python "${SCRIPT_ROOT}/preprocess_spec.py"
43+
TEMP_FOLDER=$(mktemp -d)
44+
trap "rm -rf ${TEMP_FOLDER}" EXIT SIGINT
4545

46-
echo "--- Cleaning up previously generated folders"
47-
rm -rf "${CLIENT_ROOT}/client/apis"
48-
rm -rf "${CLIENT_ROOT}/client/models"
49-
rm -rf "${CLIENT_ROOT}/docs"
50-
rm -rf "${CLIENT_ROOT}/test"
46+
GEN_ROOT="${TEMP_FOLDER}/gen"
47+
SETTING_FILE="${TEMP_FOLDER}/settings"
48+
echo "export KUBERNETES_BRANCH=\"$(python ${SCRIPT_ROOT}/constants.py KUBERNETES_BRANCH)\"" > $SETTING_FILE
49+
echo "export CLIENT_VERSION=\"$(python ${SCRIPT_ROOT}/constants.py CLIENT_VERSION)\"" >> $SETTING_FILE
50+
echo "export PACKAGE_NAME=\"client\"" >> $SETTING_FILE
5151

52-
echo "--- Generating client ..."
53-
mvn -f "${SCRIPT_ROOT}/pom.xml" clean generate-sources -Dgenerator.spec.path="${SCRIPT_ROOT}/swagger.json" -Dgenerator.output.path="${CLIENT_ROOT}" -Dgenerator.package.name=client -D=generator.client.version=${CLIENT_VERSION}
52+
echo ">>> Cloning gen repo"
53+
git clone --recursive https://github.com/kubernetes-client/gen.git "${GEN_ROOT}"
5454

55-
echo "--- Patching generated code..."
56-
find "${CLIENT_ROOT}/test" -type f -name \*.py -exec sed -i 's/\bclient/kubernetes.client/g' {} +
57-
find "${CLIENT_ROOT}" -path "${CLIENT_ROOT}/base" -prune -o -type f -a -name \*.md -exec sed -i 's/\bclient/kubernetes.client/g' {} +
58-
find "${CLIENT_ROOT}" -path "${CLIENT_ROOT}/base" -prune -o -type f -a -name \*.md -exec sed -i 's/kubernetes.client-python/client-python/g' {} +
59-
# rm "${CLIENT_ROOT}/LICENSE"
60-
echo "--- updating version information..."
55+
echo ">>> Running python generator from the gen repo"
56+
"${GEN_ROOT}/openapi/python.sh" "${CLIENT_ROOT}" "${SETTING_FILE}"
57+
mv "${CLIENT_ROOT}/swagger.json" "${SCRIPT_ROOT}/swagger.json"
58+
59+
echo ">>> updating version information..."
6160
sed -i'' "s/^CLIENT_VERSION = .*/CLIENT_VERSION = \\\"${CLIENT_VERSION}\\\"/" "${SCRIPT_ROOT}/../setup.py"
6261
sed -i'' "s/^PACKAGE_NAME = .*/PACKAGE_NAME = \\\"${PACKAGE_NAME}\\\"/" "${SCRIPT_ROOT}/../setup.py"
6362
sed -i'' "s,^DEVELOPMENT_STATUS = .*,DEVELOPMENT_STATUS = \\\"${DEVELOPMENT_STATUS}\\\"," "${SCRIPT_ROOT}/../setup.py"
64-
sed -i'' "/^configuration = Configuration()$/d" "${CLIENT_ROOT}/client/__init__.py"
65-
sed -i'' "/^from .configuration import Configuration$/d" "${CLIENT_ROOT}/client/__init__.py"
66-
sed -i '${/^$/d;}' "${CLIENT_ROOT}/client/__init__.py"
67-
echo "from .configuration import Configuration, ConfigurationObject, configuration" >> "${CLIENT_ROOT}/client/__init__.py"
68-
echo "---Done."
63+
echo ">>> Done."

0 commit comments

Comments
 (0)