|  | 
|  | 1 | +#!/usr/bin/env bash | 
|  | 2 | + | 
|  | 3 | +# Copyright 2020 Crunchy Data Solutions, Inc. | 
|  | 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | +# you may not use this file except in compliance with the License. | 
|  | 6 | +# You may obtain a copy of the License at | 
|  | 7 | +# | 
|  | 8 | +# http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | +# | 
|  | 10 | +# Unless required by applicable law or agreed to in writing, software | 
|  | 11 | +# distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | +# See the License for the specific language governing permissions and | 
|  | 14 | +# limitations under the License. | 
|  | 15 | + | 
|  | 16 | +set -eu | 
|  | 17 | + | 
|  | 18 | +# Find the Go install path. | 
|  | 19 | +[ "${GOBIN:-}" ] || GOBIN="$(go env GOBIN)" | 
|  | 20 | +[ "${GOBIN:-}" ] || GOBIN="$(go env GOPATH)/bin" | 
|  | 21 | + | 
|  | 22 | +# Create and cleanup a temporary directory. | 
|  | 23 | +DIR="$(mktemp -d)" | 
|  | 24 | +trap "rm -rf '$DIR'" EXIT | 
|  | 25 | + | 
|  | 26 | +# Find `client-gen` on the current PATH or install it to the Go install path. | 
|  | 27 | +tool="$(command -v client-gen || true)" | 
|  | 28 | +[ -n "$tool" ] || tool="$GOBIN/client-gen" | 
|  | 29 | +[ -x "$tool" ] || ( cd "$DIR" && go mod init tmp && go get 'k8s.io/code-generator/cmd/client-gen@v0.17.9' ) | 
|  | 30 | + | 
|  | 31 | +# Generate ./pkg/generated/clientset/versioned from objects defined in ./pkg/apis/crunchydata.com/... | 
|  | 32 | + | 
|  | 33 | +target_directory='pkg/generated/clientset' | 
|  | 34 | +target_package="$(go list -m)/${target_directory}" | 
|  | 35 | + | 
|  | 36 | +"$tool" \ | 
|  | 37 | +--clientset-name='versioned' \ | 
|  | 38 | +--go-header-file='hack/boilerplate.go.txt' \ | 
|  | 39 | +--input-base='' --input="$(go list ./pkg/apis/crunchydata.com/... | paste -sd, -)" \ | 
|  | 40 | +--output-base="$DIR" --output-package="$target_package" \ | 
|  | 41 | + | 
|  | 42 | +[ ! -d "$target_directory" ] || rm -r "$target_directory" | 
|  | 43 | +mv "${DIR}/${target_package}" "${target_directory}" | 
0 commit comments