Skip to content

Commit

Permalink
fix: logic referenced wrong replicasets
Browse files Browse the repository at this point in the history
  • Loading branch information
Yarel Maman committed Feb 3, 2021
1 parent 596ecaf commit 15d74c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg
cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To=
cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4=
cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M=
cloud.google.com/go v0.54.0 h1:3ithwDMr7/3vpAMXiH+ZQnYbuIsh+OPhUPMFC9enmn0=
cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc=
cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE=
Expand Down
34 changes: 16 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import (
"context"
"flag"
"fmt"
"os"
"path/filepath"

"github.com/jedib0t/go-pretty/v6/table"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
"os"
"path/filepath"

policy "k8s.io/api/policy/v1beta1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
)

type ParentResource struct {
Expand Down Expand Up @@ -61,9 +63,7 @@ func main() {
panic(fmt.Errorf("error listing PodDisruptionBudgets: %s", err.Error()))
}
if _pdbs != nil {
for _, p := range _pdbs.Items {
podDisruptionBudgets = append(podDisruptionBudgets, p)
}
podDisruptionBudgets = append(podDisruptionBudgets, _pdbs.Items...)
}
}
// Get non obsolete podDisruptionBudgets, e.g. active ones
Expand All @@ -88,24 +88,22 @@ func main() {
}
}
}
if matchingLabelsCount == len(activePDB.Spec.Selector.MatchLabels)-1 {
if matchingLabelsCount > 0 && matchingLabelsCount == len(activePDB.Spec.Selector.MatchLabels) {
for _, or := range pod.OwnerReferences {
switch or.Kind {
case "ReplicaSet":
replicaSets, err := c.AppsV1().ReplicaSets(activePDB.Namespace).List(context.TODO(), listOpts)
replicaSet, err := c.AppsV1().ReplicaSets(activePDB.Namespace).Get(context.TODO(), or.Name, meta.GetOptions{})
if err != nil {
panic(fmt.Errorf("error listing replica sets: %s", err.Error()))
panic(fmt.Errorf("error listing replica set: %s", err.Error()))
}
for _, rs := range replicaSets.Items {
for _, rsp := range getRSParents(rs.OwnerReferences, activePDB) {
parents = append(parents, ParentResource{
Namespace: activePDB.Namespace,
Name: rsp.Name,
Kind: rsp.Kind,
APIVersion: rsp.APIVersion,
PDBName: activePDB.Name,
})
}
for _, rsp := range getRSParents(replicaSet.OwnerReferences, activePDB) {
parents = append(parents, ParentResource{
Namespace: activePDB.Namespace,
Name: rsp.Name,
Kind: rsp.Kind,
APIVersion: rsp.APIVersion,
PDBName: activePDB.Name,
})
}
default:
parents = append(parents, ParentResource{
Expand Down

0 comments on commit 15d74c7

Please # to comment.