Skip to content

Support -f/--file flag in argocd app add#35

Merged
merenbach merged 22 commits intoargoproj:masterfrom
merenbach:app-add-file
Mar 14, 2018
Merged

Support -f/--file flag in argocd app add#35
merenbach merged 22 commits intoargoproj:masterfrom
merenbach:app-add-file

Conversation

@merenbach
Copy link
Contributor

@merenbach merenbach commented Mar 14, 2018

Summary

This adds an -f flag to (mostly) mirror Kubernetes' kubectl create -f flag, and in the process resolves #31.

Problem

Currently a GitHub repo and a path to a manifest inside the repo are required. It would be nice to be able to use a -f flag to point to a local file or URL containing a Kubernetes Application manifest that can be used directly. The repo and path can be recovered from inside the file.

Solution

  • Add util methods for reading remote/local files.
  • Add tests for remote/local file reading methods.
  • Add util method for unmarshaling byte data into an argoappv1.Application struct.
  • Update NewApplicationAddCommand:
    1. Don't require path and repo args at the FlagSet level.
    2. Accept an -f/--file flag that contains either a local path or a remote URL.
    3. If the flag points to a valid JSON or YAML file, try unmarshaling it with the aforementioned util method.
    4. Error out if this fails.

Notes

@alexmt and any other reviewers:

  • Because the K8s manifest is assumed to contain a name in the metedata, this PR takes the liberty of removing the APPNAME positional parameter and replaces it with a named parameter.
  • File extensions are not checked, since it's really just the contents we're interested in. This may or may not match kubectl create -f directly.
  • kubectl create -f also allows local directories to be specified. Since Application manifests are small for now and not generally divided between files, directories are not currently supported.

@merenbach merenbach requested a review from alexmt March 14, 2018 17:09
@merenbach merenbach changed the title Support Support -f/--file flag in argocd app add Mar 14, 2018
@merenbach merenbach added the enhancement New feature or request label Mar 14, 2018
Copy link
Collaborator

@alexmt alexmt left a comment

Choose a reason for hiding this comment

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

LGTM. I've added two minor comments. Please fix and merge

}
if err != nil {
log.Fatal(err)
os.Exit(1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

log.Fatal already executes os.Exit(1). Can you please remove this line?

@@ -0,0 +1,48 @@
package commands

import (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpicking. Please run goimports -w cmd/argocd/commands/util.go. We usually automatically run goimports on file save, so next person might get unexpected changes.

@merenbach
Copy link
Contributor Author

merenbach commented Mar 14, 2018

@alexmt thank you! The requested changes have been made, and per https://godoc.org/golang.org/x/tools/cmd/goimports I've updated my .emacs.

@merenbach merenbach merged commit e7e3c50 into argoproj:master Mar 14, 2018
@merenbach merenbach deleted the app-add-file branch March 14, 2018 21:00
@merenbach merenbach restored the app-add-file branch March 14, 2018 21:00
@merenbach merenbach deleted the app-add-file branch March 16, 2018 17:39
leoluz pushed a commit to leoluz/argo-cd that referenced this pull request Sep 29, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

argocd app add should support an -f option

2 participants