Skip to content

Conversation

AlinaGoaga
Copy link
Contributor

@AlinaGoaga AlinaGoaga commented Jan 12, 2023

Closes #2215

What changed?
gitops create template template.yaml --values CLUSTER_NAME=ewq --export (go run cmd/gitops/main.go create template ...)

only renders to stdout. We want to respect the file paths returned and write out the yaml to those paths, relative to the --outDir flag. e.g:

gitops create template --outDir ./out --values CLUSTER_NAME=ewq should write out: ./out/clusters/ewq.yaml

How did you validate the change?
Tested with go run cmd/gitops/main.go create template cmd/gitops/app/create/templates/testdata/template.yaml --values RESOURCE_NAME=ewq NAMESPACE=default TEMPLATE_PATH=./ GIT_REPO_NAME=test GIT_REPO_NAMESPACE=default --outDir=./out

after updating template.yaml to:

resourcetemplates:
    - path: "/resources1/${RESOURCE_NAME}.yaml"
      content:
        - apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
          kind: Kustomization
          metadata:
            name: ${RESOURCE_NAME}
            namespace: ${NAMESPACE}
          spec:
            interval: 1h
            path: ${TEMPLATE_PATH}
            sourceRef:
              kind: GitRepository
              name: ${GIT_REPO_NAME}
              namespace: ${GIT_REPO_NAMESPACE}
    - path: "/resources2/${RESOURCE_NAME}.yaml"
      content:
        - apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
          kind: Kustomization
          metadata:
            name: ${RESOURCE_NAME}
            namespace: ${NAMESPACE}
          spec:
            interval: 1h
            path: ${TEMPLATE_PATH}
            sourceRef:
              kind: GitRepository
              name: ${GIT_REPO_NAME}
              namespace: ${GIT_REPO_NAMESPACE}

The directories and files that got created:
Screenshot 2023-01-12 at 16 41 09

Documentation Changes
Need to update docs.

@AlinaGoaga AlinaGoaga added the enhancement New feature or request label Jan 12, 2023
@AlinaGoaga AlinaGoaga requested review from sarataha and foot January 12, 2023 15:43
@AlinaGoaga AlinaGoaga marked this pull request as ready for review January 12, 2023 15:43
Copy link
Member

@sarataha sarataha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🥇

Copy link
Collaborator

@foot foot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@AlinaGoaga AlinaGoaga merged commit 6e0cbd8 into main Jan 13, 2023
@AlinaGoaga AlinaGoaga deleted the 2215 branch January 13, 2023 09:26
return nil
if flags.outputDir != "" {
for _, res := range templateResources.RenderedTemplate {
filePath := filepath.Join(flags.outputDir, *res.Path)
Copy link
Contributor

@bigkevmcd bigkevmcd Jan 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use SecureJoin https://github.com/fluxcd/flux2/blob/9c3750613014b4b499675b231f7b08103ac5e8d1/pkg/manifestgen/manifest.go#L24 we're accepting data from a user, so we should make sure not to allow escapes!

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

Successfully merging this pull request may close these issues.

gitops create template should have --outputPath option
4 participants