Merge pull request #116 from fluxcd/helm-repo-cmd

Implement Helm repository commands
pull/118/head
Stefan Prodan 5 years ago committed by GitHub
commit b384c5f14c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -42,19 +42,19 @@ the bootstrap command will perform an upgrade if needed.`,
export GITHUB_TOKEN=<my-token>
# Run bootstrap for a private repo owned by a GitHub organization
bootstrap github --owner=<organization> --repository=<repo name>
tk bootstrap github --owner=<organization> --repository=<repo name>
# Run bootstrap for a private repo and assign organization teams to it
bootstrap github --owner=<organization> --repository=<repo name> --team=<team1 slug> --team=<team2 slug>
tk bootstrap github --owner=<organization> --repository=<repo name> --team=<team1 slug> --team=<team2 slug>
# Run bootstrap for a repository path
bootstrap github --owner=<organization> --repository=<repo name> --path=dev-cluster
tk bootstrap github --owner=<organization> --repository=<repo name> --path=dev-cluster
# Run bootstrap for a public repository on a personal account
bootstrap github --owner=<user> --repository=<repo name> --private=false --personal=true
tk bootstrap github --owner=<user> --repository=<repo name> --private=false --personal=true
# Run bootstrap for a private repo hosted on GitHub Enterprise
bootstrap github --owner=<organization> --repository=<repo name> --hostname=<domain>
tk bootstrap github --owner=<organization> --repository=<repo name> --hostname=<domain>
`,
RunE: bootstrapGitHubCmdRun,
}

@ -42,16 +42,16 @@ the bootstrap command will perform an upgrade if needed.`,
export GITLAB_TOKEN=<my-token>
# Run bootstrap for a private repo owned by a GitLab group
bootstrap gitlab --owner=<group> --repository=<repo name>
tk bootstrap gitlab --owner=<group> --repository=<repo name>
# Run bootstrap for a repository path
bootstrap gitlab --owner=<group> --repository=<repo name> --path=dev-cluster
tk bootstrap gitlab --owner=<group> --repository=<repo name> --path=dev-cluster
# Run bootstrap for a public repository on a personal account
bootstrap gitlab --owner=<user> --repository=<repo name> --private=false --personal=true
tk bootstrap gitlab --owner=<user> --repository=<repo name> --private=false --personal=true
# Run bootstrap for a private repo hosted on a GitLab server
bootstrap gitlab --owner=<group> --repository=<repo name> --hostname=<domain>
tk bootstrap gitlab --owner=<group> --repository=<repo name> --hostname=<domain>
`,
RunE: bootstrapGitLabCmdRun,
}

@ -40,7 +40,7 @@ var createKsCmd = &cobra.Command{
Short: "Create or update a Kustomization resource",
Long: "The kustomization source create command generates a Kustomize resource for a given GitRepository source.",
Example: ` # Create a Kustomization resource from a source at a given path
create kustomization contour \
tk create kustomization contour \
--source=contour \
--path="./examples/contour/" \
--prune=true \
@ -51,7 +51,7 @@ var createKsCmd = &cobra.Command{
--health-check-timeout=3m
# Create a Kustomization resource that depends on the previous one
create kustomization webapp \
tk create kustomization webapp \
--depends-on=contour \
--source=webapp \
--path="./deploy/overlays/dev" \
@ -60,7 +60,7 @@ var createKsCmd = &cobra.Command{
--validation=client
# Create a Kustomization resource that runs under a service account
create kustomization webapp \
tk create kustomization webapp \
--source=webapp \
--path="./deploy/overlays/staging" \
--prune=true \

@ -46,35 +46,35 @@ The create source git command generates a GitRepository resource and waits for i
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 git podinfo \
tk create source git podinfo \
--url=https://github.com/stefanprodan/podinfo \
--branch=master
# Create a source from a Git repository pinned to specific git tag
create source git podinfo \
tk create source git podinfo \
--url=https://github.com/stefanprodan/podinfo \
--tag="3.2.3"
# Create a source from a public Git repository tag that matches a semver range
create source git podinfo \
tk create source git podinfo \
--url=https://github.com/stefanprodan/podinfo \
--tag-semver=">=3.2.0 <3.3.0"
# Create a source from a Git repository using SSH authentication
create source git podinfo \
tk create source git podinfo \
--url=ssh://git@github.com/stefanprodan/podinfo \
--branch=master
# Create a source from a Git repository using SSH authentication and an
# ECDSA P-521 curve public key
create source git podinfo \
tk create source git podinfo \
--url=ssh://git@github.com/stefanprodan/podinfo \
--branch=master \
--ssh-key-algorithm=ecdsa \
--ssh-ecdsa-curve=p521
# Create a source from a Git repository using basic authentication
create source git podinfo \
tk create source git podinfo \
--url=https://github.com/stefanprodan/podinfo \
--username=username \
--password=password
@ -115,7 +115,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
name := args[0]
if sourceGitURL == "" {
return fmt.Errorf("git-url is required")
return fmt.Errorf("url is required")
}
tmpDir, err := ioutil.TempDir("", name)

@ -0,0 +1,229 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"context"
"fmt"
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
"github.com/spf13/cobra"
"io/ioutil"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"net/url"
"os"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml"
)
var createSourceHelmCmd = &cobra.Command{
Use: "helm [name]",
Short: "Create or update a HelmRepository source",
Long: `
The create source helm command generates a HelmRepository resource and waits for it to fetch the index.
For private Helm repositories, the basic authentication credentials are stored in a Kubernetes secret.`,
Example: ` # Create a source from a public Helm repository
tk create source helm podinfo \
--url=https://stefanprodan.github.io/podinfo \
--interval=10m
# Create a source from a Helm repository using basic authentication
tk create source helm podinfo \
--url=https://stefanprodan.github.io/podinfo \
--username=username \
--password=password
`,
RunE: createSourceHelmCmdRun,
}
var (
sourceHelmURL string
sourceHelmUsername string
sourceHelmPassword string
)
func init() {
createSourceHelmCmd.Flags().StringVar(&sourceHelmURL, "url", "", "Helm repository address")
createSourceHelmCmd.Flags().StringVarP(&sourceHelmUsername, "username", "u", "", "basic authentication username")
createSourceHelmCmd.Flags().StringVarP(&sourceHelmPassword, "password", "p", "", "basic authentication password")
createSourceCmd.AddCommand(createSourceHelmCmd)
}
func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("source name is required")
}
name := args[0]
secretName := fmt.Sprintf("helm-%s", name)
if sourceHelmURL == "" {
return fmt.Errorf("url is required")
}
tmpDir, err := ioutil.TempDir("", name)
if err != nil {
return err
}
defer os.RemoveAll(tmpDir)
if _, err := url.Parse(sourceHelmURL); err != nil {
return fmt.Errorf("url parse failed: %w", err)
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig)
if err != nil {
return err
}
helmRepository := sourcev1.HelmRepository{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: sourcev1.HelmRepositorySpec{
URL: sourceHelmURL,
Interval: metav1.Duration{
Duration: interval,
},
},
}
if export {
return exportHelmRepository(helmRepository)
}
withAuth := false
if sourceHelmUsername != "" && sourceHelmPassword != "" {
logger.Actionf("applying secret with basic auth credentials")
secret := corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: secretName,
Namespace: namespace,
},
StringData: map[string]string{
"username": sourceHelmUsername,
"password": sourceHelmPassword,
},
}
if err := upsertSecret(ctx, kubeClient, secret); err != nil {
return err
}
withAuth = true
}
if withAuth {
logger.Successf("authentication configured")
}
logger.Generatef("generating source")
if withAuth {
helmRepository.Spec.SecretRef = &corev1.LocalObjectReference{
Name: secretName,
}
}
logger.Actionf("applying source")
if err := upsertHelmRepository(ctx, kubeClient, helmRepository); err != nil {
return err
}
logger.Waitingf("waiting for index download")
if err := wait.PollImmediate(pollInterval, timeout,
isHelmRepositoryReady(ctx, kubeClient, name, namespace)); err != nil {
return err
}
logger.Successf("index download completed")
namespacedName := types.NamespacedName{
Namespace: namespace,
Name: name,
}
err = kubeClient.Get(ctx, namespacedName, &helmRepository)
if err != nil {
return fmt.Errorf("helm index failed: %w", err)
}
if helmRepository.Status.Artifact != nil {
logger.Successf("fetched revision: %s", helmRepository.Status.Artifact.Revision)
} else {
return fmt.Errorf("index download failed, artifact not found")
}
return nil
}
func upsertHelmRepository(ctx context.Context, kubeClient client.Client, helmRepository sourcev1.HelmRepository) error {
namespacedName := types.NamespacedName{
Namespace: helmRepository.GetNamespace(),
Name: helmRepository.GetName(),
}
var existing sourcev1.HelmRepository
err := kubeClient.Get(ctx, namespacedName, &existing)
if err != nil {
if errors.IsNotFound(err) {
if err := kubeClient.Create(ctx, &helmRepository); err != nil {
return err
} else {
logger.Successf("source created")
return nil
}
}
return err
}
existing.Spec = helmRepository.Spec
if err := kubeClient.Update(ctx, &existing); err != nil {
return err
}
logger.Successf("source updated")
return nil
}
func exportHelmRepository(source sourcev1.HelmRepository) error {
gvk := sourcev1.GroupVersion.WithKind(sourcev1.HelmRepositoryKind)
export := sourcev1.HelmRepository{
TypeMeta: metav1.TypeMeta{
Kind: gvk.Kind,
APIVersion: gvk.GroupVersion().String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: source.Name,
Namespace: source.Namespace,
},
Spec: source.Spec,
}
data, err := yaml.Marshal(export)
if err != nil {
return err
}
fmt.Println("---")
fmt.Println(string(data))
return nil
}

@ -31,7 +31,10 @@ var deleteKsCmd = &cobra.Command{
Aliases: []string{"ks"},
Short: "Delete a Kustomization resource",
Long: "The delete kustomization command deletes the given Kustomization from the cluster.",
RunE: deleteKsCmdRun,
Example: ` # Delete a kustomization and the Kubernetes resources created by it
tk delete kustomization podinfo
`,
RunE: deleteKsCmdRun,
}
func init() {

@ -30,7 +30,10 @@ var deleteSourceGitCmd = &cobra.Command{
Use: "git [name]",
Short: "Delete a GitRepository source",
Long: "The delete source git command deletes the given GitRepository from the cluster.",
RunE: deleteSourceGitCmdRun,
Example: ` # Delete a Git repository
tk delete source git podinfo
`,
RunE: deleteSourceGitCmdRun,
}
func init() {

@ -0,0 +1,86 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"context"
"fmt"
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/types"
)
var deleteSourceHelmCmd = &cobra.Command{
Use: "helm [name]",
Short: "Delete a HelmRepository source",
Long: "The delete source helm command deletes the given HelmRepository from the cluster.",
Example: ` # Delete a Helm repository
tk delete source helm podinfo
`,
RunE: deleteSourceHelmCmdRun,
}
func init() {
deleteSourceCmd.AddCommand(deleteSourceHelmCmd)
}
func deleteSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("name is required")
}
name := args[0]
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig)
if err != nil {
return err
}
namespacedName := types.NamespacedName{
Namespace: namespace,
Name: name,
}
var helmRepository sourcev1.HelmRepository
err = kubeClient.Get(ctx, namespacedName, &helmRepository)
if err != nil {
return err
}
if !deleteSilent {
prompt := promptui.Prompt{
Label: "Are you sure you want to delete this source",
IsConfirm: true,
}
if _, err := prompt.Run(); err != nil {
return fmt.Errorf("aborting")
}
}
logger.Actionf("deleting source %s in %s namespace", name, namespace)
err = kubeClient.Delete(ctx, &helmRepository)
if err != nil {
return err
}
logger.Successf("source deleted")
return nil
}

@ -34,10 +34,10 @@ var exportKsCmd = &cobra.Command{
Short: "Export Kustomization resources in YAML format",
Long: "The export kustomization command exports one or all Kustomization resources in YAML format.",
Example: ` # Export all Kustomization resources
export kustomization --all > kustomizations.yaml
tk export kustomization --all > kustomizations.yaml
# Export a Kustomization
export kustomization my-app > kustomization.yaml
tk export kustomization my-app > kustomization.yaml
`,
RunE: exportKsCmdRun,
}

@ -34,10 +34,10 @@ var exportSourceGitCmd = &cobra.Command{
Short: "Export GitRepository sources in YAML format",
Long: "The export source git command exports on or all GitRepository sources in YAML format.",
Example: ` # Export all GitRepository sources
export source git --all > sources.yaml
tk export source git --all > sources.yaml
# Export a GitRepository source including the SSH key pair or basic auth credentials
export source git my-private-repo --with-credentials > source.yaml
tk export source git my-private-repo --with-credentials > source.yaml
`,
RunE: exportSourceGitCmdRun,
}
@ -48,7 +48,7 @@ func init() {
func exportSourceGitCmdRun(cmd *cobra.Command, args []string) error {
if !exportAll && len(args) < 1 {
return fmt.Errorf("kustomization name is required")
return fmt.Errorf("name is required")
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
@ -103,7 +103,7 @@ func exportSourceGitCmdRun(cmd *cobra.Command, args []string) error {
}
func exportGit(source sourcev1.GitRepository) error {
gvk := sourcev1.GroupVersion.WithKind("GitRepository")
gvk := sourcev1.GroupVersion.WithKind(sourcev1.GitRepositoryKind)
export := sourcev1.GitRepository{
TypeMeta: metav1.TypeMeta{
Kind: gvk.Kind,

@ -0,0 +1,139 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"context"
"fmt"
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml"
)
var exportSourceHelmCmd = &cobra.Command{
Use: "helm [name]",
Short: "Export HelmRepository sources in YAML format",
Long: "The export source git command exports on or all HelmRepository sources in YAML format.",
Example: ` # Export all HelmRepository sources
tk export source helm --all > sources.yaml
# Export a HelmRepository source including the basic auth credentials
tk export source helm my-private-repo --with-credentials > source.yaml
`,
RunE: exportSourceHelmCmdRun,
}
func init() {
exportSourceCmd.AddCommand(exportSourceHelmCmd)
}
func exportSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
if !exportAll && len(args) < 1 {
return fmt.Errorf("name is required")
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig)
if err != nil {
return err
}
if exportAll {
var list sourcev1.HelmRepositoryList
err = kubeClient.List(ctx, &list, client.InNamespace(namespace))
if err != nil {
return err
}
if len(list.Items) == 0 {
logger.Failuref("no source found in %s namespace", namespace)
return nil
}
for _, repository := range list.Items {
if err := exportHelmRepository(repository); err != nil {
return err
}
if exportSourceWithCred {
if err := exportHelmCredentials(ctx, kubeClient, repository); err != nil {
return err
}
}
}
} else {
name := args[0]
namespacedName := types.NamespacedName{
Namespace: namespace,
Name: name,
}
var repository sourcev1.HelmRepository
err = kubeClient.Get(ctx, namespacedName, &repository)
if err != nil {
return err
}
if err := exportHelmRepository(repository); err != nil {
return err
}
if exportSourceWithCred {
return exportHelmCredentials(ctx, kubeClient, repository)
}
}
return nil
}
func exportHelmCredentials(ctx context.Context, kubeClient client.Client, source sourcev1.HelmRepository) error {
if source.Spec.SecretRef != nil {
namespacedName := types.NamespacedName{
Namespace: source.Namespace,
Name: source.Spec.SecretRef.Name,
}
var cred corev1.Secret
err := kubeClient.Get(ctx, namespacedName, &cred)
if err != nil {
return fmt.Errorf("failed to retrieve secret %s, error: %w", namespacedName.Name, err)
}
exported := corev1.Secret{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Secret",
},
ObjectMeta: metav1.ObjectMeta{
Name: namespacedName.Name,
Namespace: namespacedName.Namespace,
},
Data: cred.Data,
Type: cred.Type,
}
data, err := yaml.Marshal(exported)
if err != nil {
return err
}
fmt.Println("---")
fmt.Println(string(data))
}
return nil
}

@ -28,9 +28,12 @@ import (
var getKsCmd = &cobra.Command{
Use: "kustomizations",
Aliases: []string{"ks"},
Short: "Get Kustomization source statuses",
Short: "Get Kustomization statuses",
Long: "The get kustomizations command prints the statuses of the resources.",
RunE: getKsCmdRun,
Example: ` # List all kustomizations and their status
tk get kustomizations
`,
RunE: getKsCmdRun,
}
func init() {

@ -29,7 +29,10 @@ var getSourceGitCmd = &cobra.Command{
Use: "git",
Short: "Get GitRepository source statuses",
Long: "The get sources git command prints the status of the GitRepository sources.",
RunE: getSourceGitCmdRun,
Example: ` # List all Git repositories and their status
tk get sources git
`,
RunE: getSourceGitCmdRun,
}
func init() {

@ -0,0 +1,80 @@
/*
Copyright 2020 The Flux CD contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"context"
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
var getSourceHelmCmd = &cobra.Command{
Use: "helm",
Short: "Get HelmRepository source statuses",
Long: "The get sources helm command prints the status of the HelmRepository sources.",
Example: ` # List all Helm repositories and their status
tk get sources helm
`,
RunE: getSourceHelmCmdRun,
}
func init() {
getSourceCmd.AddCommand(getSourceHelmCmd)
}
func getSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
kubeClient, err := utils.kubeClient(kubeconfig)
if err != nil {
return err
}
var list sourcev1.HelmRepositoryList
err = kubeClient.List(ctx, &list, client.InNamespace(namespace))
if err != nil {
return err
}
if len(list.Items) == 0 {
logger.Failuref("no sources found in %s namespace", namespace)
return nil
}
for _, source := range list.Items {
isInitialized := false
for _, condition := range source.Status.Conditions {
if condition.Type == sourcev1.ReadyCondition {
if condition.Status != corev1.ConditionFalse {
logger.Successf("%s last fetched revision: %s", source.GetName(), source.Status.Artifact.Revision)
} else {
logger.Failuref("%s %s", source.GetName(), condition.Message)
}
isInitialized = true
break
}
}
if !isInitialized {
logger.Failuref("%s is not ready", source.GetName())
}
}
return nil
}

@ -34,7 +34,7 @@ var reconcileSourceHelmCmd = &cobra.Command{
Use: "helm [name]",
Short: "Reconcile a HelmRepository source",
Long: `The reconcile source command triggers a reconciliation of a HelmRepository resource and waits for it to finish.`,
Example: ` # Trigger a helm repo update for an existing source
Example: ` # Trigger a reconciliation for an existing source
tk reconcile source helm podinfo
`,
RunE: syncSourceHelmCmdRun,

@ -35,6 +35,9 @@ var resumeHrCmd = &cobra.Command{
Short: "Resume a suspended HelmRelease",
Long: `The resume command marks a previously suspended HelmRelease resource for reconciliation and waits for it to
finish the apply.`,
Example: ` # Resume reconciliation for an existing Helm release
tk resume hr podinfo
`,
RunE: resumeHrCmdRun,
}

@ -35,6 +35,9 @@ var resumeKsCmd = &cobra.Command{
Short: "Resume a suspended Kustomization",
Long: `The resume command marks a previously suspended Kustomization resource for reconciliation and waits for it to
finish the apply.`,
Example: ` # Resume reconciliation for an existing Kustomization
tk resume ks podinfo
`,
RunE: resumeKsCmdRun,
}

@ -31,7 +31,10 @@ var suspendHrCmd = &cobra.Command{
Aliases: []string{"hr"},
Short: "Suspend reconciliation of HelmRelease",
Long: "The suspend command disables the reconciliation of a HelmRelease resource.",
RunE: suspendHrCmdRun,
Example: ` # Suspend reconciliation for an existing Helm release
tk suspend hr podinfo
`,
RunE: suspendHrCmdRun,
}
func init() {

@ -29,7 +29,10 @@ var suspendKsCmd = &cobra.Command{
Aliases: []string{"ks"},
Short: "Suspend reconciliation of Kustomization",
Long: "The suspend command disables the reconciliation of a Kustomization resource.",
RunE: suspendKsCmdRun,
Example: ` # Suspend reconciliation for an existing Kustomization
tk suspend ks podinfo
`,
RunE: suspendKsCmdRun,
}
func init() {

@ -30,10 +30,10 @@ var uninstallCmd = &cobra.Command{
Short: "Uninstall the toolkit components",
Long: "The uninstall command removes the namespace, cluster roles, cluster role bindings and CRDs from the cluster.",
Example: ` # Dry-run uninstall of all components
uninstall --dry-run --namespace=gitops-system
tk uninstall --dry-run --namespace=gitops-system
# Uninstall all components and delete custom resource definitions
uninstall --crds --namespace=gitops-system
tk uninstall --crds --namespace=gitops-system
`,
RunE: uninstallCmdRun,
}

@ -21,19 +21,19 @@ tk bootstrap github [flags]
export GITHUB_TOKEN=<my-token>
# Run bootstrap for a private repo owned by a GitHub organization
bootstrap github --owner=<organization> --repository=<repo name>
tk bootstrap github --owner=<organization> --repository=<repo name>
# Run bootstrap for a private repo and assign organization teams to it
bootstrap github --owner=<organization> --repository=<repo name> --team=<team1 slug> --team=<team2 slug>
tk bootstrap github --owner=<organization> --repository=<repo name> --team=<team1 slug> --team=<team2 slug>
# Run bootstrap for a repository path
bootstrap github --owner=<organization> --repository=<repo name> --path=dev-cluster
tk bootstrap github --owner=<organization> --repository=<repo name> --path=dev-cluster
# Run bootstrap for a public repository on a personal account
bootstrap github --owner=<user> --repository=<repo name> --private=false --personal=true
tk bootstrap github --owner=<user> --repository=<repo name> --private=false --personal=true
# Run bootstrap for a private repo hosted on GitHub Enterprise
bootstrap github --owner=<organization> --repository=<repo name> --hostname=<domain>
tk bootstrap github --owner=<organization> --repository=<repo name> --hostname=<domain>
```

@ -21,16 +21,16 @@ tk bootstrap gitlab [flags]
export GITLAB_TOKEN=<my-token>
# Run bootstrap for a private repo owned by a GitLab group
bootstrap gitlab --owner=<group> --repository=<repo name>
tk bootstrap gitlab --owner=<group> --repository=<repo name>
# Run bootstrap for a repository path
bootstrap gitlab --owner=<group> --repository=<repo name> --path=dev-cluster
tk bootstrap gitlab --owner=<group> --repository=<repo name> --path=dev-cluster
# Run bootstrap for a public repository on a personal account
bootstrap gitlab --owner=<user> --repository=<repo name> --private=false --personal=true
tk bootstrap gitlab --owner=<user> --repository=<repo name> --private=false --personal=true
# Run bootstrap for a private repo hosted on a GitLab server
bootstrap gitlab --owner=<group> --repository=<repo name> --hostname=<domain>
tk bootstrap gitlab --owner=<group> --repository=<repo name> --hostname=<domain>
```

@ -14,7 +14,7 @@ tk create kustomization [name] [flags]
```
# Create a Kustomization resource from a source at a given path
create kustomization contour \
tk create kustomization contour \
--source=contour \
--path="./examples/contour/" \
--prune=true \
@ -25,7 +25,7 @@ tk create kustomization [name] [flags]
--health-check-timeout=3m
# Create a Kustomization resource that depends on the previous one
create kustomization webapp \
tk create kustomization webapp \
--depends-on=contour \
--source=webapp \
--path="./deploy/overlays/dev" \
@ -34,7 +34,7 @@ tk create kustomization [name] [flags]
--validation=client
# Create a Kustomization resource that runs under a service account
create kustomization webapp \
tk create kustomization webapp \
--source=webapp \
--path="./deploy/overlays/staging" \
--prune=true \

@ -27,4 +27,5 @@ The create source sub-commands generate sources.
* [tk create](tk_create.md) - Create or update sources and resources
* [tk create source git](tk_create_source_git.md) - Create or update a GitRepository source
* [tk create source helm](tk_create_source_helm.md) - Create or update a HelmRepository source

@ -17,35 +17,35 @@ tk create source git [name] [flags]
```
# Create a source from a public Git repository master branch
create source git podinfo \
tk create source git podinfo \
--url=https://github.com/stefanprodan/podinfo \
--branch=master
# Create a source from a Git repository pinned to specific git tag
create source git podinfo \
tk create source git podinfo \
--url=https://github.com/stefanprodan/podinfo \
--tag="3.2.3"
# Create a source from a public Git repository tag that matches a semver range
create source git podinfo \
tk create source git podinfo \
--url=https://github.com/stefanprodan/podinfo \
--tag-semver=">=3.2.0 <3.3.0"
# Create a source from a Git repository using SSH authentication
create source git podinfo \
tk create source git podinfo \
--url=ssh://git@github.com/stefanprodan/podinfo \
--branch=master
# Create a source from a Git repository using SSH authentication and an
# ECDSA P-521 curve public key
create source git podinfo \
tk create source git podinfo \
--url=ssh://git@github.com/stefanprodan/podinfo \
--branch=master \
--ssh-key-algorithm=ecdsa \
--ssh-ecdsa-curve=p521
# Create a source from a Git repository using basic authentication
create source git podinfo \
tk create source git podinfo \
--url=https://github.com/stefanprodan/podinfo \
--username=username \
--password=password

@ -0,0 +1,54 @@
## tk create source helm
Create or update a HelmRepository source
### Synopsis
The create source helm command generates a HelmRepository resource and waits for it to fetch the index.
For private Helm repositories, the basic authentication credentials are stored in a Kubernetes secret.
```
tk create source helm [name] [flags]
```
### Examples
```
# Create a source from a public Helm repository
tk create source helm podinfo \
--url=https://stefanprodan.github.io/podinfo \
--interval=10m
# Create a source from a Helm repository using basic authentication
tk create source helm podinfo \
--url=https://stefanprodan.github.io/podinfo \
--username=username \
--password=password
```
### Options
```
-h, --help help for helm
-p, --password string basic authentication password
--url string Helm repository address
-u, --username string basic authentication username
```
### Options inherited from parent commands
```
--export export in YAML format to stdout
--interval duration source sync interval (default 1m0s)
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk create source](tk_create_source.md) - Create or update sources

@ -10,6 +10,14 @@ The delete kustomization command deletes the given Kustomization from the cluste
tk delete kustomization [name] [flags]
```
### Examples
```
# Delete a kustomization and the Kubernetes resources created by it
tk delete kustomization podinfo
```
### Options
```

@ -26,4 +26,5 @@ The delete source sub-commands delete sources.
* [tk delete](tk_delete.md) - Delete sources and resources
* [tk delete source git](tk_delete_source_git.md) - Delete a GitRepository source
* [tk delete source helm](tk_delete_source_helm.md) - Delete a HelmRepository source

@ -10,6 +10,14 @@ The delete source git command deletes the given GitRepository from the cluster.
tk delete source git [name] [flags]
```
### Examples
```
# Delete a Git repository
tk delete source git podinfo
```
### Options
```

@ -0,0 +1,40 @@
## tk delete source helm
Delete a HelmRepository source
### Synopsis
The delete source helm command deletes the given HelmRepository from the cluster.
```
tk delete source helm [name] [flags]
```
### Examples
```
# Delete a Helm repository
tk delete source helm podinfo
```
### Options
```
-h, --help help for helm
```
### Options inherited from parent commands
```
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
-s, --silent delete resource without asking for confirmation
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk delete source](tk_delete_source.md) - Delete sources

@ -14,10 +14,10 @@ tk export kustomization [name] [flags]
```
# Export all Kustomization resources
export kustomization --all > kustomizations.yaml
tk export kustomization --all > kustomizations.yaml
# Export a Kustomization
export kustomization my-app > kustomization.yaml
tk export kustomization my-app > kustomization.yaml
```

@ -27,4 +27,5 @@ The export source sub-commands export sources in YAML format.
* [tk export](tk_export.md) - Export resources in YAML format
* [tk export source git](tk_export_source_git.md) - Export GitRepository sources in YAML format
* [tk export source helm](tk_export_source_helm.md) - Export HelmRepository sources in YAML format

@ -14,10 +14,10 @@ tk export source git [name] [flags]
```
# Export all GitRepository sources
export source git --all > sources.yaml
tk export source git --all > sources.yaml
# Export a GitRepository source including the SSH key pair or basic auth credentials
export source git my-private-repo --with-credentials > source.yaml
tk export source git my-private-repo --with-credentials > source.yaml
```

@ -0,0 +1,44 @@
## tk export source helm
Export HelmRepository sources in YAML format
### Synopsis
The export source git command exports on or all HelmRepository sources in YAML format.
```
tk export source helm [name] [flags]
```
### Examples
```
# Export all HelmRepository sources
tk export source helm --all > sources.yaml
# Export a HelmRepository source including the basic auth credentials
tk export source helm my-private-repo --with-credentials > source.yaml
```
### Options
```
-h, --help help for helm
```
### Options inherited from parent commands
```
--all select all resources
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
--with-credentials include credential secrets
```
### SEE ALSO
* [tk export source](tk_export_source.md) - Export sources

@ -24,6 +24,6 @@ The get sub-commands print the statuses of sources and resources.
### SEE ALSO
* [tk](tk.md) - Command line utility for assembling Kubernetes CD pipelines
* [tk get kustomizations](tk_get_kustomizations.md) - Get Kustomization source statuses
* [tk get kustomizations](tk_get_kustomizations.md) - Get Kustomization statuses
* [tk get sources](tk_get_sources.md) - Get source statuses

@ -1,6 +1,6 @@
## tk get kustomizations
Get Kustomization source statuses
Get Kustomization statuses
### Synopsis
@ -10,6 +10,14 @@ The get kustomizations command prints the statuses of the resources.
tk get kustomizations [flags]
```
### Examples
```
# List all kustomizations and their status
tk get kustomizations
```
### Options
```

@ -25,4 +25,5 @@ The get source sub-commands print the statuses of the sources.
* [tk get](tk_get.md) - Get sources and resources
* [tk get sources git](tk_get_sources_git.md) - Get GitRepository source statuses
* [tk get sources helm](tk_get_sources_helm.md) - Get HelmRepository source statuses

@ -10,6 +10,14 @@ The get sources git command prints the status of the GitRepository sources.
tk get sources git [flags]
```
### Examples
```
# List all Git repositories and their status
tk get sources git
```
### Options
```

@ -0,0 +1,39 @@
## tk get sources helm
Get HelmRepository source statuses
### Synopsis
The get sources helm command prints the status of the HelmRepository sources.
```
tk get sources helm [flags]
```
### Examples
```
# List all Helm repositories and their status
tk get sources helm
```
### Options
```
-h, --help help for helm
```
### Options inherited from parent commands
```
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
--namespace string the namespace scope for this operation (default "gitops-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [tk get sources](tk_get_sources.md) - Get source statuses

@ -13,7 +13,7 @@ tk reconcile source helm [name] [flags]
### Examples
```
# Trigger a helm repo update for an existing source
# Trigger a reconciliation for an existing source
tk reconcile source helm podinfo
```

@ -11,6 +11,14 @@ finish the apply.
tk resume helmrelease [name] [flags]
```
### Examples
```
# Resume reconciliation for an existing Helm release
tk resume hr podinfo
```
### Options
```

@ -11,6 +11,14 @@ finish the apply.
tk resume kustomization [name] [flags]
```
### Examples
```
# Resume reconciliation for an existing Kustomization
tk resume ks podinfo
```
### Options
```

@ -10,6 +10,14 @@ The suspend command disables the reconciliation of a HelmRelease resource.
tk suspend helmrelease [name] [flags]
```
### Examples
```
# Suspend reconciliation for an existing Helm release
tk suspend hr podinfo
```
### Options
```

@ -10,6 +10,14 @@ The suspend command disables the reconciliation of a Kustomization resource.
tk suspend kustomization [name] [flags]
```
### Examples
```
# Suspend reconciliation for an existing Kustomization
tk suspend ks podinfo
```
### Options
```

@ -14,10 +14,10 @@ tk uninstall [flags]
```
# Dry-run uninstall of all components
uninstall --dry-run --namespace=gitops-system
tk uninstall --dry-run --namespace=gitops-system
# Uninstall all components and delete custom resource definitions
uninstall --crds --namespace=gitops-system
tk uninstall --crds --namespace=gitops-system
```

@ -227,7 +227,7 @@ If you delete a kustomization from the `fleet-infra` repo, the reconciler will r
were previously applied from that kustomization.
If you alter the webapp deployment using `kubectl edit`, the changes will be reverted to match
the state described in git. When dealing with an incident, you can pause the recitation of a
the state described in git. When dealing with an incident, you can pause the reconciliation of a
kustomization with `tk suspend kustomization <name>`. Once the debugging session
is over, you can re-enable the reconciliation with `tk resume kustomization <name>`.

@ -75,18 +75,22 @@ nav:
- Create kustomization: cmd/tk_create_kustomization.md
- Create source: cmd/tk_create_source.md
- Create source git: cmd/tk_create_source_git.md
- Create source helm: cmd/tk_create_source_helm.md
- Delete: cmd/tk_delete.md
- Delete kustomization: cmd/tk_delete_kustomization.md
- Delete source: cmd/tk_delete_source.md
- Delete source git: cmd/tk_delete_source_git.md
- Delete source helm: cmd/tk_delete_source_helm.md
- Export: cmd/tk_export.md
- Export kustomization: cmd/tk_export_kustomization.md
- Export source: cmd/tk_export_source.md
- Export source git: cmd/tk_export_source_git.md
- Export source helm: cmd/tk_export_source_helm.md
- Get: cmd/tk_get.md
- Get kustomizations: cmd/tk_get_kustomizations.md
- Get sources: cmd/tk_get_sources.md
- Get sources git: cmd/tk_get_sources_git.md
- Get sources helm: cmd/tk_get_sources_helm.md
- Install: cmd/tk_install.md
- Resume: cmd/tk_resume.md
- Resume kustomization: cmd/tk_resume_kustomization.md

Loading…
Cancel
Save