-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a script to auto-generate GCP example docs from the examples folder Move existing examples under folders
- Loading branch information
Showing
22 changed files
with
688 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,53 @@ | ||
# CloudSQL example | ||
# CloudSQL | ||
|
||
This example creates a ResourceGraphDefinition called `CloudSQL` to deploy Cloud SQL instance in 2 regions as a primary replica pair. | ||
This example show how you can use KRO to deploy GCP Cloud SQL instance in 2 regions as a primary and replica instances. | ||
|
||
## Create ResourceGraphDefinitions | ||
|
||
Apply the RGD to your cluster: | ||
## End User: CloudSQL | ||
The administrator needs to install the RGD first. | ||
The end user creates a `CloudSQL` resource that looks like this: | ||
|
||
```yaml | ||
apiVersion: kro.run/v1alpha1 | ||
kind: CloudSQL | ||
metadata: | ||
name: demo | ||
namespace: config-connector | ||
spec: | ||
name: demo | ||
project: my-gcp-project | ||
primaryRegion: us-central1 | ||
replicaRegion: us-west1 | ||
``` | ||
kubectl apply -f rgd.yaml | ||
``` | ||
|
||
Validate the RGD: | ||
``` | ||
> kubectl get rgd cloudsql.kro.run | ||
NAME APIVERSION KIND STATE AGE | ||
cloudsql.kro.run v1alpha1 CloudSQL Active 44m | ||
``` | ||
The status of the applied resource can be checked using: | ||
## Create an Instance of CloudSQL | ||
Set the env variables used in the instance template: | ||
``` | ||
export CLOUDSQL_NAME=demo | ||
export GCP_PROJECT=myproject | ||
export PRIMARY_REGION=us-central1 | ||
export REPLICA_REGION=us-west1 | ||
kubectl get cloudsqls | ||
kubectl get cloudsql demo -n config-connector -o yaml | ||
``` | ||
|
||
Run the following command to replace the env variables in `instance-template.yaml` file and create | ||
a new file called instance.yaml. | ||
```shell | ||
envsubst < "instance-template.yaml" > "instance.yaml" | ||
``` | ||
Navigate to CloudSQL page in the GCP Console and verify the creation of primary and replica instances. | ||
|
||
Apply the `instance.yaml` | ||
Once done, the user can delete the `CloudSQL` instance: | ||
|
||
``` | ||
kubectl apply -f instance.yaml | ||
kubectl delete cloudsql demo -n config-connector | ||
``` | ||
|
||
Validate instance status: | ||
## Administrator: ResourceGraphDefinition | ||
The administrator needs to install the RGD in the cluster first before the user can consume it: | ||
|
||
``` | ||
kubectl get cloudsqls | ||
kubectl apply -f rgd.yaml | ||
``` | ||
|
||
## Validate | ||
|
||
Navigate to CloudSQL page in the GCP Console and verify the creation of primary and replica instances. | ||
|
||
## Clean up | ||
|
||
Remove the instance: | ||
Validate the RGD is installed correctly: | ||
|
||
``` | ||
kubectl delete cloudsql $CLOUDSQL_NAME | ||
> kubectl get rgd cloudsql.kro.run | ||
NAME APIVERSION KIND STATE AGE | ||
cloudsql.kro.run v1alpha1 CloudSQL Active 44m | ||
``` | ||
|
||
Remove the ResourceGraphDefinitions: | ||
|
||
``` | ||
kubectl delete rgd cloudsql.kro.run | ||
``` | ||
Once all user created instances are deleted, the administrator can choose to deleted the RGD. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/bin/bash | ||
|
||
create_example() { | ||
out_file=$1 | ||
position=$2 | ||
readme_file=$3 | ||
rgd_file=$4 | ||
|
||
# Verify all parameters are valid | ||
if [ -z "$out_file" ] || [ -z "$position" ] || [ -z "$readme_file" ] || [ -z "$rgd_file" ]; then | ||
echo "Error: Missing required parameters" | ||
echo "Usage: create_example <out_file> <position> <readme_file> <rgd_file>" | ||
return 1 | ||
fi | ||
|
||
|
||
cat > "$out_file" << EOF | ||
--- | ||
sidebar_position: $position | ||
--- | ||
$(cat $readme_file) | ||
<details> | ||
<summary>ResourceGraphDefinition</summary> | ||
\`\`\`yaml title="rgd.yaml" | ||
$(cat "$yaml_file") | ||
\`\`\` | ||
</details> | ||
EOF | ||
|
||
} | ||
|
||
update_gcp_example_docs() { | ||
# Create the GCP examples directory if it doesn't exist | ||
mkdir -p website/docs/examples/gcp | ||
# Initialize position counter | ||
position=405 | ||
# Find all rgd.yaml files in examples/gcp directory and its subdirectories | ||
find examples/gcp -name "rgd.yaml" | while read -r yaml_file; do | ||
# Extract the directory name as the example name | ||
example_path=$(dirname "$yaml_file") | ||
dir_name=$(basename $example_path) | ||
readme_file=$example_path/README.md | ||
out_file="website/docs/examples/gcp/${dir_name}.md" | ||
|
||
# Convert directory name to title case (e.g., gke-cluster -> GKE Cluster) | ||
# title=$(echo "$dir_name" | sed -E 's/-/ /g' | awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1') | ||
|
||
# copy all images | ||
cp $example_path/*.png website/docs/examples/gcp/ 2>/dev/null | ||
# Generate the markdown content | ||
create_example "$out_file" "$position" "$readme_file" "$yaml_file" | ||
|
||
# Increment position for next file | ||
((position+=1)) | ||
|
||
echo "Generated documentation for ${dir_name} at ${out_file}" | ||
done | ||
} | ||
|
||
update_aws_example_docs() { | ||
echo "TODO: implement aws examples" | ||
} | ||
update_azure_example_docs() { | ||
echo "TODO: implement azure examples" | ||
} | ||
update_kubernetes_example_docs() { | ||
echo "TODO: implement kubernetes examples" | ||
} | ||
|
||
update_gcp_example_docs | ||
update_aws_example_docs | ||
update_azure_example_docs | ||
update_kubernetes_example_docs |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"label": "AWS Examples", | ||
"position": 300, | ||
"link": { | ||
"type": "generated-index", | ||
"description": "Examples of using Kro with AWS" | ||
}, | ||
"collapsible": true, | ||
"collapsed": true | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"label": "Azure Examples", | ||
"position": 500, | ||
"link": { | ||
"type": "generated-index", | ||
"description": "Examples of using Kro with Microsoft Azure" | ||
}, | ||
"collapsible": true, | ||
"collapsed": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"label": "Basic Examples", | ||
"position": 100, | ||
"link": { | ||
"type": "generated-index", | ||
"description": "Basic examples to get started with Kro" | ||
}, | ||
"collapsible": true, | ||
"collapsed": true | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"label": "GCP Examples", | ||
"position": 400, | ||
"link": { | ||
"type": "generated-index", | ||
"description": "Examples of using Kro with Google Cloud Platform" | ||
}, | ||
"collapsible": true, | ||
"collapsed": true | ||
} |
Oops, something went wrong.