Skip to content

Commit

Permalink
feat: 🎉 get the ball rolling
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostsquad committed Aug 2, 2020
1 parent ee757e0 commit c2e5d46
Show file tree
Hide file tree
Showing 33 changed files with 2,674 additions and 3 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
vendor/

tmp/

/seaworthy
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.PHONY: gen
gen:
go generate ./...

.PHONY: fmt
fmt:
go fmt ./...

.PHONY: vet
vet:
go vet ./...

.PHONY: build
build: clean
go build -o ./seaworthy ./cmd/seaworthy
chmod +x ./seaworthy

clean:
rm -f ./seaworthy
80 changes: 78 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,78 @@
# dicap
Status Monitoring for Kubernetes Resources (Damage Identification Capability)
#



<h1 align="center">
<br>
<a href="http://github.com/cakehappens/seaworthy"><img src="./assets/036-yacht.svg" alt="seaworthy" width="200px" /></a>
<br>
Seaworthy
<br>
</h1>

<h4 align="center">Post-apply check to verify your K8s resources are <i>Seaworthy</i></h4>

<p align="center">
<a href="https://github.com/cakehappens/seaworthy/releases/">
<img src="https://img.shields.io/github/release/cakehappens/seaworthy.svg">
</a>
<a href="https://pkg.go.dev/github.com/cakehappens/seaworthy">
<img src="https://img.shields.io/badge/godoc-reference-5272B4.svg">
</a>
<img src="https://img.shields.io/github/go-mod/go-version/cakehappens/seaworthy">
<br />
<a href="./docs/tanka.md">
<img src="https://img.shields.io/badge/tanka-ready-orange.svg">
</a>
<a href="https://saythanks.io/to/ghostsquad">
<img src="https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg">
</a>
<a href="buymeacoff.ee/50onA1pjc">
<img src="https://img.shields.io/badge/buymeacoffee-%24-orange">
</a>
<a href="./LICENSE">
<img src="https://img.shields.io/github/license/cakehappens/seaworthy">
</a>
</p>

<p align="center">
<a href="#introduction">Introduction</a> •
<a href="#install">Install</a> •
<a href="#how-to-use">How To Use</a> •
<a href="#credits">Credits</a> •
<a href="#related--inspiration">Related</a> •
<a href="#credits">License</a> •
<a href="#license">License</a>
</p>

## 👋 Introduction

`Seaworthy` is your post-apply validation that your K8s resources deployed correctly and are healthy.

## ⚡️ Install

```shell
go get github.com/cakehappens/seaworthy/cmd/seaworthy
```

### ASDF

_coming soon_

```shell
asdf plugin-add seaworthy https://github.com/cakehappens/asdf-seaworthy.git
```

## 📖 How To Use

```shell
seaworthy --help
```

You can find more information in [the docs 📖](./docs)!

## ⚖️ License

<a href="./LICENSE">
<img src="https://img.shields.io/github/license/cakehappens/lonely-mountain">
</a>
1 change: 1 addition & 0 deletions assets/036-yacht.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
112 changes: 112 additions & 0 deletions cmd/seaworthy/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package main

import (
"context"
"errors"
"fmt"
"github.com/cakehappens/seaworthy/pkg/clioptions"
cmdverify "github.com/cakehappens/seaworthy/pkg/cmd/verify"
"github.com/cakehappens/seaworthy/pkg/kubernetes"
"github.com/cakehappens/seaworthy/pkg/util/templates"
"github.com/fatih/color"
"github.com/oklog/run"
"github.com/spf13/cobra"
"io"
"os"
"os/signal"
"syscall"

// registers health checks
_ "github.com/cakehappens/seaworthy/pkg/kubernetes/health/install"
)

const binaryName = "seaworthy"

func NewSeaworthyCommand(in io.Reader, out, err io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: binaryName,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
runHelp(cmd, args)
return nil
}

fmt.Println("main")

fmt.Printf("running: %s\n", args)

color.New(color.FgGreen).Fprintln(os.Stderr, "Done!")
return nil
},
}

client := kubernetes.NewKubectl()

ioStreams := clioptions.IOStreams{In: in, Out: out, ErrOut: err}
groups := templates.CommandGroups{
{
Message: "Basic Commands (Beginner):",
Commands: []*cobra.Command{
cmdverify.New(ioStreams, client),
},
},
}
groups.Add(cmd)
templates.ActsAsRootCommand(cmd, nil, groups...)

return cmd
}

func runHelp(cmd *cobra.Command, args []string) {
cmd.Help()
}

func main() {
ctx, cancel := context.WithCancel(context.Background())

runGroup := run.Group{}
{
cancelInterrupt := make(chan struct{})
runGroup.Add(
createSignalWatcher(ctx, cancelInterrupt, cancel),
func(error) {
close(cancelInterrupt)
})
}
{
runGroup.Add(func() error {
rootC := NewSeaworthyCommand(os.Stdin, os.Stdout, os.Stderr)
rootC.SetArgs(os.Args[1:])
return rootC.ExecuteContext(ctx)
}, func(error) {
cancel()
})
}

err := runGroup.Run()
if err != nil {
fmt.Fprintf(os.Stderr, "exit reason: %s\n", err)
os.Exit(1)
}
}

// This function just sits and waits for ctrl-C
func createSignalWatcher(ctx context.Context, cancelInterruptChan <-chan struct{}, cancel context.CancelFunc) func() error {
return func() error {
c := make(chan os.Signal, 1)

signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
select {
case sig := <-c:
err := errors.New(fmt.Sprintf("received signal %s", sig))
fmt.Fprintf(os.Stderr, "%s\n", err)
signal.Stop(c)
cancel()
return err
case <-ctx.Done():
return nil
case <-cancelInterruptChan:
return nil
}
}
}
19 changes: 19 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module github.com/cakehappens/seaworthy

go 1.14

require (
github.com/fatih/color v1.9.0
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mitchellh/go-wordwrap v1.0.0
github.com/moby/term v0.0.0-20200611042045-63b9a826fb74
github.com/oklog/run v1.1.0
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5
github.com/theckman/yacspin v0.8.0
golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c
k8s.io/api v0.18.6
k8s.io/apimachinery v0.18.6
k8s.io/client-go v0.18.6
k8s.io/kubectl v0.18.6
)
Loading

0 comments on commit c2e5d46

Please sign in to comment.