Skip to content

Commit 61c8c90

Browse files
committed
add generate yaml file test
add generate yaml file test to avoid break code on the yaml file
1 parent c80524a commit 61c8c90

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

Makefile

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ DEP = github.com/golang/dep/cmd/dep
1919
DEP_CHECK := $(shell command -v dep 2> /dev/null)
2020

2121
HAS_DEP := $(shell command -v dep;)
22+
HAS_KUSTOMIZE := $(shell command -v kustomize;)
23+
24+
GENERATE_YAML_PATH=cmd/clusterctl/examples/ibmcloud
25+
GENERATE_YAML_EXEC=generate-yaml.sh
26+
GENERATE_YAML_TEST_FOLDER=dummy-make-auto-test
2227

2328
all: test manager
2429

2530
# Run tests
26-
test: depend generate fmt vet manifests
31+
test: depend generate fmt vet manifests generate_yaml_test
2732
go test ./pkg/... ./cmd/... -coverprofile cover.out
2833

2934

@@ -63,6 +68,22 @@ fmt:
6368
vet:
6469
go vet ./pkg/... ./cmd/...
6570

71+
generate_yaml_test:
72+
73+
ifndef HAS_KUSTOMIZE
74+
# for now, higher version has some problem so we stick to 1.0.11
75+
wget https://github.com/kubernetes-sigs/kustomize/releases/download/v1.0.11/kustomize_1.0.11_linux_amd64
76+
mv kustomize_1.0.11_linux_amd64 /usr/local/bin/kustomize
77+
chmod +x /usr/local/bin/kustomize
78+
endif
79+
80+
# Create a dummy file for test only
81+
echo 'clouds' > cmd/clusterctl/examples/ibmcloud/dummy-clouds-test.yaml
82+
$(GENERATE_YAML_PATH)/$(GENERATE_YAML_EXEC) -f dummy-clouds-test.yaml ubuntu $(GENERATE_YAML_TEST_FOLDER)
83+
# the folder will be generated under same folder of $(GENERATE_YAML_PATH)
84+
rm -fr $(GENERATE_YAML_PATH)/$(GENERATE_YAML_TEST_FOLDER)
85+
rm -f cmd/clusterctl/examples/ibmcloud/dummy-clouds-test.yaml
86+
6687
# Generate code
6788
generate:
6889
ifndef GOPATH

cmd/clusterctl/examples/ibmcloud/generate-yaml.sh

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ print_help()
77
echo "$SCRIPT - generates a provider-configs.yaml file"
88
echo ""
99
echo "Usage:"
10-
echo "$SCRIPT [options] <path/to/clouds.yaml> <provider os: [ubuntu]>"
10+
echo "$SCRIPT [options] <path/to/clouds.yaml> <provider os: [ubuntu]> [output folder]"
1111
echo "options:"
1212
echo "-h, --help show brief help"
1313
echo "-f, --force-overwrite if file to be generated already exists, force script to overwrite it"
@@ -55,6 +55,13 @@ else
5555
exit 1
5656
fi
5757

58+
OUTPUT=out
59+
if [[ -n "$3" ]] && [[ $3 != -* ]] && [[ $3 != --* ]]; then
60+
OUTPUT=$(echo $3 | tr '[:upper:]' '[:lower:]')
61+
else
62+
echo "no output folder provided, use name 'out' by default"
63+
fi
64+
5865
# Check that OS is supported
5966
for i in "${arr[@]}"
6067
do
@@ -70,7 +77,7 @@ if test -z "$PROVIDER_OS"; then
7077
exit 1
7178
fi
7279

73-
if [ -e out/provider-components.yaml ] && [ "$OVERWRITE" != "1" ]; then
80+
if [ -e $OUTPUT/provider-components.yaml ] && [ "$OVERWRITE" != "1" ]; then
7481
echo "Can't overwrite provider-components.yaml without user permission. Either run the script again"
7582
echo "with -f or --force-overwrite, or delete the file in the out/ directory."
7683
echo ""
@@ -100,24 +107,25 @@ fi
100107
# Prepare dependecies for kustomize
101108
mkdir -p $CONFIG_DIR
102109
cat $PWD/$CLOUDS_PATH > $CONFIG_DIR/clouds.yaml
103-
104110
cat "$MASTER_USER_DATA" > $USERDATA/$PROVIDER_OS/master-user-data.sh
105111
cat "$WORKER_USER_DATA" > $USERDATA/$PROVIDER_OS/worker-user-data.sh
106112

107113
# Set up the output dir if it does not yet exist
108-
mkdir -p $PWD/out
109-
cp -n $PWD/cluster.yaml.template $PWD/out/cluster.yaml
110-
cp -n $PWD/machines.yaml.template $PWD/out/machines.yaml
114+
mkdir -p $PWD/$OUTPUT
115+
cp -n $PWD/cluster.yaml.template $PWD/$OUTPUT/cluster.yaml
116+
cp -n $PWD/machines.yaml.template $PWD/$OUTPUT/machines.yaml
111117

112118
# Build provider-components.yaml with kustomize
113-
kustomize build ../../../../config -o out/provider-components.yaml
119+
echo $PWD
120+
echo $OUTPUT
121+
kustomize build $PWD/../../../../config -o $PWD/$OUTPUT/provider-components.yaml
114122

115-
echo "---" >> $PWD/out/provider-components.yaml
116-
kustomize build $PWD/provider-component/clouds-secrets >> $PWD/out/provider-components.yaml
123+
echo "---" >> $PWD/$OUTPUT/provider-components.yaml
124+
kustomize build $PWD/provider-component/clouds-secrets >> $PWD/$OUTPUT/provider-components.yaml
117125

118-
echo "---" >> $PWD/out/provider-components.yaml
119-
kustomize build $PWD/provider-component/cluster-api >> $PWD/out/provider-components.yaml
126+
echo "---" >> $PWD/$OUTPUT/provider-components.yaml
127+
kustomize build $PWD/provider-component/cluster-api >> $PWD/$OUTPUT/provider-components.yaml
120128

121-
echo "---" >> $PWD/out/provider-components.yaml
122-
kustomize build $USERDATA/$PROVIDER_OS >> out/provider-components.yaml
129+
echo "---" >> $PWD/$OUTPUT/provider-components.yaml
130+
kustomize build $USERDATA/$PROVIDER_OS >> $PWD/$OUTPUT/provider-components.yaml
123131

0 commit comments

Comments
 (0)