Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

k8 client-go upgrade #25

Merged
merged 2 commits into from
Jan 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
4 changes: 2 additions & 2 deletions chaos/chaos.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/asobti/kube-monkey/deployments"
"github.com/asobti/kube-monkey/kubernetes"

kube "k8s.io/client-go/1.5/kubernetes"
"k8s.io/client-go/1.5/pkg/api/v1"
kube "k8s.io/client-go/kubernetes"
"k8s.io/api/core/v1"
)

type Chaos struct {
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/asobti/kube-monkey/config/param"

"k8s.io/client-go/1.5/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/sets"
)

const (
Expand Down
45 changes: 23 additions & 22 deletions deployments/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (

"github.com/asobti/kube-monkey/config"

kube "k8s.io/client-go/1.5/kubernetes"
"k8s.io/client-go/1.5/pkg/api"
"k8s.io/client-go/1.5/pkg/api/v1"
"k8s.io/client-go/1.5/pkg/apis/extensions/v1beta1"
"k8s.io/client-go/1.5/pkg/labels"
"k8s.io/client-go/1.5/pkg/selection"
"k8s.io/client-go/1.5/pkg/util/sets"
kube "k8s.io/client-go/kubernetes"

"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
"k8s.io/apimachinery/pkg/util/sets"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type Deployment struct {
Expand Down Expand Up @@ -87,10 +88,10 @@ func (d *Deployment) Mtbf() int {
}

// Returns a list of running pods for the deployment
func (d *Deployment) RunningPods(client *kube.Clientset) ([]v1.Pod, error) {
func (d *Deployment) RunningPods(clientset *kube.Clientset) ([]v1.Pod, error) {
runningPods := []v1.Pod{}

pods, err := d.Pods(client)
pods, err := d.Pods(clientset)
if err != nil {
return nil, err
}
Expand All @@ -105,56 +106,56 @@ func (d *Deployment) RunningPods(client *kube.Clientset) ([]v1.Pod, error) {
}

// Returns a list of pods under the Deployment
func (d *Deployment) Pods(client *kube.Clientset) ([]v1.Pod, error) {
func (d *Deployment) Pods(clientset *kube.Clientset) ([]v1.Pod, error) {
labelSelector, err := d.LabelFilterForPods()
if err != nil {
return nil, err
}

podlist, err := client.Core().Pods(d.namespace).List(*labelSelector)
podlist, err := clientset.Core().Pods(d.namespace).List(*labelSelector)
if err != nil {
return nil, err
}
return podlist.Items, nil
}

func (d *Deployment) DeletePod(client *kube.Clientset, podName string) error {
deleteopts := &api.DeleteOptions{
func (d *Deployment) DeletePod(clientset *kube.Clientset, podName string) error {
deleteopts := &meta_v1.DeleteOptions{
GracePeriodSeconds: config.GracePeriodSeconds(),
}

return client.Core().Pods(d.namespace).Delete(podName, deleteopts)
return clientset.Core().Pods(d.namespace).Delete(podName, deleteopts)
}

// Create a label filter to filter only for pods that belong to the this
// deployment. This is done using the identifier label
func (d *Deployment) LabelFilterForPods() (*api.ListOptions, error) {
func (d *Deployment) LabelFilterForPods() (*meta_v1.ListOptions, error) {
req, err := d.LabelRequirementForPods()
if err != nil {
return nil, err
}
labelFilter := &api.ListOptions{
LabelSelector: labels.NewSelector().Add(*req),
labelFilter := &meta_v1.ListOptions{
LabelSelector: labels.NewSelector().Add(*req).String(),
}
return labelFilter, nil
}

// Create a labels.Requirement that can be used to build a filter
func (d *Deployment) LabelRequirementForPods() (*labels.Requirement, error) {
return labels.NewRequirement(config.IdentLabelKey, selection.Equals, sets.NewString(d.identifier))
return labels.NewRequirement(config.IdentLabelKey, selection.Equals, sets.NewString(d.identifier).UnsortedList())
}

// Checks if the deployment is enrolled in kube-monkey
func (d *Deployment) IsEnrolled(client *kube.Clientset) (bool, error) {
deployment, err := client.Extensions().Deployments(d.namespace).Get(d.name)
func (d *Deployment) IsEnrolled(clientset *kube.Clientset) (bool, error) {
deployment, err := clientset.ExtensionsV1beta1().Deployments(d.namespace).Get(d.name, meta_v1.GetOptions{})
if err != nil {
return false, nil
}
return deployment.Labels[config.EnabledLabelKey] == config.EnabledLabelValue, nil
}

func (d * Deployment) HasKillAll(client *kube.Clientset) (bool, error) {
deployment, err := client.Extensions().Deployments(d.namespace).Get(d.name)
func (d * Deployment) HasKillAll(clientset *kube.Clientset) (bool, error) {
deployment, err := clientset.ExtensionsV1beta1().Deployments(d.namespace).Get(d.name, meta_v1.GetOptions{})
if err != nil {
// Ran into some error: return 'false' for killAll to be safe
return false, nil
Expand Down
22 changes: 11 additions & 11 deletions deployments/eligible_deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"github.com/asobti/kube-monkey/config"
"github.com/asobti/kube-monkey/kubernetes"

"k8s.io/client-go/1.5/pkg/api"
"k8s.io/client-go/1.5/pkg/apis/extensions/v1beta1"
"k8s.io/client-go/1.5/pkg/labels"
"k8s.io/client-go/1.5/pkg/selection"
"k8s.io/client-go/1.5/pkg/util/sets"
"k8s.io/api/extensions/v1beta1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
"k8s.io/apimachinery/pkg/util/sets"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func EligibleDeployments() ([]*Deployment, error) {
Expand Down Expand Up @@ -40,7 +40,7 @@ func EligibleDeployments() ([]*Deployment, error) {
}

func EnrolledDeployments() ([]v1beta1.Deployment, error) {
client, err := kubernetes.NewInClusterClient()
clientset, err := kubernetes.NewInClusterClient()
if err != nil {
return nil, err
}
Expand All @@ -50,23 +50,23 @@ func EnrolledDeployments() ([]v1beta1.Deployment, error) {
return nil, err
}

deployments, err := client.Extensions().Deployments(api.NamespaceAll).List(*filter)
deployments, err := clientset.ExtensionsV1beta1().Deployments(meta_v1.NamespaceAll).List(*filter)
if err != nil {
return nil, err
}
return deployments.Items, nil
}

func EnrollmentFilter() (*api.ListOptions, error) {
func EnrollmentFilter() (*meta_v1.ListOptions, error) {
req, err := EnrollmentRequirement()
if err != nil {
return nil, err
}
return &api.ListOptions{
LabelSelector: labels.NewSelector().Add(*req),
return &meta_v1.ListOptions{
LabelSelector: labels.NewSelector().Add(*req).String(),
}, nil
}

func EnrollmentRequirement() (*labels.Requirement, error) {
return labels.NewRequirement(config.EnabledLabelKey, selection.Equals, sets.NewString(config.EnabledLabelValue))
return labels.NewRequirement(config.EnabledLabelKey, selection.Equals, sets.NewString(config.EnabledLabelValue).UnsortedList())
}
Loading