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) Lua Scripting for Dynamic Kubernetes Deployments #960

Merged
merged 1 commit into from
Jan 20, 2025

Conversation

gianlucam76
Copy link
Member

@gianlucam76 gianlucam76 commented Jan 18, 2025

Sveltos can execute Lua code stored in ConfigMap or Secret resources. To enable this functionality, these resources must be annotated with the projectsveltos.io/lua annotation.

  1. Resource Referencing: Sveltos profiles can reference ConfigMap and Secret resources.
  2. Lua Code Identification: Sveltos identifies resources with the projectsveltos.io/lua annotation.
  3. Lua Code Execution: Sveltos executes the Lua code found within these resources.
  4. Deployment based on Output: The output generated by the Lua code is used to deploy configurations to matching clusters.

Sveltos provides helper functions to simplify working with resources:

  1. getResource(resources, "resource identifier"): Retrieves a specific
    resource using its identifier from the provided resource list. resources
    represents all Kubernetes resources defined in the Spec.TemplateResourceRefs
    section of a Sveltos profile. identifier must match an identifier previously
    defined in the Spec.TemplateResourceRefs section of the profile.
  2. getLabel(resource, "key"): Returns the value of a label with the
    specified key for a given resource.
  3. getAnnotation(resource, "key"): Returns the value of an annotation
    with the specified key for a given resource.
  4. base64Encode and base64Decode
  5. json.encode and json.decode
  6. strings functions like Compare, Contains, HasPrefix, HasSuffix, Join,
    Replace, Split, ToLower, ToUpper. We use https://github.com/chai2010/glua-strings
    so full list can be found there. To use those methods strings.ToUpper("mystring")
    for instance

Sveltos allows users to extend its Lua scripting capabilities
by defining custom helper functions. These functions are packaged
as Lua code within a ConfigMap residing in the projectsveltos namespace.
For Sveltos to load and utilize these custom functions, the lua-methods
argument must be provided to the addon-controller deployment. Once loaded,
these custom methods become available whenever Lua code is executed by Sveltos.

This PR uses:

  1. https://github.com/chai2010/glua-strings/
  2. https://github.com/layeh/gopher-json

Fixes #403

@gianlucam76 gianlucam76 force-pushed the lua branch 3 times, most recently from f1b4a61 to 7456cf4 Compare January 20, 2025 08:54
Sveltos can execute Lua code stored in ConfigMap or Secret resources.
To enable this functionality, these resources must be annotated with
the `projectsveltos.io/lua` annotation.

1. Resource Referencing: Sveltos profiles can reference ConfigMap and
Secret resources.
2. Lua Code Identification: Sveltos identifies resources with the
`projectsveltos.io/lua` annotation.
3. Lua Code Execution: Sveltos executes the Lua code found within
these resources.
4. Deployment based on Output: The output generated by the Lua code
is used to deploy configurations to matching clusters.

Sveltos provides helper functions to simplify working with resources:

1. getResource(resources, "resource identifier"): Retrieves a specific
resource using its identifier from the provided resource list. resources
represents all Kubernetes resources defined in the Spec.TemplateResourceRefs
section of a Sveltos profile. identifier must match an identifier previously
defined in the Spec.TemplateResourceRefs section of the profile.
2. getLabel(resource, "key"): Returns the value of a label with the
specified key for a given resource.
3. getAnnotation(resource, "key"): Returns the value of an annotation
with the specified key for a given resource.
4. base64Encode and base64Decode
5. json.encode and json.decode
6. strings functions like Compare, Contains, HasPrefix, HasSuffix, Join,
Replace, Split, ToLower, ToUpper. We use https://github.com/chai2010/glua-strings
so full list can be found there. To use those methods `strings.ToUpper("mystring")`
for instance

Sveltos allows users to extend its Lua scripting capabilities
by defining custom helper functions. These functions are packaged
as Lua code within a ConfigMap residing in the projectsveltos namespace.
For Sveltos to load and utilize these custom functions, the `lua-methods`
argument must be provided to the addon-controller deployment. Once loaded,
these custom methods become available whenever Lua code is executed by Sveltos.

This PR uses:
1. https://github.com/chai2010/glua-strings/
2. https://github.com/layeh/gopher-json
@gianlucam76 gianlucam76 merged commit f609fa4 into projectsveltos:main Jan 20, 2025
6 checks passed
@gianlucam76 gianlucam76 deleted the lua branch January 20, 2025 10:54
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.

Accept Lua functions for template instantiations
1 participant