/ kubernetes / hack / update-codegen.sh
update-codegen.sh
 1  #!/usr/bin/env bash
 2  # Copyright 2025 Alibaba Group Holding Ltd.
 3  # 
 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 -o errexit
17  set -o nounset
18  set -o pipefail
19  
20  SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
21  CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; go env GOPATH)/pkg/mod/k8s.io/code-generator@v0.33.0}
22  
23  if [ ! -d "${CODEGEN_PKG}" ]; then
24      echo "code-generator not found at ${CODEGEN_PKG}"
25      echo "Installing k8s.io/code-generator@v0.33.0..."
26      go install k8s.io/code-generator/cmd/client-gen@v0.33.0
27      go install k8s.io/code-generator/cmd/lister-gen@v0.33.0
28      go install k8s.io/code-generator/cmd/informer-gen@v0.33.0
29  fi
30  
31  source "${CODEGEN_PKG}/kube_codegen.sh"
32  
33  kube::codegen::gen_client \
34      --with-watch \
35      --output-dir "${SCRIPT_ROOT}/pkg/client" \
36      --output-pkg "github.com/alibaba/OpenSandbox/sandbox-k8s/pkg/client" \
37      --boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \
38      "${SCRIPT_ROOT}/apis"
39  
40  echo "Code generation completed successfully!"