Skip to content

Commit

Permalink
update packages
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyas-badiger committed Sep 21, 2023
1 parent 9db1009 commit 03ce779
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 93 deletions.
21 changes: 11 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ require (
github.com/spf13/cobra v0.0.7
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
k8s.io/api v0.17.17
k8s.io/apimachinery v0.17.17
k8s.io/client-go v0.17.17
k8s.io/api v0.20.15
k8s.io/apimachinery v0.20.15
k8s.io/client-go v0.20.15
)

require (
Expand All @@ -24,10 +24,11 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/evanphx/json-patch v4.9.0+incompatible // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v0.2.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gofuzz v1.0.0 // indirect
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/googleapis/gnostic v0.4.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/imdario/mergo v0.3.5 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
Expand All @@ -38,7 +39,6 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/onsi/ginkgo v1.10.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
Expand All @@ -62,8 +62,9 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog v1.0.0 // indirect
k8s.io/kube-openapi v0.0.0-20200410145947-bcb3869e6f29 // indirect
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f // indirect
sigs.k8s.io/yaml v1.1.0 // indirect
k8s.io/klog/v2 v2.4.0 // indirect
k8s.io/kube-openapi v0.0.0-20211110013926-83f114cd0513 // indirect
k8s.io/utils v0.0.0-20201110183641-67b214c5f920 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)
119 changes: 65 additions & 54 deletions go.sum

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions pkg/reaper/nodereaper/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (ctx *ReaperContext) annotateNode(nodeName, annotationKey, annotationValue

func (ctx *ReaperContext) publishEvent(namespace string, event *v1.Event) error {
log.Infof("publishing event: %v", event.Reason)
_, err := ctx.KubernetesClient.CoreV1().Events(namespace).Create(event)
_, err := ctx.KubernetesClient.CoreV1().Events(namespace).Create(context.Background(), event, metav1.CreateOptions{})
if err != nil {
log.Errorf("failed to publish event: %v", err)
return err
Expand Down Expand Up @@ -338,7 +338,7 @@ func getAutoScalingGroup(w autoscalingiface.AutoScalingAPI, name string) (autosc
}

func dumpSpec(nodeName string, kubeClient kubernetes.Interface) error {
nodeObject, err := kubeClient.CoreV1().Nodes().Get(nodeName, metav1.GetOptions{})
nodeObject, err := kubeClient.CoreV1().Nodes().Get(context.Background(), nodeName, metav1.GetOptions{})
if err != nil {
return err
}
Expand All @@ -359,7 +359,7 @@ func nodeMeetsReapAfterThreshold(minuteThreshold float64, minutesSinceTransition

func isMaster(node string, kubeClient kubernetes.Interface) (bool, error) {
corev1 := kubeClient.CoreV1()
nodeObject, err := corev1.Nodes().Get(node, metav1.GetOptions{})
nodeObject, err := corev1.Nodes().Get(context.Background(), node, metav1.GetOptions{})
if err != nil {
log.Errorf("failed to get node, %v", err)
return false, err
Expand All @@ -375,7 +375,7 @@ func getHealthyMasterCount(kubeClient kubernetes.Interface) (int, error) {
corev1 := kubeClient.CoreV1()
masterCount := 0

nodeList, err := corev1.Nodes().List(metav1.ListOptions{LabelSelector: "kubernetes.io/role=master"})
nodeList, err := corev1.Nodes().List(context.Background(), metav1.ListOptions{LabelSelector: "kubernetes.io/role=master"})
if err != nil {
log.Errorf("failed to list master nodes, %v", err)
return 0, err
Expand All @@ -391,7 +391,7 @@ func getHealthyMasterCount(kubeClient kubernetes.Interface) (int, error) {
func allNodesAreReady(kubeClient kubernetes.Interface) (bool, error) {
corev1 := kubeClient.CoreV1()

nodeList, err := corev1.Nodes().List(metav1.ListOptions{})
nodeList, err := corev1.Nodes().List(context.Background(), metav1.ListOptions{})
if err != nil {
log.Errorf("failed to list all nodes, %v", err)
return false, err
Expand Down
7 changes: 4 additions & 3 deletions pkg/reaper/nodereaper/nodereaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package nodereaper

import (
"context"
"fmt"
"os"
"reflect"
Expand Down Expand Up @@ -672,21 +673,21 @@ func (ctx *ReaperContext) scan(w ReaperAwsAuth) error {

log.Infof("Self Pod Namespace = %v", ctx.SelfNamespace)

nodeList, err := corev1.Nodes().List(metav1.ListOptions{})
nodeList, err := corev1.Nodes().List(context.Background(), metav1.ListOptions{})
if err != nil {
log.Errorf("failed to list all nodes, %v", err)
return err
}
ctx.AllNodes = nodeList.Items

podList, err := corev1.Pods("").List(metav1.ListOptions{})
podList, err := corev1.Pods("").List(context.Background(), metav1.ListOptions{})
if err != nil {
log.Errorf("failed to list all pods, %v", err)
return err
}
ctx.AllPods = podList.Items

eventList, err := corev1.Events("").List(metav1.ListOptions{FieldSelector: "involvedObject.kind=Node"})
eventList, err := corev1.Events("").List(context.Background(), metav1.ListOptions{FieldSelector: "involvedObject.kind=Node"})
if err != nil {
log.Errorf("failed to list all events, %v", err)
return err
Expand Down
9 changes: 5 additions & 4 deletions pkg/reaper/nodereaper/nodereaper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package nodereaper

import (
"context"
"flag"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -222,7 +223,7 @@ func loadFakeAPI(ctx *ReaperContext) {
namespace := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{
Name: c.namespaceName,
}}
ctx.KubernetesClient.CoreV1().Namespaces().Create(namespace)
ctx.KubernetesClient.CoreV1().Namespaces().Create(context.Background(), namespace, metav1.CreateOptions{})
}
}

Expand Down Expand Up @@ -348,7 +349,7 @@ func createFakeNodes(nodes []FakeNode, ctx *ReaperContext) {
Conditions: nodeConditions,
}}

ctx.KubernetesClient.CoreV1().Nodes().Create(node)
ctx.KubernetesClient.CoreV1().Nodes().Create(context.Background(), node, metav1.CreateOptions{})

for _, c := range fakePods {
createFakePod(c, ctx)
Expand All @@ -374,7 +375,7 @@ func createFakeEvents(events []FakeEvent, ctx *ReaperContext) {
Count: e.count,
Reason: e.reason,
}
ctx.KubernetesClient.CoreV1().Events("default").Create(fakeEvent)
ctx.KubernetesClient.CoreV1().Events("default").Create(context.Background(), fakeEvent, metav1.CreateOptions{})
}
}

Expand Down Expand Up @@ -413,7 +414,7 @@ func createFakePod(c FakePod, ctx *ReaperContext) {
}, Spec: v1.PodSpec{
NodeName: c.scheduledNode,
}}
ctx.KubernetesClient.CoreV1().Pods(c.podNamespace).Create(pod)
ctx.KubernetesClient.CoreV1().Pods(c.podNamespace).Create(context.Background(), pod, metav1.CreateOptions{})
}

func runFakeReaper(ctx *ReaperContext, awsAuth ReaperAwsAuth) {
Expand Down
13 changes: 7 additions & 6 deletions pkg/reaper/pdbreaper/pdbreaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package pdbreaper

import (
"context"
"encoding/json"
"fmt"
"reflect"
Expand Down Expand Up @@ -108,7 +109,7 @@ func (ctx *ReaperContext) scan() error {
var (
namespacedPDBs = make(map[string][]policyv1beta1.PodDisruptionBudget)
)
pdbs, err := ctx.KubernetesClient.PolicyV1beta1().PodDisruptionBudgets("").List(metav1.ListOptions{})
pdbs, err := ctx.KubernetesClient.PolicyV1beta1().PodDisruptionBudgets("").List(context.Background(), metav1.ListOptions{})
if err != nil {
return errors.Wrap(err, "failed to list PDBs")
}
Expand Down Expand Up @@ -140,8 +141,8 @@ func (ctx *ReaperContext) scan() error {
}

// if pdb is allowing disruptions, it is non-blocking
if pdb.Status.PodDisruptionsAllowed != 0 {
log.Infof("ignoring pdb %v since it is allowing %v disruptions", pdbNamespacedName(pdb), pdb.Status.PodDisruptionsAllowed)
if pdb.Status.DisruptionsAllowed != 0 {
log.Infof("ignoring pdb %v since it is allowing %v disruptions", pdbNamespacedName(pdb), pdb.Status.DisruptionsAllowed)
continue
}
// if no pods match the selector / expected, it is non-blocking
Expand Down Expand Up @@ -176,7 +177,7 @@ func (ctx *ReaperContext) handleReapableDisruptionBudgets() error {
continue
}

err = ctx.KubernetesClient.PolicyV1beta1().PodDisruptionBudgets(namespace).Delete(name, &metav1.DeleteOptions{})
err = ctx.KubernetesClient.PolicyV1beta1().PodDisruptionBudgets(namespace).Delete(context.Background(), name, metav1.DeleteOptions{})
if err != nil {
if kerrors.IsNotFound(err) {
continue
Expand Down Expand Up @@ -311,7 +312,7 @@ func (ctx *ReaperContext) handleMultipleDisruptionBudgets() error {

func (ctx *ReaperContext) listPodsWithSelector(namespace, selector string) ([]corev1.Pod, error) {
var pods []corev1.Pod
podList, err := ctx.KubernetesClient.CoreV1().Pods(namespace).List(metav1.ListOptions{LabelSelector: selector})
podList, err := ctx.KubernetesClient.CoreV1().Pods(namespace).List(context.Background(), metav1.ListOptions{LabelSelector: selector})
if err != nil {
return pods, errors.Wrapf(err, "failed to list pods with selector '%v'", selector)
}
Expand Down Expand Up @@ -346,7 +347,7 @@ func (ctx *ReaperContext) publishEvent(pdb policyv1beta1.PodDisruptionBudget, re
FirstTimestamp: metav1.NewTime(now),
LastTimestamp: metav1.NewTime(now),
}
_, err := ctx.KubernetesClient.CoreV1().Events(pdbNamespace).Create(event)
_, err := ctx.KubernetesClient.CoreV1().Events(pdbNamespace).Create(context.Background(), event, metav1.CreateOptions{})
if err != nil {
return errors.Wrap(err, "failed to publish event")
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/reaper/pdbreaper/pdbreaper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package pdbreaper

import (
"context"
"flag"
"io/ioutil"
"testing"
Expand Down Expand Up @@ -72,7 +73,7 @@ func _fakeAPI(u *ReaperUnitTest) {
namespace := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{
Name: n.Name,
}}
_, err := u.FakeReaper.KubernetesClient.CoreV1().Namespaces().Create(namespace)
_, err := u.FakeReaper.KubernetesClient.CoreV1().Namespaces().Create(context.Background(), namespace, metav1.CreateOptions{})
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -106,7 +107,7 @@ func _fakeAPI(u *ReaperUnitTest) {
}

pod.Status.StartTime = &metav1.Time{Time: time.Now().Add(time.Duration(-100) * time.Second)}
_, err := u.FakeReaper.KubernetesClient.CoreV1().Pods(p.Namespace).Create(pod)
_, err := u.FakeReaper.KubernetesClient.CoreV1().Pods(p.Namespace).Create(context.Background(), pod, metav1.CreateOptions{})
if err != nil {
panic(err)
}
Expand All @@ -124,11 +125,11 @@ func _fakeAPI(u *ReaperUnitTest) {
Selector: p.Selector,
},
Status: policyv1beta1.PodDisruptionBudgetStatus{
PodDisruptionsAllowed: p.PodDisruptionsAllowed,
DisruptionsAllowed: p.PodDisruptionsAllowed,
ExpectedPods: p.ExpectedPods,
},
}
_, err := u.FakeReaper.KubernetesClient.PolicyV1beta1().PodDisruptionBudgets(p.Namespace).Create(pdb)
_, err := u.FakeReaper.KubernetesClient.PolicyV1beta1().PodDisruptionBudgets(p.Namespace).Create(context.Background(), pdb, metav1.CreateOptions{})
if err != nil {
panic(err)
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/reaper/podreaper/podreaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package podreaper

import (
"context"
"encoding/json"
"fmt"
"sort"
Expand Down Expand Up @@ -168,11 +169,11 @@ func (ctx *ReaperContext) reapPods(pods map[string]string) error {
for pod, namespace := range pods {
log.Infof("reaping %v/%v", namespace, pod)
gracePeriod := int64(0)
forceDeleteOpts := &metav1.DeleteOptions{}
forceDeleteOpts := metav1.DeleteOptions{}
forceDeleteOpts.GracePeriodSeconds = &gracePeriod

// Dump pod json
podObject, err := corev1.Pods(namespace).Get(pod, metav1.GetOptions{})
podObject, err := corev1.Pods(namespace).Get(context.Background(), pod, metav1.GetOptions{})
if err != nil {
log.Warnf("failed to dump pod spec, %v", err)
}
Expand All @@ -185,7 +186,7 @@ func (ctx *ReaperContext) reapPods(pods map[string]string) error {
log.Infof("pod dump: %v", string(podDump))

if !ctx.DryRun {
err := corev1.Pods(namespace).Delete(pod, forceDeleteOpts)
err := corev1.Pods(namespace).Delete(context.Background(), pod, forceDeleteOpts)
if err != nil {
return err
}
Expand Down Expand Up @@ -354,13 +355,13 @@ func (ctx *ReaperContext) getPods() error {
corev1 := ctx.KubernetesClient.CoreV1()

// get pods in all namespaces
allPods, err := corev1.Pods("").List(metav1.ListOptions{})
allPods, err := corev1.Pods("").List(context.Background(), metav1.ListOptions{})
if err != nil {
return err
}
ctx.AllPods = allPods

namespaces, err := ctx.KubernetesClient.CoreV1().Namespaces().List(metav1.ListOptions{})
namespaces, err := ctx.KubernetesClient.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{})
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/reaper/podreaper/podreaper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package podreaper

import (
"context"
"flag"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -126,7 +127,7 @@ func loadFakeAPI(ctx *ReaperContext) {

// Create fake namespaces
for _, ns := range fakeNamespaces {
ctx.KubernetesClient.CoreV1().Namespaces().Create(ns)
ctx.KubernetesClient.CoreV1().Namespaces().Create(context.Background(), ns, metav1.CreateOptions{})
}
}

Expand Down Expand Up @@ -190,7 +191,7 @@ func createFakePods(pods []FakePod, ctx *ReaperContext) {
pod.Status.ContainerStatuses = append(pod.Status.ContainerStatuses, runningContainerStatus)
}

ctx.KubernetesClient.CoreV1().Pods(c.podNamespace).Create(pod)
ctx.KubernetesClient.CoreV1().Pods(c.podNamespace).Create(context.Background(), pod, metav1.CreateOptions{})
}
}

Expand Down

0 comments on commit 03ce779

Please sign in to comment.