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

Enhancement: Support Multiple Inline Templates #104

Open
organic-scholar opened this issue Jul 18, 2024 · 0 comments
Open

Enhancement: Support Multiple Inline Templates #104

organic-scholar opened this issue Jul 18, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@organic-scholar
Copy link

organic-scholar commented Jul 18, 2024

What problem are you facing?

The inline definition of resources using source: Inline can become unmaintainable as the template size grows. The solution to the problem of increasing size of the inline template is to use source: FileSystem for which you can construct a config map and mount it to the function using DeploymentRuntimeConfig but that has another problem for each different composition template, you have to deploy a copy of the function.

Change proposed to help solve the problem?

Using source: Inline if there is a new field inline.templates is introduced of type []string that can have multiple yaml strings for resource definitions then kustomize can be used to separate resource definitions into separate files e.g

# composition.yaml
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
  name: example-inline
spec:
  mode: Pipeline
  compositeTypeRef:
    apiVersion: example.crossplane.io/v1beta1
    kind: XR
  pipeline:
    - step: render-templates
      functionRef:
        name: function-go-templating
      input:
        apiVersion: gotemplating.fn.crossplane.io/v1beta1
        kind: GoTemplate
        source: Inline
        inline:
          templates: []
# user.patch.yaml
- op: add
  path: /spec/pipeline/0/input/inline/templates/-
  value: |
    apiVersion: iam.aws.upbound.io/v1beta1
    kind: User
    metadata:
      annotations:
        gotemplating.fn.crossplane.io/composition-resource-name: user
    spec:
      forProvider: {}
# access-key.patch.yaml
- op: add
  path: /spec/pipeline/0/input/inline/templates/-
  value: |
    apiVersion: iam.aws.upbound.io/v1beta1
    kind: AccessKey
    metadata:
      annotations:
        gotemplating.fn.crossplane.io/composition-resource-name: access-key
    spec:
      forProvider: {}
# kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - compositions.yaml
patches:
  - path: user.patch.yaml
    target: { kind: Composition, name: example-inline }
  - path: access-key.patch.yaml
    target: { kind: Composition, name: example-inline }

Implementation

Adding this new field to TemplateSourceInline will be backwards compatible.

type TemplateSourceInline struct {
	Template  string   `json:"template,omitempty"`
	Templates []string `json:"templates,omitempty"`
}

The string items of Templates field will be appended to the Template field with separator "\n---\n"

@organic-scholar organic-scholar added the enhancement New feature or request label Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant