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:
go install cmd/tk
.PHONY: docs
docs:
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.
API spec: https://github.com/fluxcd/kustomize-controller/tree/master/docs/spec/v1alpha1`,
Example: ` # Create a kustomization from a source at a given path
create kustomization backend \
--source=webapp \
--path="./overlays/backend/" \
--prune="app=backend" \
create kustomization contour \
--source=contour \
--path="./examples/contour/" \
--prune="instance=contour" \
--generate=true \
--interval=10m \
--validate=client \
--health-check="StatefulSet/backend.test" \
--health-check="Deployment/contour.projectcontour" \
--health-check="DaemonSet/envoy.projectcontour" \
--health-check-timeout=3m
# Create a kustomization that depends on another
create kustomization frontend \
--depends-on=backend \
# Create a kustomization that depends on the previous one
create kustomization webapp \
--depends-on=contour \
--source=webapp \
--path="./overlays/frontend/" \
--prune="app=frontend" \
--path="./deploy/overlays/dev" \
--prune="env=dev,instance=webapp" \
--interval=5m \
--validate=client \
--health-check="Deployment/frontend.test" \
--health-check-timeout=2m
--validate=client
`,
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 private Git repositories, the basic authentication credentials are stored in a Kubernetes secret.`,
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 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 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 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,
}
@ -45,6 +59,7 @@ For private Git repositories, the basic authentication credentials are stored in
var (
sourceGitURL string
sourceGitBranch string
sourceGitTag string
sourceGitSemver string
sourceUsername string
sourcePassword string
@ -53,6 +68,7 @@ var (
func init() {
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(&sourceGitTag, "git-tag", "", "git tag")
createSourceCmd.Flags().StringVar(&sourceGitSemver, "git-semver", "", "git tag semver range")
createSourceCmd.Flags().StringVarP(&sourceUsername, "username", "u", "", "basic authentication username")
createSourceCmd.Flags().StringVarP(&sourcePassword, "password", "p", "", "basic authentication password")
@ -109,6 +125,7 @@ func createSourceCmdRun(cmd *cobra.Command, args []string) error {
Interval: metav1.Duration{
Duration: interval,
},
Reference: &sourcev1.GitRepositoryRef{},
},
}
@ -117,14 +134,13 @@ func createSourceCmdRun(cmd *cobra.Command, args []string) error {
Name: name,
}
}
if sourceGitSemver != "" {
gitRepository.Spec.Reference = &sourcev1.GitRepositoryRef{
SemVer: sourceGitSemver,
}
gitRepository.Spec.Reference.SemVer = sourceGitSemver
} else if sourceGitTag != "" {
gitRepository.Spec.Reference.Tag = sourceGitTag
} else {
gitRepository.Spec.Reference = &sourcev1.GitRepositoryRef{
Branch: sourceGitBranch,
}
gitRepository.Spec.Reference.Branch = sourceGitBranch
}
kubeClient, err := utils.kubeClient(kubeconfig)

@ -16,11 +16,35 @@ var VERSION = "0.0.1"
var rootCmd = &cobra.Command{
Use: "tk",
Short: "Command line utility for assembling Kubernetes CD pipelines",
Long: `Command line utility for assembling Kubernetes CD pipelines.`,
Version: VERSION,
SilenceUsage: 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 (

Loading…
Cancel
Save