From 0b43fffa486abd426c83a26f2e3b5279bbf53180 Mon Sep 17 00:00:00 2001 From: Solly Ross Date: Mon, 1 May 2017 18:24:23 -0400 Subject: [PATCH] Enable client-gen for k8s.io/metrics This commit turns on client-gen for k8s.io/metrics. Clients are generated for `k8s.io/metrics/pkg/apis/metrics` (both internal and v1alpha1). `k8s.io/metrics/pkg/apis/custom_metrics` uses a bespoke client due to the unique nature of its paths. --- hack/update-codegen.sh | 1 + hack/verify-codegen.sh | 1 + .../src/k8s.io/metrics/hack/update-codegen.sh | 42 +++++++++++++++ .../src/k8s.io/metrics/hack/verify-codegen.sh | 51 +++++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100755 staging/src/k8s.io/metrics/hack/update-codegen.sh create mode 100755 staging/src/k8s.io/metrics/hack/verify-codegen.sh diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 3c8d75b6dc1..4b809eb7be0 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -104,3 +104,4 @@ ${informergen} \ vendor/k8s.io/kube-aggregator/hack/update-codegen.sh vendor/k8s.io/sample-apiserver/hack/update-codegen.sh vendor/k8s.io/kube-apiextensions-server/hack/update-codegen.sh +vendor/k8s.io/metrics/hack/update-codegen.sh diff --git a/hack/verify-codegen.sh b/hack/verify-codegen.sh index cef0a60d2b0..85845ff3b24 100755 --- a/hack/verify-codegen.sh +++ b/hack/verify-codegen.sh @@ -27,6 +27,7 @@ kube::golang::setup_env vendor/k8s.io/kube-aggregator/hack/verify-codegen.sh vendor/k8s.io/sample-apiserver/hack/verify-codegen.sh vendor/k8s.io/kube-apiextensions-server/hack/verify-codegen.sh +vendor/k8s.io/metrics/hack/verify-codegen.sh "${KUBE_ROOT}/hack/update-codegen.sh" --verify-only diff --git a/staging/src/k8s.io/metrics/hack/update-codegen.sh b/staging/src/k8s.io/metrics/hack/update-codegen.sh new file mode 100755 index 00000000000..785ece8eed2 --- /dev/null +++ b/staging/src/k8s.io/metrics/hack/update-codegen.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Copyright 2017 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. + +set -o errexit +set -o nounset +set -o pipefail + +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../../../../.. +METRICS_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "${KUBE_ROOT}/hack/lib/init.sh" + +# Register function to be called on EXIT to remove generated binary. +function cleanup { + rm -f "${CLIENTGEN:-}" +} +trap cleanup EXIT + +echo "Building client-gen" +CLIENTGEN="${PWD}/client-gen-binary" +go build -o "${CLIENTGEN}" ./cmd/libs/go2idl/client-gen + +PREFIX=k8s.io/metrics/pkg/apis +INPUT_BASE="--input-base ${PREFIX}" +CLIENTSET_PATH="--clientset-path k8s.io/metrics/pkg/client/clientset_generated" + +${CLIENTGEN} --clientset-name="clientset" ${INPUT_BASE} --input metrics/v1alpha1 ${CLIENTSET_PATH} --output-base ${KUBE_ROOT}/vendor + +# we skip informers and listers for metrics, because we don't quite support the requisite operations yet +# we skip generating the internal clientset as it's not really needed diff --git a/staging/src/k8s.io/metrics/hack/verify-codegen.sh b/staging/src/k8s.io/metrics/hack/verify-codegen.sh new file mode 100755 index 00000000000..fcb45ca2446 --- /dev/null +++ b/staging/src/k8s.io/metrics/hack/verify-codegen.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# Copyright 2017 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. + +set -o errexit +set -o nounset +set -o pipefail + +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../../../../.. +METRICS_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "${KUBE_ROOT}/hack/lib/init.sh" + +DIFFROOT="${METRICS_ROOT}/pkg" +TMP_DIFFROOT="${METRICS_ROOT}/_tmp/pkg" +_tmp="${METRICS_ROOT}/_tmp" + +cleanup() { + rm -rf "${_tmp}" +} +trap "cleanup" EXIT SIGINT + +cleanup + +mkdir -p "${TMP_DIFFROOT}" +cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}" + +"${METRICS_ROOT}/hack/update-codegen.sh" +echo "diffing ${DIFFROOT} against freshly generated codegen" +ret=0 +diff -Naupr "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$? +cp -a "${TMP_DIFFROOT}"/* "${DIFFROOT}" +if [[ $ret -eq 0 ]] +then + echo "${DIFFROOT} up to date." +else + echo "${DIFFROOT} is out of date. Please run hack/update-codegen.sh" + exit 1 +fi +