Skip to content

Commit

Permalink
docs: README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Telemaco019 committed Sep 8, 2024
1 parent bdf3ed4 commit 36ce476
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
# Dependency directories (remove the comment below to include it)
# vendor/

# MacOS stuff
.DS_Store

# Go workspace file
go.work
go.work.sum
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2024 Michele Zanotti <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
71 changes: 70 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

---

![](./docs/demo.gif)
![](./docs/demo.jpg)

**kubesafe** allows you to safely run commands acrosss multiple Kubernetes contexts.
By allowing you to mark specific contexts as "safe" and define a list of protected commands, kubesafe makes sure
Expand All @@ -22,6 +22,32 @@ Key Features:
- **🛡️ Context Protection with Custom Commands**: Mark one or more contexts as "safe" and define a list of commands that require confirmation before execution.
- **🔄 Flexible and Customizable**: Easily configure protected contexts and commands to suit your workflow.

## How does it work?

Simply prepend `kubesafe` to any command you want to run:

```shell
# Example with kubectl
kubesafe kubectl delete pod my-pod

# Example with Helm
kubesafe helm upgrade my-release stable/my-chart
```

Kubesafe seamlessly wraps any CLI command you provide as the first argument (e.g., kubectl, helm, etc.).
If you attempt to run a protected command in a safe context, kubesafe will prompt you for confirmation before proceeding.

For convinience, you can set aliases in your shell configuration:

```shell
alias kubectl='kubesafe kubectl'
alias helm='kubesafe helm'
```

Now, every time you use kubectl or helm, kubesafe will automatically protect your commands!

To manage your safe contexts and protected commands, see the [Managing contexts](#managing-contexts) section.

## Installation

### Install with Homebrew (Mac/Linux)
Expand All @@ -37,4 +63,47 @@ $ brew install kubesafe
$ go install github.com/telemaco019/kubesafe/kubesafe@latest
```

## Managing contexts

Kubesafe makes it easy to manage your safe contexts and protected commands. To see all available options, run:

```shell
kubesafe --help
```

### Adding a safe context

To add a safe context, simply execute:

```shell
kubesafe context add
```

Kubesafe will guide you interactively to select a context to mark as "safe" and choose the commands you want to protect.
Alternatively, you can add a safe context directly by specifying its name:

```shell
kubesafe context add my-context
```

### Listing Safe Contexts

To display all your configured safe contexts and their protected commands, use:

```shell
kubesafe context list
```

### Removing a safe context

To remove a context from your list of safe contexts, run:

```shell
kubesafe context remove my-context
```

## Similar tools

## License

This project is licensed under the Apache License. See the [LICENSE](./LICENSE) file for details.
Binary file added docs/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/demo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions docs/demo.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Output ./docs/demo.gif

Set Width 1500
Set LineHeight 1.7

Set Shell zsh

Type "kubesafe context add"
Enter
Sleep 500ms
Type "j"
Sleep 1.5s
Enter
# Show commands
Sleep 1s
Enter
Sleep 200ms

Type 'alias k="kubesafe kubectl"'
Enter
Sleep 200ms
Type 'alias helm="kubesafe helm"'
Enter
Sleep 200ms

# Kubectl example
Type "k delete pod my-pod --context prod-cluster"
Enter
Sleep 1s
Type "n"
Enter

# Helm example
Type "helm install my-release my-chart --context prod-cluster"
Enter
Sleep 1s
Type "n"
Enter

Sleep 3s
2 changes: 2 additions & 0 deletions internal/cmd/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cmd
import (
"fmt"
"os"
"sort"

"github.com/charmbracelet/huh"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -53,6 +54,7 @@ func selectContext(settings core.Settings, args []string) (string, error) {
selectableContexts = append(selectableContexts, context)
}
}
sort.Strings(selectableContexts)
if len(selectableContexts) == 0 {
return "", fmt.Errorf("no contexts are available")
}
Expand Down

0 comments on commit 36ce476

Please sign in to comment.