Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) add more template functions #851

Merged

Conversation

gianlucam76
Copy link
Member

  • getField: return a field of a resource. Requires the identifier of the resource fetched via TemplateResourceRefs and the field For instance to get the Spec.Replicas of a Deployment.
{{ $replicasValue := getField "Deployment" "spec.replicas" }}
  • removeField: removes a field from a resource Requires the identifier of the resource fetched via TemplateResourceRefs and the field For instance to remove Spec.Replicas of a Deployment
{{ removeField "Deployment" "spec.replicas" }}
  • setField: set a field to a specific value Requires the identifier of the resource fetched via TemplateResourceRefs, the field and new value For instance to update Spec.Replicas of a Deployment
{{ setField "Deployment" "spec.replicas" (int64 7) }}
  • The functions chainRemoveField and chainSetField can be used to pipe more modifications one after another.
    For instance to modify Spec.Replicas, Namespace, ServiceAccount and Paused field
{{ $depl := (getResource "Deployment") }}
{{ $depl := (chainSetField $depl "spec.replicas" (int64 5) ) }}
{{ $depl := (chainSetField $depl "metadata.namespace" .Cluster.metadata.namespace ) }}
{{ $depl := (chainSetField $depl "spec.template.spec.serviceAccountName" "default" ) }}
{{ $depl := (chainSetField $depl "spec.paused" true ) }}
{{ toYaml $depl }}

- getField: return a field of a resource.
Requires the identifier of the resource fetched via TemplateResourceRefs and the field
For instance to get the Spec.Replicas of a Deployment.
```
{{ $replicasValue := getField "Deployment" "spec.replicas" }}
```

- removeField: removes a field from a resource
Requires the identifier of the resource fetched via TemplateResourceRefs and the field
For instance to remove Spec.Replicas of a Deployment
```
{{ removeField "Deployment" "spec.replicas" }}
```

- setField: set a field to a specific value
Requires the identifier of the resource fetched via TemplateResourceRefs, the field and new value
For instance to update Spec.Replicas of a Deployment
```
{{ setField "Deployment" "spec.replicas" (int64 7) }}
```

- The functions chainRemoveField chainSetField can be used to pipe more modifications
one after another.
For instance to modify Spec.Replicas, Namespace, ServiceAccount and Paused field
```
{{ $depl := (getResource "Deployment") }}
{{ $depl := (chainSetField $depl "spec.replicas" (int64 5) ) }}
{{ $depl := (chainSetField $depl "metadata.namespace" .Cluster.metadata.namespace ) }}
{{ $depl := (chainSetField $depl "spec.template.spec.serviceAccountName" "default" ) }}
{{ $depl := (chainSetField $depl "spec.paused" true ) }}
{{ toYaml $depl }}
```
@gianlucam76 gianlucam76 force-pushed the more-template-functions branch from 8caa9c4 to 8b91534 Compare November 26, 2024 13:17
@gianlucam76 gianlucam76 merged commit 685e7ab into projectsveltos:main Nov 26, 2024
5 checks passed
@gianlucam76 gianlucam76 deleted the more-template-functions branch November 26, 2024 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant