Skip to content

Commit

Permalink
Turn guides into executable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mortent committed Sep 14, 2020
1 parent 3be8029 commit 6dfd83e
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 10 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/verifyGuides.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2019 Google LLC
#
# 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.

name: VerifyGuides
on:
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.14
- uses: actions/checkout@v2
- run: |
make build
- run: |
GOPATH=$(go env GOPATH) go get github.com/monopole/mdrip
GOPATH=$(go env GOPATH) go get sigs.k8s.io/kind@v0.8.1
- run: |
make verify-guides
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,6 @@ docs: gencatalog lintdocs gendocs license

servedocs:
(cd site && go run github.com/gohugoio/hugo server)

verify-guides:
./scripts/verifyGuides.sh
10 changes: 10 additions & 0 deletions scripts/verifyGuides.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -o nounset
set -o errexit
set -o pipefail

mdrip --blockTimeOut 6m0s --mode test \
--label verifyGuides site/content/en/guides

echo "Success"
80 changes: 70 additions & 10 deletions site/content/en/guides/consumer/get/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ description: >
a cluster
---

{{% hide %}}

<!-- @makeWorkplace @verifyGuides-->
```
# Set up workspace for the test.
TEST_HOME=$(mktemp -d)
cd $TEST_HOME
```

{{% /hide %}}

*Any git directory containing configuration files may be used by kpt
as a package.*

Expand Down Expand Up @@ -47,6 +58,7 @@ as a public package catalogue.

### Fetch Command

<!-- @fetchPackage @verifyGuides-->
```sh
kpt pkg get https://github.com/kubernetes/examples/staging/cockroachdb cockroachdb
```
Expand All @@ -61,6 +73,16 @@ The contents of the `staging/cockroachdb` subdirectory in the
`https://github.com/kubernetes/examples` were copied to the local folder
`cockroachdb`.

{{% hide %}}

<!-- @verifyFetch @verifyGuides-->
```
# Verify that we downloaded the package and that it includes KRM resources.
cat cockroachdb/cockroachdb-statefulset.yaml | grep "kind: StatefulSet"
```

{{% /hide %}}

{{% pageinfo color="info" %}}

- Any git subdirectory containing configuration (e.g. `deploy.yaml`) may be
Expand All @@ -82,6 +104,7 @@ The contents of the `staging/cockroachdb` subdirectory in the
The upstream commit and branch / tag reference are stored in the package's
[Kptfile]. These are used by `kpt pkg update`.

<!-- @catPackage @verifyGuides-->
```sh
cat cockroachdb/Kptfile
```
Expand All @@ -104,6 +127,16 @@ upstream:
ref: master
```

{{% hide %}}

<!-- @verifyKptfile @verifyGuides-->
```
# Verify that the Kptfile exists and points to the correct upstream repo.
cat cockroachdb/Kptfile | grep "repo: https://github.com/kubernetes/examples"
```

{{% /hide %}}

## View the package contents

The primary package artifacts are Kubernetes [resource configuration]
Expand All @@ -112,22 +145,19 @@ artifacts such as documentation.

### Package Contents Command

<!-- @treePackage @verifyGuides-->
```sh
tree cockroachdb/
kpt cfg tree cockroachdb/
```

### Package Contents Output

```sh
cockroachdb/
├── Kptfile
├── OWNERS
├── README.md
├── cockroachdb-statefulset.yaml
├── demo.sh
└── minikube.sh

0 directories, 6 files
cockroachdb
├── [cockroachdb-statefulset.yaml] Service cockroachdb
├── [cockroachdb-statefulset.yaml] StatefulSet cockroachdb
├── [cockroachdb-statefulset.yaml] PodDisruptionBudget cockroachdb-budget
└── [cockroachdb-statefulset.yaml] Service cockroachdb-public
```

The cockroachdb package fetched from [kubernetes examples] contains a
Expand Down Expand Up @@ -174,6 +204,16 @@ Use `kubectl apply` to deploy the local package to a remote cluster.

### Apply Command

{{% hide %}}

<!-- @createKindCluster @verifyGuides-->
```
kind delete cluster && kind create cluster
```

{{% /hide %}}

<!-- @applyPackage @verifyGuides-->
```sh
kubectl apply -R -f cockroachdb
```
Expand All @@ -187,6 +227,26 @@ poddisruptionbudget.policy/cockroachdb-budget unchanged
statefulset.apps/cockroachdb created
```

{{% hide %}}

<!-- @verifyApply @verifyGuides-->
```
# Verify that we have cockroachdb installed and that it can be reconciled.
counter=0
until kubectl get sts cockroachdb | grep "3/3"
do
if [ $counter -gt 150 ];then
echo "sts has not reconciled after 5m. Exiting.."
exit 1
fi
echo "Waiting for sts to reconcile"
counter=$((counter + 1))
sleep 2s
done
```

{{% /hide %}}

{{% pageinfo color="info" %}}
This guide used `kubectl apply` to demonstrate how kpt packages work out of the
box with tools that have been around since the beginning of Kubernetes.
Expand Down
1 change: 1 addition & 0 deletions site/layouts/shortcodes/hide.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- if .Inner -}}{{- end -}}

0 comments on commit 6dfd83e

Please sign in to comment.