Skip to content

Commit

Permalink
make setup
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfenwick committed Jul 28, 2020
1 parent 12f6482 commit 53668fa
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 388 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
*.out

bin/

.idea/
16 changes: 8 additions & 8 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
project_name: {{ .PluginName }}
project_name: node-pod
release:
github:
owner: {{ .Owner }}
name: {{ .Repo }}
owner: mattfenwick
name: krew-node-pod
builds:
- id: {{ .PluginName }}
- id: node-pod
goos:
- linux
- windows
Expand All @@ -17,12 +17,12 @@ builds:
- GO111MODULE=on
main: cmd/plugin/main.go
ldflags: -s -w
-X github.com/{{ .Owner }}/{{ .Repo }}/pkg/version.version=
-X github.com/mattfenwick/krew-node-pod/pkg/version.version=
archives:
- id: {{ .PluginName }}
- id: node-pod
builds:
- {{ .PluginName }}
name_template: {{ `"{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"` }}
- node-pod
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
format_overrides:
- goos: windows
format: zip
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test:

.PHONY: bin
bin: fmt vet
go build -o bin/{{ .PluginName }} github.com/{{ .Owner }}/{{ .Repo }}/cmd/plugin
go build -o bin/node-pod github.com/mattfenwick/krew-node-pod/cmd/plugin

.PHONY: fmt
fmt:
Expand Down
66 changes: 5 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,11 @@
# kubectl krew template repo
# node-pod kubectl

There's a lot of scaffolding needed to set up a good kubectl plugin. This repo is a GitHub Template Repo to make it easy to set all of this scaffolding up for a new repo.
A `kubectl` plugin to ...

The assumptions made are:
1. You'll write your plugin in go
2. You want client-go to interact with the cluster
3. You want all of the kubectl flags available to your plugin
4. Your plugin's home will be a github.com repo
5. Your plugin will work in Linux, MacOS and Windows
## Quick Start

## Create your repo

[Start here](https://github.com/replicatedhq/krew-plugin-template/generate) to create a new repo based on this template. This is not a fork, it will make a copy of this repo into your own organization or GitHub account.

Click that, and create your own version of this repo. Clone it locally. The rest of the steps you will be performing on your local copy.

## Make it yours

Once you have your own repo created locally, change to the directory and run:

```shell
make setup
```

This will prompt you for a few things, such as your GitHub org, repo name and plugin name. The setup application will then update the import paths and code with the data you provided.

(Note, once you've run this step, these instructions will no longer be present in your repo. You can always vew then at [https://github.com/replicatedhq/krew-plugin-template](https://github.com/replicatedhq/krew-plugin-template)).

Commit and check it in to your repo!

```shell
git add .
git commit -m "Updating from template"
git push -u origin master
kubectl krew install node-pod
kubectl node-pod
```

## Write your Plugin

Next, open the pkg/plugin/plugin.go file. This is where you can start writing your plugin.

For an example, take a look at the [outdated](https://github.com/replicatedhq/outdated) plugin that inspired this template.

To make a local build:

```shell
make bin
```

## Creating a release

To create a new release of your plugin, create and push a tag.

```shell
git tag v0.1.0 -m 'initial release'
git push --tags
```

This repo has a built-in GitHub Action that will handle the build process. We use [GoReleaser](https://goreleaser.com) to create tagged releases. This will create all three binaries and push them to the releases page when you push a tag. It will take a few minutes to complete, so be patient.

## Submitting to Krew

Be sure to read the guidelines on the Krew Developer guide before submitting you plugin. This is not automated (yet). We've created a starting point for your plugin manifest, look for it in deploy/krew/plugin.yaml.

## Share!

Finally, we'd love to hear if you've used this template. Let us know on Twitter at @replicatedhq. We've written a few kubectl plugins too, and are always curious to see what other people are working on.
6 changes: 3 additions & 3 deletions cmd/plugin/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strings"
"time"

"github.com/{{ .Owner }}/{{ .Repo }}/pkg/logger"
"github.com/{{ .Owner }}/{{ .Repo }}/pkg/plugin"
"github.com/mattfenwick/krew-node-pod/pkg/logger"
"github.com/mattfenwick/krew-node-pod/pkg/plugin"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -21,7 +21,7 @@ var (

func RootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "{{ .PluginName }}",
Use: "node-pod",
Short: "",
Long: `.`,
SilenceErrors: true,
Expand Down
2 changes: 1 addition & 1 deletion cmd/plugin/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/{{ .Owner }}/{{ .Repo }}/cmd/plugin/cli"
"github.com/mattfenwick/krew-node-pod/cmd/plugin/cli"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp" // required for GKE
)

Expand Down
28 changes: 14 additions & 14 deletions deploy/krew/plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
name: {{ .PluginName }}
name: node-pod
spec:
version: "v0.1.0"
platforms:
- selector:
matchLabels:
os: linux
arch: amd64
uri: https://github.com/{{ .Owner }}/{{ .Repo }}/releases/download/v0.1.0/{{ .PluginName }}_linux_amd64.tar.gz
uri: https://github.com/mattfenwick/krew-node-pod/releases/download/v0.1.0/node-pod_linux_amd64.tar.gz
sha256: ""
files:
- from: "./{{ .PluginName }}"
- from: "./node-pod"
to: "."
- from: LICENSE
to: "."
bin: "{{ .PluginName }}"
bin: "node-pod"
- selector:
matchLabels:
os: darwin
arch: amd64
uri: https://github.com/{{ .Owner }}/{{ .Repo }}/releases/download/v0.1.0/{{ .PluginName }}_darwin_amd64.tar.gz
uri: https://github.com/mattfenwick/krew-node-pod/releases/download/v0.1.0/node-pod_darwin_amd64.tar.gz
sha256: ""
files:
- from: "./{{ .PluginName }}"
- from: "./node-pod"
to: "."
- from: LICENSE
to: "."
bin: "{{ .PluginName }}"
bin: "node-pod"
- selector:
matchLabels:
os: windows
arch: amd64
uri: https://github.com/{{ .Owner }}/{{ .Repo }}/releases/download/v0.1.0/{{ .PluginName }}_windows_amd64.zip
uri: https://github.com/mattfenwick/krew-node-pod/releases/download/v0.1.0/node-pod_windows_amd64.zip
sha256: ""
files:
- from: "/{{ .PluginName }}.exe"
- from: "/node-pod.exe"
to: "."
- from: LICENSE
to: "."
bin: "{{ .PluginName }}.exe"
bin: "node-pod.exe"
shortDescription: A new plugin
homepage: https://github.com/{{ .Owner }}/{{ .Repo }}
homepage: https://github.com/mattfenwick/krew-node-pod
caveats: |
Usage:
$ kubectl {{ .PluginName }}
$ kubectl node-pod
For additional options:
$ kubectl {{ .PluginName }} --help
or https://github.com/{{ .Owner }}/{{ .Repo }}/blob/v0.1.0/doc/USAGE.md
$ kubectl node-pod --help
or https://github.com/mattfenwick/krew-node-pod/blob/v0.1.0/doc/USAGE.md
description: |
This is a new plugin
6 changes: 3 additions & 3 deletions doc/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
The following assumes you have the plugin installed via

```shell
kubectl krew install {{ .PluginName }}
kubectl krew install node-pod
```

### Scan images in your current kubecontext

```shell
kubectl {{ .PluginName }}
kubectl node-pod
```

### Scan images in another kubecontext

```shell
kubectl {{ .PluginName }} --context=context-name
kubectl node-pod --context=context-name
```

## How it works
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/replicatedhq/krew-plugin-template
module github.com/mattfenwick/krew-node-pod

go 1.12

Expand Down
6 changes: 0 additions & 6 deletions setup/Makefile

This file was deleted.

29 changes: 0 additions & 29 deletions setup/gomod.go

This file was deleted.

11 changes: 0 additions & 11 deletions setup/hack/README.txt

This file was deleted.

0 comments on commit 53668fa

Please sign in to comment.