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: Allow templating in GlobalTenantResource and TenantResource #688

Closed
h4wkmoon opened this issue Jan 30, 2023 · 4 comments · Fixed by #694
Closed

feat: Allow templating in GlobalTenantResource and TenantResource #688

h4wkmoon opened this issue Jan 30, 2023 · 4 comments · Fixed by #694
Assignees
Labels
enhancement New feature or request needs-discussion No outline on the feature, discussion is welcome
Milestone

Comments

@h4wkmoon
Copy link
Contributor

Describe the feature

It would be nice to allow some templating in GlobalTenantResource and TenantResource. For now, I can see 2 variables that could be templated: the tenant name, and the namespace name.

We have a use-case where we want to deploy an ingress in specific namespaces for specific tenants. The hostname of the ingress has the tenant name in it.

What would the new user story look like?

As a cluster-admin, I would like to be able to use tenant name, and namespace name in the manifest of resource generated by globaltenantresources.
As a tenant owner, I would like to be able to use tenant name, and namespace name in the manifest of resource generated by tenantresources.

Expected behavior

This resource would create an ingress with the interpolated hostname.
Double curly brackets is just a proposal. Any other templating synthax may be ok. Kyverno has similar features. It can be used as an example.

apiVersion: capsule.clastix.io/v1beta2
kind: GlobalTenantResource
metadata:
  name: some-ingress
spec:
  tenantSelector:
    matchLabels:
      somelabel: "somevalue"
  resyncPeriod: 60s
  resources:
    - namespaceSelector:
        matchLabels:
          somelabel: "somevalue"
      rawItems:
      - apiVersion: networking.k8s.io/v1
        kind: Ingress
        metadata:
          name: something
        spec:
          rules:
          - host: something.{{tenant_name}}.mydomain
            [...]
@h4wkmoon h4wkmoon added the blocked-needs-validation Issue need triage and validation label Jan 30, 2023
@prometherion
Copy link
Member

prometherion commented Feb 2, 2023

This could be done, thanks for sharing your proposal!

I'd say we should stick to the Go templating guidelines, so curly brackets as delimitators are good.

I was thinking something like as:

  • {{ tenant.name }} for the given Tenant Name
  • {{ namespace }} for the Namespace where the resource will be deployed

Any other ones that could be helpful?

Keep in mind that we can just support templating for rawItems, at the current state.

@prometherion prometherion added enhancement New feature or request needs-discussion No outline on the feature, discussion is welcome and removed blocked-needs-validation Issue need triage and validation labels Feb 2, 2023
@h4wkmoon
Copy link
Contributor Author

h4wkmoon commented Feb 2, 2023

Nothing else comes to my mind.
Thx.

@aslafy-z
Copy link
Contributor

aslafy-z commented Feb 2, 2023

@prometherion Wouldn't it be nice to get the whole Tenant object into the templating engine? So we can use {{ tenant.metadata.name}} and access all the other fields? I don't have a real use case for it as of now.

@prometherion
Copy link
Member

Wouldn't it be nice to get the whole Tenant object into the templating engine?

"With great power comes great responsibility", and templating is so error-prone and I think we should stick to simplicity.

If there's a real and documented use-case for further templating, we can talk, I'm totally open to it.

@prometherion prometherion self-assigned this Feb 3, 2023
@prometherion prometherion added this to the v0.2.2 milestone Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs-discussion No outline on the feature, discussion is welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants