Implement delete for git sources
- add delete source git command - add delete source git e2e test
This commit is contained in:
3
.github/workflows/e2e.yaml
vendored
3
.github/workflows/e2e.yaml
vendored
@@ -83,6 +83,9 @@ jobs:
|
||||
- name: tk delete kustomization
|
||||
run: |
|
||||
./bin/tk delete kustomization podinfo --silent
|
||||
- name: tk delete source git
|
||||
run: |
|
||||
./bin/tk delete source git podinfo --silent
|
||||
- name: tk check
|
||||
run: |
|
||||
./bin/tk check
|
||||
|
||||
14
cmd/tk/delete_source.go
Normal file
14
cmd/tk/delete_source.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var deleteSourceCmd = &cobra.Command{
|
||||
Use: "source",
|
||||
Short: "Delete sources commands",
|
||||
}
|
||||
|
||||
func init() {
|
||||
deleteCmd.AddCommand(deleteSourceCmd)
|
||||
}
|
||||
68
cmd/tk/delete_source_git.go
Normal file
68
cmd/tk/delete_source_git.go
Normal file
@@ -0,0 +1,68 @@
|
||||
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 deleteSourceGitCmd = &cobra.Command{
|
||||
Use: "git [name]",
|
||||
Short: "Delete git source",
|
||||
RunE: deleteSourceGitCmdRun,
|
||||
}
|
||||
|
||||
func init() {
|
||||
deleteSourceCmd.AddCommand(deleteSourceGitCmd)
|
||||
}
|
||||
|
||||
func deleteSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
||||
if len(args) < 1 {
|
||||
return fmt.Errorf("git 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 git sourcev1.GitRepository
|
||||
err = kubeClient.Get(ctx, namespacedName, &git)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !deleteSilent {
|
||||
prompt := promptui.Prompt{
|
||||
Label: fmt.Sprintf(
|
||||
"Are you sure you want to delete the %s source from the %s namespace", name, namespace,
|
||||
),
|
||||
IsConfirm: true,
|
||||
}
|
||||
if _, err := prompt.Run(); err != nil {
|
||||
return fmt.Errorf("aborting")
|
||||
}
|
||||
}
|
||||
|
||||
logAction("deleting source %s in %s namespace", name, namespace)
|
||||
err = kubeClient.Delete(ctx, &git)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logSuccess("source deleted")
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -27,14 +27,20 @@ var rootCmd = &cobra.Command{
|
||||
tk install --version=master
|
||||
|
||||
# Create a source from a public Git repository
|
||||
tk create source git webapp \
|
||||
tk create source git webapp-latest \
|
||||
--url=https://github.com/stefanprodan/podinfo \
|
||||
--branch=master \
|
||||
--interval=3m
|
||||
|
||||
# List git sources and their status
|
||||
tk get sources git
|
||||
|
||||
# Trigger a git sync
|
||||
tk sync source git webapp-latest
|
||||
|
||||
# Create a kustomization for deploying a series of microservices
|
||||
tk create kustomization webapp \
|
||||
--source=webapp \
|
||||
tk create kustomization webapp-dev \
|
||||
--source=webapp-latest \
|
||||
--path="./deploy/webapp/" \
|
||||
--prune="instance=webapp" \
|
||||
--generate=true \
|
||||
@@ -45,7 +51,22 @@ var rootCmd = &cobra.Command{
|
||||
--health-check-timeout=2m
|
||||
|
||||
# Trigger a git sync and apply changes if any
|
||||
sync kustomization webapp --with-source
|
||||
tk sync kustomization webapp-dev --with-source
|
||||
|
||||
# Suspend a kustomization reconciliation
|
||||
tk suspend kustomization webapp-dev
|
||||
|
||||
# Resume a kustomization reconciliation
|
||||
tk resume kustomization webapp-dev
|
||||
|
||||
# Delete a kustomization
|
||||
tk delete kustomization webapp-dev
|
||||
|
||||
# Delete a git source
|
||||
tk delete source git webapp-latest
|
||||
|
||||
# Uninstall the toolkit and delete CRDs
|
||||
tk uninstall --crds
|
||||
`,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user