Merge pull request #9 from fluxcd/git-tags

Add git tag option to create source
pull/11/head
Stefan Prodan 5 years ago committed by GitHub
commit ea048c71b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -20,5 +20,6 @@ build:
install: install:
go install cmd/tk go install cmd/tk
.PHONY: docs
docs: docs:
mkdir -p ./docs/cmd && go run ./cmd/tk/ docgen mkdir -p ./docs/cmd && go run ./cmd/tk/ docgen

@ -24,25 +24,25 @@ var createKsCmd = &cobra.Command{
The kustomization source command generates a kustomization.kustomize.fluxcd.io resource for a given GitRepository source. The kustomization source command generates a kustomization.kustomize.fluxcd.io resource for a given GitRepository source.
API spec: https://github.com/fluxcd/kustomize-controller/tree/master/docs/spec/v1alpha1`, API spec: https://github.com/fluxcd/kustomize-controller/tree/master/docs/spec/v1alpha1`,
Example: ` # Create a kustomization from a source at a given path Example: ` # Create a kustomization from a source at a given path
create kustomization backend \ create kustomization contour \
--source=webapp \ --source=contour \
--path="./overlays/backend/" \ --path="./examples/contour/" \
--prune="app=backend" \ --prune="instance=contour" \
--generate=true \
--interval=10m \ --interval=10m \
--validate=client \ --validate=client \
--health-check="StatefulSet/backend.test" \ --health-check="Deployment/contour.projectcontour" \
--health-check="DaemonSet/envoy.projectcontour" \
--health-check-timeout=3m --health-check-timeout=3m
# Create a kustomization that depends on another # Create a kustomization that depends on the previous one
create kustomization frontend \ create kustomization webapp \
--depends-on=backend \ --depends-on=contour \
--source=webapp \ --source=webapp \
--path="./overlays/frontend/" \ --path="./deploy/overlays/dev" \
--prune="app=frontend" \ --prune="env=dev,instance=webapp" \
--interval=5m \ --interval=5m \
--validate=client \ --validate=client
--health-check="Deployment/frontend.test" \
--health-check-timeout=2m
`, `,
RunE: createKsCmdRun, RunE: createKsCmdRun,
} }

@ -28,16 +28,30 @@ The create source command generates a source.fluxcd.io resource and waits for it
For Git over SSH, host and SSH keys are automatically generated and stored in a Kubernetes secret. For Git over SSH, host and SSH keys are automatically generated and stored in a Kubernetes secret.
For private Git repositories, the basic authentication credentials are stored in a Kubernetes secret.`, For private Git repositories, the basic authentication credentials are stored in a Kubernetes secret.`,
Example: ` # Create a source from a public Git repository master branch Example: ` # Create a source from a public Git repository master branch
create source podinfo --git-url https://github.com/stefanprodan/podinfo-deploy --git-branch master create source podinfo \
--git-url=https://github.com/stefanprodan/podinfo \
--git-branch=master
# Create a source from a Git repository pinned to specific git tag
create source podinfo \
--git-url=https://github.com/stefanprodan/podinfo \
--git-tag="3.2.3"
# Create a source from a public Git repository tag that matches a semver range # Create a source from a public Git repository tag that matches a semver range
create source podinfo --git-url https://github.com/stefanprodan/podinfo-deploy --git-semver=">=0.0.1-rc.1 <0.1.0" create source podinfo \
--git-url=https://github.com/stefanprodan/podinfo \
--git-semver=">=3.2.0 <3.3.0"
# Create a source from a Git repository using SSH authentication # Create a source from a Git repository using SSH authentication
create source podinfo --git-url ssh://git@github.com/stefanprodan/podinfo-deploy create source podinfo \
--git-url=ssh://git@github.com/stefanprodan/podinfo \
--git-branch=master
# Create a source from a Git repository using basic authentication # Create a source from a Git repository using basic authentication
create source podinfo --git-url https://github.com/stefanprodan/podinfo-deploy -u username -p password create source podinfo \
--git-url=https://github.com/stefanprodan/podinfo \
--username=username \
--password=password
`, `,
RunE: createSourceCmdRun, RunE: createSourceCmdRun,
} }
@ -45,6 +59,7 @@ For private Git repositories, the basic authentication credentials are stored in
var ( var (
sourceGitURL string sourceGitURL string
sourceGitBranch string sourceGitBranch string
sourceGitTag string
sourceGitSemver string sourceGitSemver string
sourceUsername string sourceUsername string
sourcePassword string sourcePassword string
@ -53,6 +68,7 @@ var (
func init() { func init() {
createSourceCmd.Flags().StringVar(&sourceGitURL, "git-url", "", "git address, e.g. ssh://git@host/org/repository") createSourceCmd.Flags().StringVar(&sourceGitURL, "git-url", "", "git address, e.g. ssh://git@host/org/repository")
createSourceCmd.Flags().StringVar(&sourceGitBranch, "git-branch", "master", "git branch") createSourceCmd.Flags().StringVar(&sourceGitBranch, "git-branch", "master", "git branch")
createSourceCmd.Flags().StringVar(&sourceGitTag, "git-tag", "", "git tag")
createSourceCmd.Flags().StringVar(&sourceGitSemver, "git-semver", "", "git tag semver range") createSourceCmd.Flags().StringVar(&sourceGitSemver, "git-semver", "", "git tag semver range")
createSourceCmd.Flags().StringVarP(&sourceUsername, "username", "u", "", "basic authentication username") createSourceCmd.Flags().StringVarP(&sourceUsername, "username", "u", "", "basic authentication username")
createSourceCmd.Flags().StringVarP(&sourcePassword, "password", "p", "", "basic authentication password") createSourceCmd.Flags().StringVarP(&sourcePassword, "password", "p", "", "basic authentication password")
@ -109,6 +125,7 @@ func createSourceCmdRun(cmd *cobra.Command, args []string) error {
Interval: metav1.Duration{ Interval: metav1.Duration{
Duration: interval, Duration: interval,
}, },
Reference: &sourcev1.GitRepositoryRef{},
}, },
} }
@ -117,14 +134,13 @@ func createSourceCmdRun(cmd *cobra.Command, args []string) error {
Name: name, Name: name,
} }
} }
if sourceGitSemver != "" { if sourceGitSemver != "" {
gitRepository.Spec.Reference = &sourcev1.GitRepositoryRef{ gitRepository.Spec.Reference.SemVer = sourceGitSemver
SemVer: sourceGitSemver, } else if sourceGitTag != "" {
} gitRepository.Spec.Reference.Tag = sourceGitTag
} else { } else {
gitRepository.Spec.Reference = &sourcev1.GitRepositoryRef{ gitRepository.Spec.Reference.Branch = sourceGitBranch
Branch: sourceGitBranch,
}
} }
kubeClient, err := utils.kubeClient(kubeconfig) kubeClient, err := utils.kubeClient(kubeconfig)

@ -16,11 +16,35 @@ var VERSION = "0.0.1"
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
Use: "tk", Use: "tk",
Short: "Command line utility for assembling Kubernetes CD pipelines",
Long: `Command line utility for assembling Kubernetes CD pipelines.`,
Version: VERSION, Version: VERSION,
SilenceUsage: true, SilenceUsage: true,
SilenceErrors: true, SilenceErrors: true,
Short: "Command line utility for assembling Kubernetes CD pipelines",
Long: `Command line utility for assembling Kubernetes CD pipelines.`,
Example: ` # Check prerequisites
tk check --pre
# Install the latest version of the toolkit
tk install --version=master
# Create a source from a public Git repository
tk create source webapp \
--git-url=https://github.com/stefanprodan/podinfo \
--git-branch=master \
--interval=5m
# Create a kustomization for deploying a series of microservices
tk create kustomization webapp \
--source=webapp \
--path="./deploy/webapp/" \
--prune="instance=webapp" \
--generate=true \
--interval=5m \
--validate=client \
--health-check="Deployment/backend.webapp" \
--health-check="Deployment/frontend.webapp" \
--health-check-timeout=2m
`,
} }
var ( var (

Loading…
Cancel
Save