forked from SAP/sap-btp-service-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-k8s-client.sh
executable file
·83 lines (68 loc) · 3.02 KB
/
generate-k8s-client.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env bash
##
## Copyright (c) 2021 SAP SE or an SAP affiliate company. All rights reserved.
##
## Base script created by SAP Oliver Götz.
## This file is part of ewm-cloud-robotics (see https://github.com/SAP/ewm-cloud-robotics).
## Script was enhanced by SAP Steffen Brunner
##
## This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file (https://github.com/SAP/ewm-cloud-robotics/)
######## ATTENTION ######
## $FOLDER_NAME /tmp/.gopath/src/$FOLDER_NAME MUST
## match go.mod "package" definition!
set -e
# K8S branch for code-generator and apimachinery
K8S_BRANCH="release-1.22"
GIT_APIMACHINERY="https://github.com/kubernetes/apimachinery.git"
GIT_CODEGENERATOR="https://github.com/kubernetes/code-generator.git"
# Versions of api to be generated
K8S_GROUPS_VERSIONS="services.cloud.sap.com:v1alpha1"
# Start
echo "### Using kubernetes code-generator and apimachinery from branch: $K8S_BRANCH ###"
# Directory of this script
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# Prepare temporary environment for generating files
echo "### Prepare temporary environment for generating files ###"
rm -Rf "$SCRIPT_DIR/../tmp/.gopath/src/github.com"
mkdir -p "$SCRIPT_DIR/../tmp/.gopath/src/github.com/SAP/sap-btp-service-operator/api"
mkdir -p "$SCRIPT_DIR/../tmp/.gopath/src/k8s.io"
mkdir -p "$SCRIPT_DIR/../tmp/.gopath/bin"
# Copy preserving file attributes
cp -R -p "$SCRIPT_DIR/api" "$SCRIPT_DIR/../tmp/.gopath/src/github.com/SAP/sap-btp-service-operator"
cd "$SCRIPT_DIR/../tmp/.gopath/src/github.com/SAP/sap-btp-service-operator"
TEMP_REPO=$(pwd)
# Prepare header for generated files
cat > "$TEMP_REPO/HEADER" <<EOF
// Your header goes here...
//
EOF
# Set GOPATH
cd "$SCRIPT_DIR/../tmp/.gopath"
export GOPATH=$(pwd)
export GOBIN=
export GO111MODULE=auto
# Get kubernetes code-generator and apimachinery
echo "### Get kubernetes code-generator and apimachinery ###"
cd "$SCRIPT_DIR/../tmp/.gopath/src/k8s.io"
git clone --branch $K8S_BRANCH $GIT_APIMACHINERY
git clone --branch $K8S_BRANCH $GIT_CODEGENERATOR
# Generate kubernetes client
echo "### Generate kubernetes client ###"
cd "$SCRIPT_DIR/../tmp/.gopath/src"
./k8s.io/code-generator/generate-groups.sh all \
"github.com/SAP/sap-btp-service-operator/client" \
"github.com/SAP/sap-btp-service-operator/api" \
"$K8S_GROUPS_VERSIONS" \
--go-header-file "$TEMP_REPO/HEADER"
# Copy generated files
echo "### Copy generated files ###"
echo "### Copy new files ###"
# We overwrite presevering attributes here but do not delete old files
#cp -Rf -p "$SCRIPT_DIR/../tmp/.gopath/src/github.com/SAP/sap-btp-service-operator/api" "$SCRIPT_DIR/../client/api"
cp -Rf "$SCRIPT_DIR/../tmp/.gopath/src/github.com/SAP/sap-btp-service-operator/client/" "$SCRIPT_DIR/client/"
# Cleanup temporary environment
echo "### Cleanup temporary environment ###"
# Files in GOPATH/pkg/mod are usually read only. Give write rights that deletion does not fail
chmod -R +w "$SCRIPT_DIR/../tmp/.gopath/pkg"
sleep 1
rm -Rf "$SCRIPT_DIR/../tmp"