Skip to content

Commit

Permalink
Merge pull request #321 from gianlucam76/replace-index
Browse files Browse the repository at this point in the history
Use getResource
  • Loading branch information
gianlucam76 authored Jul 15, 2024
2 parents 0bd18c7 + 9b6f4f8 commit 9455136
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
8 changes: 4 additions & 4 deletions docs/template/bring_your_own_controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,18 @@ The following YAML instructions are used to deploy add-ons using Sveltos:
name: gcs-credentials
namespace: default
annotations:
bucket: {{ (index .MgtmResources "Bucket").status.bucketURL }}
bucket: {{ (getResource "Bucket").status.bucketURL }}
type: Opaque
data:
service-account.json: {{ (index .MgtmResources "Bucket").status.serviceAccountCredentials }}
service-account.json: {{ (getResource "Bucket").status.serviceAccountCredentials }}
pod.yaml: |
apiVersion: v1
kind: Pod
metadata:
name: create-and-upload-to-gcs
namespace: default
annotations:
bucket: {{ (index .MgtmResources "Bucket").status.bucketURL }}
bucket: {{ (getResource "Bucket").status.bucketURL }}
spec:
containers:
- name: uploader
Expand All @@ -153,7 +153,7 @@ The following YAML instructions are used to deploy add-ons using Sveltos:
- |
echo "Hello world" > /tmp/hello.txt
gcloud auth activate-service-account --key-file=/var/run/secrets/cloud.google.com/service-account.json
gsutil cp /tmp/hello.txt gs://{{ (index .MgtmResources "Bucket").spec.bucketName }}
gsutil cp /tmp/hello.txt gs://{{ (getResource "Bucket").spec.bucketName }}
volumeMounts:
- name: gcp-sa
mountPath: /var/run/secrets/cloud.google.com/
Expand Down
8 changes: 4 additions & 4 deletions docs/template/crossplane.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ Once the Pod is deployed, it will upload a file to the `my-bucket` bucket.
name: gcs-credentials
namespace: default
annotations:
bucket: "{{ (index .MgmtResources "CrossplaneBucket").status.atProvider.url }}"
bucket: "{{ (getResource "CrossplaneBucket").status.atProvider.url }}"
type: Opaque
data:
service-account.json: {{ $data:=(index .MgmtResources "Credentials").data }} {{ (index $data "creds") }}
service-account.json: {{ $data:=(getResource "Credentials").data }} {{ (index $data "creds") }}
pod.yaml: |
apiVersion: v1
kind: Pod
metadata:
name: create-and-upload-to-gcs
namespace: default
annotations:
bucket: {{ (index .MgmtResources "CrossplaneBucket").status.atProvider.url }}
bucket: {{ (getResource "CrossplaneBucket").status.atProvider.url }}
spec:
containers:
- name: uploader
Expand All @@ -120,7 +120,7 @@ Once the Pod is deployed, it will upload a file to the `my-bucket` bucket.
- |
echo "Hello world" > /tmp/hello.txt
gcloud auth activate-service-account --key-file=/var/run/secrets/cloud.google.com/service-account.json
gsutil cp /tmp/hello.txt gs://{{ (index .MgmtResources "CrossplaneBucket").metadata.name }}
gsutil cp /tmp/hello.txt gs://{{ (getResource "CrossplaneBucket").metadata.name }}
volumeMounts:
- name: gcp-sa
mountPath: /var/run/secrets/cloud.google.com/
Expand Down
2 changes: 1 addition & 1 deletion docs/template/example_multicluster_iteration_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Lets assume the clusters where the service should get deployed has the cluster l
projectsveltos.io/template: "true"
data:
services.yaml: |
{{ range $cluster := (index .MgmtResources "ClusterData").spec.matchingResources }}
{{ range $cluster := (getResource "ClusterData").spec.matchingResources }}
apiVersion: v1
kind: Service
metadata:
Expand Down
4 changes: 2 additions & 2 deletions docs/template/external_secret.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ Now we can configure Sveltos to distribute such content to all managed clusters
kind: Secret
metadata:
name: eso
namespace: {{ (index .MgmtResources "ExternalSecret").metadata.namespace }}
namespace: {{ (getResource "ExternalSecret").metadata.namespace }}
data:
content: {{ (index .MgmtResources "ExternalSecret").data.content }}
content: {{ (getResource "ExternalSecret").data.content }}
EOF
```

Expand Down
2 changes: 1 addition & 1 deletion docs/template/jsonnet_extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ At this point, you can use the Sveltos' [template](template_generic_examples.md)
projectsveltos.io/template: "true" # add annotation to indicate Sveltos content is a template
data:
resource.yaml: |
{{ (index .MgmtResources "JsonnetSource").status.resources }}
{{ (getResource "JsonnetSource").status.resources }}
```

The above configuration instructs Sveltos to deploy the resources generated by jsonnet to the selected managed clusters.
Expand Down
28 changes: 14 additions & 14 deletions docs/template/template_generic_examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Following ClusterProfile
releaseNamespace: kyverno
helmChartAction: Install
values: |
{{ (index .MgmtResources "ConfigData").data.values }}
{{ (getResource "ConfigData").data.values }}
```

will deploy Kyverno with _3_ replicas on cluster1
Expand Down Expand Up @@ -221,10 +221,10 @@ Find the template below.
kind: Secret
metadata:
name: autoscaler
namespace: {{ (index .MgmtResources "AutoscalerSecret").metadata.namespace }}
namespace: {{ (getResource "AutoscalerSecret").metadata.namespace }}
data:
token: {{ (index .MgmtResources "AutoscalerSecret").data.token }}
ca.crt: {{ $data:=(index .MgmtResources "AutoscalerSecret").data }} {{ (index $data "ca.crt") }}
token: {{ (getResource "AutoscalerSecret").data.token }}
ca.crt: {{ $data:=(getResource "AutoscalerSecret").data }} {{ (index $data "ca.crt") }}
```

Sveltos will use the content of the _AutoscalerSecret_ to fill in the placeholders when deploying the resources to your managed clusters.
Expand All @@ -235,7 +235,7 @@ Sveltos will use the content of the _AutoscalerSecret_ to fill in the placeholde
To use any resource that Sveltos has found based on the defintion, simply use the syntax below in the YAML template:

```yaml
(index .MgmtResources "<Identifier>")
(getResource "<Identifier>")
```

Replace `<Identifier>` with the name you gave that resource in your ClusterProfile definition (like _AutoscalerSecret_).
Expand Down Expand Up @@ -285,10 +285,10 @@ Firstly, we create a ConfigMap named _replicate-external-secret-operator-secret_
apiVersion: v1
kind: Secret
metadata:
name: {{ (index .MgmtResources "ESOSecret").metadata.name }}
namespace: {{ (index .MgmtResources "ESOSecret").metadata.namespace }}
name: {{ (getResource "ESOSecret").metadata.name }}
namespace: {{ (getResource "ESOSecret").metadata.namespace }}
data:
{{ range $key, $value := (index .MgmtResources "ESOSecret").data }}
{{ range $key, $value := (getResource "ESOSecret").data }}
{{$key}}: {{ $value }}
{{ end }}
```
Expand Down Expand Up @@ -420,10 +420,10 @@ The content of this ConfigMap is a template that uses the information contained
kind: Secret
metadata:
name: autoscaler
namespace: {{ (index .MgmtResources "AutoscalerSecret").metadata.namespace }}
namespace: {{ (getResource "AutoscalerSecret").metadata.namespace }}
data:
token: {{ (index .MgmtResources "AutoscalerSecret").data.token }}
ca.crt: {{ $data:=(index .MgmtResources "AutoscalerSecret").data }} {{ (index $data "ca.crt") }}
token: {{ (getResource "AutoscalerSecret").data.token }}
ca.crt: {{ $data:=(getResource "AutoscalerSecret").data }} {{ (index $data "ca.crt") }}
```

### Autoscaler All-in-One - YAML Definition
Expand Down Expand Up @@ -503,8 +503,8 @@ The content of this ConfigMap is a template that uses the information contained
kind: Secret
metadata:
name: autoscaler
namespace: {{ (index .MgmtResources "AutoscalerSecret").metadata.namespace }}
namespace: {{ (getResource "AutoscalerSecret").metadata.namespace }}
data:
token: {{ (index .MgmtResources "AutoscalerSecret").data.token }}
ca.crt: {{ $data:=(index .MgmtResources "AutoscalerSecret").data }} {{ (index $data "ca.crt") }}
token: {{ (getResource "AutoscalerSecret").data.token }}
ca.crt: {{ $data:=(getResource "AutoscalerSecret").data }} {{ (index $data "ca.crt") }}
```
2 changes: 1 addition & 1 deletion docs/template/ytt_extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ At this point, you can use the Sveltos' [template](template_generic_examples.md)
projectsveltos.io/template: "true" # add annotation to indicate Sveltos content is a template
data:
resource.yaml: |
{{ (index .MgmtResources "YttSource").status.resources }}
{{ (getResource "YttSource").status.resources }}
```

The above configuration instructs Sveltos to deploy the resources generated by ytt to the selected managed clusters.
Expand Down

0 comments on commit 9455136

Please sign in to comment.