Skip to content

Commit

Permalink
fix #184 #181 #163
Browse files Browse the repository at this point in the history
  • Loading branch information
derailed committed Jul 15, 2021
1 parent 2cea939 commit 3280455
Show file tree
Hide file tree
Showing 21 changed files with 205 additions and 126 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -17,3 +17,4 @@ popeye
.vscode
.idea
spinach.yml
/kind
27 changes: 27 additions & 0 deletions change_logs/release_v0.9.4.md
@@ -0,0 +1,27 @@
<img src="https://raw.githubusercontent.com/derailed/popeye/master/assets/popeye_logo.png" align="right" width="200" height="auto"/>

# Release v0.9.4

## 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 #163](https://github.com/derailed/popeye/issues/163) popeye 0.9.0 with K8S 1.21.0 bug on PodDisruptionBudget - Wrong default API
* [Issue #712](https://github.com/derailed/popeye/pull/712) [POP-712] Found only one master node not flag on the right node
* [Issue #181](https://github.com/derailed/popeye/pull/181) [POP-404] Deprecation check failed

---

<img src="https://raw.githubusercontent.com/derailed/popeye/master/assets/imhotep_logo.png" width="32" height="auto"/>&nbsp; © 2020 Imhotep Software LLC. All materials licensed under [Apache v2.0](http://www.apache.org/licenses/LICENSE-2.0)
12 changes: 6 additions & 6 deletions go.mod
Expand Up @@ -13,10 +13,10 @@ require (
github.com/stretchr/testify v1.6.1
golang.org/x/net v0.0.0-20210224082022-3d97a244fca7
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.21.0
k8s.io/apimachinery v0.21.0
k8s.io/apiserver v0.21.0
k8s.io/cli-runtime v0.20.6
k8s.io/client-go v0.21.0
k8s.io/metrics v0.20.6
k8s.io/api v0.21.2
k8s.io/apimachinery v0.21.2
k8s.io/apiserver v0.21.2
k8s.io/cli-runtime v0.21.2
k8s.io/client-go v0.21.2
k8s.io/metrics v0.21.2
)
152 changes: 108 additions & 44 deletions go.sum

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions internal/cache/pdb.go
@@ -1,7 +1,7 @@
package cache

import (
polv1beta1 "k8s.io/api/policy/v1beta1"
polv1 "k8s.io/api/policy/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -10,21 +10,21 @@ const PodDisruptionBudgetKey = "pdb"

// PodDisruptionBudget represents PodDisruptionBudget cache.
type PodDisruptionBudget struct {
cms map[string]*polv1beta1.PodDisruptionBudget
cms map[string]*polv1.PodDisruptionBudget
}

// NewPodDisruptionBudget returns a new PodDisruptionBudget cache.
func NewPodDisruptionBudget(cms map[string]*polv1beta1.PodDisruptionBudget) *PodDisruptionBudget {
func NewPodDisruptionBudget(cms map[string]*polv1.PodDisruptionBudget) *PodDisruptionBudget {
return &PodDisruptionBudget{cms: cms}
}

// ListPodDisruptionBudgets returns all available PodDisruptionBudgets on the cluster.
func (c *PodDisruptionBudget) ListPodDisruptionBudgets() map[string]*polv1beta1.PodDisruptionBudget {
func (c *PodDisruptionBudget) ListPodDisruptionBudgets() map[string]*polv1.PodDisruptionBudget {
return c.cms
}

// ForLabels returns a pdb whose selector match the given labels. Returns nil if no match.
func (c *PodDisruptionBudget) ForLabels(labels map[string]string) *polv1beta1.PodDisruptionBudget {
func (c *PodDisruptionBudget) ForLabels(labels map[string]string) *polv1.PodDisruptionBudget {
for _, pdb := range c.ListPodDisruptionBudgets() {
m, err := metav1.LabelSelectorAsMap(pdb.Spec.Selector)
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions internal/dag/pdb.go
Expand Up @@ -6,24 +6,24 @@ import (

"github.com/derailed/popeye/internal/client"
"github.com/derailed/popeye/internal/dao"
polv1beta1 "k8s.io/api/policy/v1beta1"
polv1 "k8s.io/api/policy/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
)

// ListPodDisruptionBudgets list all included PodDisruptionBudgets.
func ListPodDisruptionBudgets(ctx context.Context) (map[string]*polv1beta1.PodDisruptionBudget, error) {
func ListPodDisruptionBudgets(ctx context.Context) (map[string]*polv1.PodDisruptionBudget, error) {
return listAllPodDisruptionBudgets(ctx)
}

// ListAllPodDisruptionBudgets fetch all PodDisruptionBudgets on the cluster.
func listAllPodDisruptionBudgets(ctx context.Context) (map[string]*polv1beta1.PodDisruptionBudget, error) {
func listAllPodDisruptionBudgets(ctx context.Context) (map[string]*polv1.PodDisruptionBudget, error) {
ll, err := fetchPodDisruptionBudgets(ctx)
if err != nil {
return nil, err
}
pdbs := make(map[string]*polv1beta1.PodDisruptionBudget, len(ll.Items))
pdbs := make(map[string]*polv1.PodDisruptionBudget, len(ll.Items))
for i := range ll.Items {
pdbs[metaFQN(ll.Items[i].ObjectMeta)] = &ll.Items[i]
}
Expand All @@ -32,14 +32,14 @@ func listAllPodDisruptionBudgets(ctx context.Context) (map[string]*polv1beta1.Po
}

// fetchPodDisruptionBudgets retrieves all PodDisruptionBudgets on the cluster.
func fetchPodDisruptionBudgets(ctx context.Context) (*polv1beta1.PodDisruptionBudgetList, error) {
func fetchPodDisruptionBudgets(ctx context.Context) (*polv1.PodDisruptionBudgetList, error) {
f, cfg := mustExtractFactory(ctx), mustExtractConfig(ctx)
if cfg.Flags.StandAlone {
dial, err := f.Client().Dial()
if err != nil {
return nil, err
}
return dial.PolicyV1beta1().PodDisruptionBudgets(f.Client().ActiveNamespace()).List(ctx, metav1.ListOptions{})
return dial.PolicyV1().PodDisruptionBudgets(f.Client().ActiveNamespace()).List(ctx, metav1.ListOptions{})
}

var res dao.Resource
Expand All @@ -48,9 +48,9 @@ func fetchPodDisruptionBudgets(ctx context.Context) (*polv1beta1.PodDisruptionBu
if err != nil {
return nil, err
}
var ll polv1beta1.PodDisruptionBudgetList
var ll polv1.PodDisruptionBudgetList
for _, o := range oo {
var pdb polv1beta1.PodDisruptionBudget
var pdb polv1.PodDisruptionBudget
err = runtime.DefaultUnstructuredConverter.FromUnstructured(o.(*unstructured.Unstructured).Object, &pdb)
if err != nil {
return nil, errors.New("expecting pdb resource")
Expand Down
14 changes: 7 additions & 7 deletions internal/dag/psp.go
Expand Up @@ -6,24 +6,24 @@ import (

"github.com/derailed/popeye/internal/client"
"github.com/derailed/popeye/internal/dao"
pv1beta1 "k8s.io/api/policy/v1beta1"
polv1beta1 "k8s.io/api/policy/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
)

// ListPodSecurityPolicies list all included PodSecurityPolicies.
func ListPodSecurityPolicies(ctx context.Context) (map[string]*pv1beta1.PodSecurityPolicy, error) {
func ListPodSecurityPolicies(ctx context.Context) (map[string]*polv1beta1.PodSecurityPolicy, error) {
return listAllPodSecurityPolicys(ctx)
}

// ListAllPodSecurityPolicys fetch all PodSecurityPolicys on the cluster.
func listAllPodSecurityPolicys(ctx context.Context) (map[string]*pv1beta1.PodSecurityPolicy, error) {
func listAllPodSecurityPolicys(ctx context.Context) (map[string]*polv1beta1.PodSecurityPolicy, error) {
ll, err := fetchPodSecurityPolicys(ctx)
if err != nil {
return nil, err
}
dps := make(map[string]*pv1beta1.PodSecurityPolicy, len(ll.Items))
dps := make(map[string]*polv1beta1.PodSecurityPolicy, len(ll.Items))
for i := range ll.Items {
dps[metaFQN(ll.Items[i].ObjectMeta)] = &ll.Items[i]
}
Expand All @@ -32,7 +32,7 @@ func listAllPodSecurityPolicys(ctx context.Context) (map[string]*pv1beta1.PodSec
}

// FetchPodSecurityPolicys retrieves all PodSecurityPolicys on the cluster.
func fetchPodSecurityPolicys(ctx context.Context) (*pv1beta1.PodSecurityPolicyList, error) {
func fetchPodSecurityPolicys(ctx context.Context) (*polv1beta1.PodSecurityPolicyList, error) {
f, cfg := mustExtractFactory(ctx), mustExtractConfig(ctx)
if cfg.Flags.StandAlone {
dial, err := f.Client().Dial()
Expand All @@ -48,9 +48,9 @@ func fetchPodSecurityPolicys(ctx context.Context) (*pv1beta1.PodSecurityPolicyLi
if err != nil {
return nil, err
}
var ll pv1beta1.PodSecurityPolicyList
var ll polv1beta1.PodSecurityPolicyList
for _, o := range oo {
var psp pv1beta1.PodSecurityPolicy
var psp polv1beta1.PodSecurityPolicy
err = runtime.DefaultUnstructuredConverter.FromUnstructured(o.(*unstructured.Unstructured).Object, &psp)
if err != nil {
return nil, errors.New("expecting configmap resource")
Expand Down
4 changes: 1 addition & 3 deletions internal/sanitize/dp.go
Expand Up @@ -74,9 +74,7 @@ func (d *Deployment) checkDeprecation(ctx context.Context, dp *appsv1.Deployment
fqn := internal.MustExtractFQN(ctx)
rev, err := resourceRev(fqn, "Deployment", dp.Annotations)
if err != nil {
rev = revFromLink(dp.SelfLink)
if rev == "" {
d.AddCode(ctx, 404, errors.New("Unable to assert resource version"))
if rev = revFromLink(dp.SelfLink); rev == "" {
return
}
}
Expand Down
5 changes: 1 addition & 4 deletions internal/sanitize/ds.go
Expand Up @@ -2,7 +2,6 @@ package sanitize

import (
"context"
"errors"

"github.com/derailed/popeye/internal"
"github.com/derailed/popeye/internal/client"
Expand Down Expand Up @@ -78,9 +77,7 @@ func (d *DaemonSet) checkDeprecation(ctx context.Context, ds *appsv1.DaemonSet)

rev, err := resourceRev(internal.MustExtractFQN(ctx), "DaemonSet", ds.Annotations)
if err != nil {
rev = revFromLink(ds.SelfLink)
if rev == "" {
d.AddCode(ctx, 404, errors.New("Unable to assert resource version"))
if rev = revFromLink(ds.SelfLink); rev == "" {
return
}
}
Expand Down
6 changes: 2 additions & 4 deletions internal/sanitize/ing.go
Expand Up @@ -2,7 +2,7 @@ package sanitize

import (
"context"
"errors"

"github.com/derailed/popeye/internal"
"github.com/derailed/popeye/internal/issues"
netv1b1 "k8s.io/api/networking/v1beta1"
Expand Down Expand Up @@ -54,9 +54,7 @@ func (i *Ingress) checkDeprecation(ctx context.Context, ing *netv1b1.Ingress) {
const current = "networking.k8s.io/v1"
rev, err := resourceRev(internal.MustExtractFQN(ctx), "Ingress", ing.Annotations)
if err != nil {
rev = revFromLink(ing.SelfLink)
if rev == "" {
i.AddCode(ctx, 404, errors.New("Unable to assert resource version"))
if rev = revFromLink(ing.SelfLink); rev == "" {
return
}
}
Expand Down
5 changes: 3 additions & 2 deletions internal/sanitize/node.go
Expand Up @@ -62,12 +62,13 @@ func (n *Node) Sanitize(ctx context.Context) error {
nodesMetrics(n.ListNodes(), n.ListNodesMetrics(), nmx)

var numMasters int

var masterCtx context.Context
for fqn, no := range n.ListNodes() {
n.InitOutcome(fqn)
ctx = internal.WithFQN(ctx, fqn)

if n.checkMasterRole(no) {
masterCtx = ctx
numMasters++
}

Expand All @@ -83,7 +84,7 @@ func (n *Node) Sanitize(ctx context.Context) error {
}

if numMasters == 1 {
n.AddCode(ctx, 712)
n.AddCode(masterCtx, 712)
}

return nil
Expand Down
5 changes: 1 addition & 4 deletions internal/sanitize/np.go
Expand Up @@ -2,7 +2,6 @@ package sanitize

import (
"context"
"errors"

"github.com/derailed/popeye/internal"
"github.com/derailed/popeye/internal/issues"
Expand Down Expand Up @@ -121,9 +120,7 @@ func (n *NetworkPolicy) checkDeprecation(ctx context.Context, np *nv1.NetworkPol

rev, err := resourceRev(internal.MustExtractFQN(ctx), "NetworkPolicy", np.Annotations)
if err != nil {
rev = revFromLink(np.SelfLink)
if rev == "" {
n.AddCode(ctx, 404, errors.New("Unable to assert resource version"))
if rev = revFromLink(np.SelfLink); rev == "" {
return
}
}
Expand Down
8 changes: 4 additions & 4 deletions internal/sanitize/pdb.go
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/derailed/popeye/internal"
"github.com/derailed/popeye/internal/issues"
"github.com/rs/zerolog/log"
polv1beta1 "k8s.io/api/policy/v1beta1"
polv1 "k8s.io/api/policy/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apiserver/pkg/endpoints/deprecation"
)
Expand All @@ -22,7 +22,7 @@ type (
// PodDisruptionBudgetLister list available PodDisruptionBudgets on a cluster.
PodDisruptionBudgetLister interface {
PodLister
ListPodDisruptionBudgets() map[string]*polv1beta1.PodDisruptionBudget
ListPodDisruptionBudgets() map[string]*polv1.PodDisruptionBudget
}
)

Expand Down Expand Up @@ -51,7 +51,7 @@ func (p *PodDisruptionBudget) Sanitize(ctx context.Context) error {
return nil
}

func (p *PodDisruptionBudget) checkDeprecation(ctx context.Context, pdb *polv1beta1.PodDisruptionBudget) {
func (p *PodDisruptionBudget) checkDeprecation(ctx context.Context, pdb *polv1.PodDisruptionBudget) {
const current = "policy/v1beta1"

fmt.Println("VERSION", pdb.GetObjectKind().GroupVersionKind())
Expand All @@ -70,7 +70,7 @@ func (p *PodDisruptionBudget) checkDeprecation(ctx context.Context, pdb *polv1be
}
}

func (p *PodDisruptionBudget) checkInUse(ctx context.Context, pdb *polv1beta1.PodDisruptionBudget) {
func (p *PodDisruptionBudget) checkInUse(ctx context.Context, pdb *polv1.PodDisruptionBudget) {
m, err := metav1.LabelSelectorAsMap(pdb.Spec.Selector)
if err != nil {
log.Error().Err(err).Msg("No selectors found")
Expand Down
12 changes: 6 additions & 6 deletions internal/sanitize/pdb_test.go
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/derailed/popeye/internal/issues"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
polv1beta1 "k8s.io/api/policy/v1beta1"
polv1 "k8s.io/api/policy/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
Expand Down Expand Up @@ -65,8 +65,8 @@ func makePDBLister(opts pdbOpts) *pdb {
}
}

func (r *pdb) ListPodDisruptionBudgets() map[string]*polv1beta1.PodDisruptionBudget {
return map[string]*polv1beta1.PodDisruptionBudget{
func (r *pdb) ListPodDisruptionBudgets() map[string]*polv1.PodDisruptionBudget {
return map[string]*polv1.PodDisruptionBudget{
cache.FQN("default", r.name): makePDB(r.name),
}
}
Expand All @@ -84,14 +84,14 @@ func (r *pdb) GetPod(ns string, sel map[string]string) *v1.Pod {
return makePod("p1")
}

func makePDB(n string) *polv1beta1.PodDisruptionBudget {
func makePDB(n string) *polv1.PodDisruptionBudget {
min, max := intstr.FromInt(1), intstr.FromInt(1)
return &polv1beta1.PodDisruptionBudget{
return &polv1.PodDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{
Name: n,
Namespace: "default",
},
Spec: polv1beta1.PodDisruptionBudgetSpec{
Spec: polv1.PodDisruptionBudgetSpec{
Selector: &metav1.LabelSelector{},
MinAvailable: &min,
MaxUnavailable: &max,
Expand Down
6 changes: 3 additions & 3 deletions internal/sanitize/pod.go
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/derailed/popeye/internal/client"
"github.com/derailed/popeye/internal/issues"
v1 "k8s.io/api/core/v1"
polv1beta1 "k8s.io/api/policy/v1beta1"
polv1 "k8s.io/api/policy/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
mv1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1"
)
Expand All @@ -34,8 +34,8 @@ type (

// PdbLister list pdb matching a given selector
PdbLister interface {
ListPodDisruptionBudgets() map[string]*polv1beta1.PodDisruptionBudget
ForLabels(labels map[string]string) *polv1beta1.PodDisruptionBudget
ListPodDisruptionBudgets() map[string]*polv1.PodDisruptionBudget
ForLabels(labels map[string]string) *polv1.PodDisruptionBudget
}

// PodLister lists available pods.
Expand Down

0 comments on commit 3280455

Please sign in to comment.