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

Add the ability to access files inside templates #70

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fernandezcuesta
Copy link

@fernandezcuesta fernandezcuesta commented Feb 13, 2024

Description of your changes

Similarly as Helm template does through the .Files object, we might need to literally inject vanilla files into a template. For example, rather than including the terraform code into workspaces.tf.upbound.io spec.forProvider.module, we might do:

apiVersion: tf.upbound.io/v1beta1
kind: Workspace
spec:
  forProvider:
    source: Inline
    module: {{ readFile "/templates/terraform/workspace.tf" | quote }}
    # module: {{ readFiles "/templates/terraform/*.tf" "\n" | quote }} # alternatively

and keep files separatedly, easier to maintain.

I have:

Signed-off-by: Jesús Fernández <jesus.fernandez@nexthink.com>
@fernandezcuesta
Copy link
Author

fernandezcuesta commented Mar 6, 2024

Just to add more clarity on the usecase, the idea is to inject some files "as is". These files are copied in configMaps which are:

  • created by kustomize
configMapGenerator:
- name: my-composition
  namespace: crossplane-system
  files:
  - terraform/variables.tf
  - terraform/main.tf
  - terraform/data.tf
generatorOptions:
  disableNameSuffixHash: true
  labels:
    part-of: function-go-templating
  annotations:
    k8s-sidecar-target-directory: terraform
  • read and injected via DeploymentRuntimeConfig this way:
apiVersion: pkg.crossplane.io/v1beta1
kind: DeploymentRuntimeConfig
metadata:
  name: function-go-templating
  # DeploymentRuntimeConfig is not namespaced, but this is required by
  # kustomize to properly inject the generated ConfigMap
  namespace: crossplane-system
spec:
  deploymentTemplate:
    metadata:
      labels:
        kubernetes.io/part-of: crossplane
    spec:
      selector: {}
      template:
        spec:
          containers:
          - name: configmap-mounter
            env:
            # All configmaps labeled `part-of: function-go-templating` will be
            # mounted in `/templates`
            - name: LABEL
              value: part-of
            - name: LABEL_VALUE
              value: function-go-templating
            - name: FOLDER
              value: /templates
            image: kiwigrid/k8s-sidecar:1.25.4
            imagePullPolicy: IfNotPresent
            volumeMounts:
            - mountPath: /templates
              name: templates
          - name: package-runtime
            args:
            - --debug
            volumeMounts:
            - name: templates
              mountPath: /templates
          volumes:
          - name: templates
            emptyDir: {}
  serviceAccountTemplate:
    metadata:
      name: function-go-templating # required by rolebinding
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: crossplane-system
  name: template-replication
rules:
- apiGroups: [""]
  resources: ["configmaps"]
  verbs: ["get", "watch", "list"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: template-replication
  namespace: crossplane-system
subjects:
- kind: ServiceAccount
  name: function-go-templating
  namespace: crossplane-system
roleRef:
  kind: Role
  name: template-replication
  apiGroup: rbac.authorization.k8s.io

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.

None yet

1 participant