diff --git a/.github/workflows/krew.yml b/.github/workflows/krew.yml new file mode 100644 index 00000000..bbb1e95e --- /dev/null +++ b/.github/workflows/krew.yml @@ -0,0 +1,29 @@ +name: release +on: + workflow_dispatch: + push: + tags: + - "v*.*.*" + +jobs: + krew: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@master + + # - name: Setup Go + # uses: actions/setup-go@v1 + # with: + # go-version: 1.16.3 + + # - name: GoReleaser + # uses: goreleaser/goreleaser-action@v1 + # with: + # version: latest + # args: release --rm-dist + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Update new version in krew-index + uses: rajatjindal/krew-release-bot@v0.0.40 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 1f1db9f6..00000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: release -on: - workflow_dispatch: - - push: - tags: - - "v*.*.*" -jobs: - goreleaser: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@master - - name: Setup Go - uses: actions/setup-go@v1 - with: - go-version: 1.16.3 - - name: GoReleaser - uses: goreleaser/goreleaser-action@v1 - with: - version: latest - args: release --rm-dist - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Update new version in krew-index - uses: rajatjindal/krew-release-bot@v0.0.40 diff --git a/.krew.yaml b/.krew.yaml index 264ae733..def9d4f7 100644 --- a/.krew.yaml +++ b/.krew.yaml @@ -21,36 +21,36 @@ spec: Popeye is a readonly tool, it does not alter any of your Kubernetes resources in any way! platforms: - - selector: - matchLabels: - os: darwin - arch: amd64 - {{addURIAndSha "https://github.com/derailed/popeye/releases/download/{{ .TagName }}/popeye_Darwin_x86_64.tar.gz" .TagName | indent 6 }} + - bin: kubectl-popeye + {{ addURIAndSha "https://github.com/derailed/popeye/releases/download/{{ .TagName }}/popeye_Darwin_x86_64.tar.gz" .TagName }} files: - from: popeye to: kubectl-popeye - from: LICENSE - to: "." - bin: kubectl-popeye - - selector: + to: . + selector: matchLabels: - os: linux + os: darwin arch: amd64 - {{addURIAndSha "https://github.com/derailed/popeye/releases/download/{{ .TagName }}/popeye_Linux_x86_64.tar.gz" .TagName | indent 6 }} + - bin: kubectl-popeye + {{ addURIAndSha "https://github.com/derailed/popeye/releases/download/{{ .TagName }}/popeye_Linux_x86_64.tar.gz" .TagName }} files: - from: popeye to: kubectl-popeye - from: LICENSE - to: "." - bin: kubectl-popeye - - selector: + to: . + selector: matchLabels: - os: windows + os: linux arch: amd64 - {{addURIAndSha "https://github.com/derailed/popeye/releases/download/{{ .TagName }}/popeye_Windows_x86_64.tar.gz" .TagName | indent 6 }} + - bin: kubectl-popeye.exe + {{ addURIAndSha "https://github.com/derailed/popeye/releases/download/{{ .TagName }}/popeye_Windows_x86_64.tar.gz" .TagName }} files: - from: popeye.exe to: kubectl-popeye.exe - from: LICENSE - to: "." - bin: kubectl-popeye.exe + to: . + selector: + matchLabels: + os: windows + arch: amd64 diff --git a/README.md b/README.md index 8b051370..8e254a7e 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ Popeye is a readonly tool, it does not alter any of your Kubernetes resources in [![codebeat badge](https://codebeat.co/badges/827e5642-3ccc-4ecc-b22b-5707dbc34cf1)](https://codebeat.co/projects/github-com-derailed-popeye-master) [![Build Status](https://travis-ci.com/derailed/popeye.svg?branch=master)](https://travis-ci.com/derailed/popeye) [![release](https://img.shields.io/github/release-pre/derailed/popeye.svg)](https://github.com/derailed/popeye/releases) -[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/derailed/popeye/blob/master/LICENSE) -[![Docker Repository on Quay](https://quay.io/repository/derailed/popeye/status "Docker Repository on Quay")](https://quay.io/repository/derailed/popeye) +[![license](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/derailed/popeye/blob/master/LICENSE) +[![docker](https://img.shields.io/docker/cloud/build/derailed/popeye?label=Docker&style=flat)](https://hub.docker.com/r/derailed/popeye/builds) ![GitHub stars](https://img.shields.io/github/stars/derailed/popeye.svg?label=github%20stars) [![Releases](https://img.shields.io/github/downloads/derailed/popeye/total.svg)]() @@ -188,7 +188,7 @@ popeye --s3-bucket=NAME-OF-YOUR-S3-BUCKET/OPTIONAL/SUBDIRECTORY --out=json ### Run public docker image locally You don't have to build and/or install the binary to run popeye: you can just -run it directly from the official docker repo on quay.io. The default command +run it directly from the official docker repo on DockerHub. The default command when you run the docker container is `popeye`, so you just need to pass whatever cli args are normally passed to popeye. To access your clusters, map your local kube config directory into the container with `-v` : @@ -196,7 +196,7 @@ your local kube config directory into the container with `-v` : ```shell docker run --rm -it \ -v $HOME/.kube:/root/.kube \ - quay.io/derailed/popeye --context foo -n bar + derailed/popeye --context foo -n bar ``` Running the above docker command with `--rm` means that the container gets @@ -210,7 +210,7 @@ NOTE: You can override the default output directory location by setting `POPEYE_ -v $HOME/.kube:/root/.kube \ -e POPEYE_REPORT_DIR=/tmp/popeye \ -v /tmp:/tmp \ - quay.io/derailed/popeye --context foo -n bar --save --output-file my_report.txt + derailed/popeye --context foo -n bar --save --output-file my_report.txt # Docker has exited, and the container has been deleted, but the file # is in your /tmp directory because you mapped it into the container @@ -362,7 +362,7 @@ spec: restartPolicy: Never containers: - name: popeye - image: quay.io/derailed/popeye + image: derailed/popeye imagePullPolicy: IfNotPresent args: - -o diff --git a/change_logs/release_v0.9.7.md b/change_logs/release_v0.9.7.md new file mode 100644 index 00000000..70847b98 --- /dev/null +++ b/change_logs/release_v0.9.7.md @@ -0,0 +1,26 @@ + + +# Release v0.9.7 + +## Notes + +Thank you to all that contributed with flushing out issues and enhancements for Popeye! I'll try to mark some of these issues as fixed. But if you don't mind grab the latest rev and see if we're happier with some of the fixes! If you've filed an issue please help me verify and close. Your support, kindness and awesome suggestions to make Popeye better is as ever very much noticed and appreciated! + +This project offers a GitHub Sponsor button (over here 👆). As you well know this is not pimped out by big corps with deep pockets. If you feel `Popeye` is saving you cycles diagnosing potential cluster issues please consider sponsoring this project!! It does go a long way in keeping our servers lights on and beers in our fridge. + +Also if you dig this tool, please make some noise on social! [@kitesurfer](https://twitter.com/kitesurfer) + +--- + +## Maintenance Release! + +--- + +## Resolved Bugs/PRs + +* [Issue #190](https://github.com/derailed/popeye/issues/190) Popeye docker image tag 0.9.6 not available on quay.io +* [Issue #163](https://github.com/derailed/popeye/issues/163) popeye 0.9.0 with K8S 1.21.0 bug on PodDisruptionBudget - Wrong default API. With Feelings! + +--- + +  © 2020 Imhotep Software LLC. All materials licensed under [Apache v2.0](http://www.apache.org/licenses/LICENSE-2.0) diff --git a/internal/client/meta.go b/internal/client/meta.go index c1b942ab..a7f372e4 100644 --- a/internal/client/meta.go +++ b/internal/client/meta.go @@ -4,19 +4,23 @@ import ( "github.com/derailed/popeye/types" ) +// Schema tracks resource schema. type Schema struct { GVR GVR Preferred bool } +// Meta tracks a collection of resources. type Meta map[string][]Schema func newMeta() Meta { return make(map[string][]Schema) } +// Resources tracks dictionary of resources. var Resources = newMeta() +// Load loads resource meta from server. func Load(f types.Factory) error { dial, err := f.Client().CachedDiscovery() if err != nil { diff --git a/internal/client/revision.go b/internal/client/revision.go index b59a302e..e6d0f235 100644 --- a/internal/client/revision.go +++ b/internal/client/revision.go @@ -8,6 +8,7 @@ import ( "k8s.io/apimachinery/pkg/version" ) +// Revision tracks server version. type Revision struct { Info *version.Info Major, Minor int @@ -15,6 +16,7 @@ type Revision struct { var minorRX = regexp.MustCompile(`(\d+)\+?`) +// NewRevision returns a new instance. func NewRevision(info *version.Info) (*Revision, error) { major, err := strconv.Atoi(info.Major) if err != nil { diff --git a/internal/dag/ing.go b/internal/dag/ing.go index 67a62186..62abd7e1 100644 --- a/internal/dag/ing.go +++ b/internal/dag/ing.go @@ -12,6 +12,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" ) +// IngressGVR tracks ingress specification var IngressGVR = client.NewGVR("networking.k8s.io/v1/ingresses") // ListIngresses list all included Ingresses. diff --git a/internal/issues/codes.go b/internal/issues/codes.go index 4d52072e..3cfab90b 100644 --- a/internal/issues/codes.go +++ b/internal/issues/codes.go @@ -1,6 +1,7 @@ package issues import ( + // Pull in asset codes. _ "embed" "github.com/derailed/popeye/pkg/config" diff --git a/internal/sanitize/pdb.go b/internal/sanitize/pdb.go index e883d71b..25edaa41 100644 --- a/internal/sanitize/pdb.go +++ b/internal/sanitize/pdb.go @@ -2,14 +2,12 @@ package sanitize import ( "context" - "fmt" "github.com/derailed/popeye/internal" "github.com/derailed/popeye/internal/issues" "github.com/rs/zerolog/log" polv1beta1 "k8s.io/api/policy/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apiserver/pkg/endpoints/deprecation" ) type ( @@ -52,10 +50,7 @@ func (p *PodDisruptionBudget) Sanitize(ctx context.Context) error { } func (p *PodDisruptionBudget) checkDeprecation(ctx context.Context, pdb *polv1beta1.PodDisruptionBudget) { - const current = "policy/v1beta1" - - fmt.Println("VERSION", pdb.GetObjectKind().GroupVersionKind()) - fmt.Printf("WARNING %q", deprecation.WarningMessage(pdb)) + const current = "policy/v1" fqn := internal.MustExtractFQN(ctx) rev, err := resourceRev(fqn, "PodDisruptionBudget", pdb.Annotations) diff --git a/internal/stringset.go b/internal/stringset.go index ad6ee458..f7a8a235 100644 --- a/internal/stringset.go +++ b/internal/stringset.go @@ -15,6 +15,7 @@ type StringSet map[string]Empty // AllKeys indicates all keys are present. var AllKeys = StringSet{All: Blank} +// AddAll merges two sets. func (ss StringSet) AddAll(s StringSet) { for k := range s { ss[k] = Blank diff --git a/krew/popeye.yaml b/krew/popeye.yaml deleted file mode 100644 index 55afb6e6..00000000 --- a/krew/popeye.yaml +++ /dev/null @@ -1,59 +0,0 @@ -apiVersion: krew.googlecontainertools.github.com/v1alpha2 -kind: Plugin -metadata: - name: popeye -spec: - homepage: https://popeyecli.io - shortDescription: 🧭 A Kubernetes cluster resource sanitizer - version: v0.8.0 - description: | - Popeye is a utility that scans live Kubernetes clusters and reports - potential issues with deployed resources and configurations. - It sanitizes your cluster based on what's deployed and not what's - sitting on disk. By scanning your cluster, it detects misconfigurations - and ensure best practices are in place thus preventing potential future - headaches. It aims at reducing the cognitive overload one faces when - operating a Kubernetes cluster in the wild. Furthermore, if your - cluster employs a metric-server, it reports potential resources - over/under allocations and attempts to warn you should your cluster - run out of capacity. - - Popeye is a readonly tool, it does not alter any of your Kubernetes - resources in any way! - platforms: - - selector: - matchLabels: - os: darwin - arch: amd64 - uri: https://github.com/derailed/popeye/releases/download/v0.8.0/popeye_Darwin_x86_64.tar.gz - sha256: e5f84baafbfa7170a02c0777e0dac5e7009c19c4b487d512b8f0e21298f10484 - files: - - from: popeye - to: kubectl-popeye - - from: LICENSE - to: "." - bin: kubectl-popeye - - selector: - matchLabels: - os: linux - arch: amd64 - uri: https://github.com/derailed/popeye/releases/download/v0.8.0/popeye_Linux_x86_64.tar.gz - sha256: d4d7d776e05a0de5b681cb5421e3d9884103b902142313d8371e4f5e6b3d66dd - files: - - from: popeye - to: kubectl-popeye - - from: LICENSE - to: "." - bin: kubectl-popeye - - selector: - matchLabels: - os: windows - arch: amd64 - uri: https://github.com/derailed/popeye/releases/download/v0.8.0/popeye_Windows_x86_64.tar.gz - sha256: a743da9715abaf320d3b9391bd0cff8f914300d0cd289a733a29224fde72fea7 - files: - - from: popeye.exe - to: kubectl-popeye.exe - - from: LICENSE - to: "." - bin: kubectl-popeye.exe diff --git a/main.go b/main.go index cc5c9c51..78ea911d 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,6 @@ import ( "github.com/derailed/popeye/cmd" "github.com/derailed/popeye/pkg" - "github.com/rs/zerolog" "github.com/rs/zerolog/log" _ "k8s.io/client-go/plugin/pkg/client/auth" diff --git a/pkg/config/flags.go b/pkg/config/flags.go index ab81010f..2139030e 100644 --- a/pkg/config/flags.go +++ b/pkg/config/flags.go @@ -4,11 +4,13 @@ import ( "k8s.io/cli-runtime/pkg/genericclioptions" ) +// BasicAuth tracks basic authentication. type BasicAuth struct { User *string Password *string } +// PushGateway tracks gateway representations. type PushGateway struct { Address *string BasicAuth BasicAuth diff --git a/pkg/popeye.go b/pkg/popeye.go index 812e69ee..86e41331 100644 --- a/pkg/popeye.go +++ b/pkg/popeye.go @@ -216,9 +216,7 @@ func (p *Popeye) sanitizers(rev *client.Revision) map[string]scrubFn { "apps/v1/replicasets": scrub.NewReplicaSet, "apps/v1/statefulsets": scrub.NewStatefulSet, "autoscaling/v1/horizontalpodautoscalers": scrub.NewHorizontalPodAutoscaler, - "networking.k8s.io/v1/ingresses": scrub.NewIngress, "networking.k8s.io/v1/networkpolicies": scrub.NewNetworkPolicy, - "policy/v1beta1/poddisruptionbudgets": scrub.NewPodDisruptionBudget, "policy/v1beta1/podsecuritypolicies": scrub.NewPodSecurityPolicy, "rbac.authorization.k8s.io/v1/clusterroles": scrub.NewClusterRole, "rbac.authorization.k8s.io/v1/clusterrolebindings": scrub.NewClusterRoleBinding, @@ -228,9 +226,13 @@ func (p *Popeye) sanitizers(rev *client.Revision) map[string]scrubFn { if rev.Minor <= 18 { mm["networking.k8s.io/v1beta1/ingresses"] = scrub.NewIngress + } else { + mm["networking.k8s.io/v1/ingresses"] = scrub.NewIngress } if rev.Minor >= 21 { mm["policy/v1/poddisruptionbudgets"] = scrub.NewPodDisruptionBudget + } else { + mm["policy/v1beta1/poddisruptionbudgets"] = scrub.NewPodDisruptionBudget } return mm