mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-02 19:28:16 +00:00
replacing handwritten client in several controllers
This commit is contained in:
@@ -22,7 +22,7 @@ import (
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/release_1_1"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
labelsutil "k8s.io/kubernetes/pkg/util/labels"
|
||||
podutil "k8s.io/kubernetes/pkg/util/pod"
|
||||
@@ -35,20 +35,20 @@ const (
|
||||
|
||||
// GetOldRCs returns the old RCs targeted by the given Deployment; get PodList and RCList from client interface.
|
||||
// Note that the first set of old RCs doesn't include the ones with no pods, and the second set of old RCs include all old RCs.
|
||||
func GetOldRCs(deployment extensions.Deployment, c client.Interface) ([]*api.ReplicationController, []*api.ReplicationController, error) {
|
||||
func GetOldRCs(deployment extensions.Deployment, c clientset.Interface) ([]*api.ReplicationController, []*api.ReplicationController, error) {
|
||||
return GetOldRCsFromLists(deployment, c,
|
||||
func(namespace string, options api.ListOptions) (*api.PodList, error) {
|
||||
return c.Pods(namespace).List(options)
|
||||
return c.Legacy().Pods(namespace).List(options)
|
||||
},
|
||||
func(namespace string, options api.ListOptions) ([]api.ReplicationController, error) {
|
||||
rcList, err := c.ReplicationControllers(namespace).List(options)
|
||||
rcList, err := c.Legacy().ReplicationControllers(namespace).List(options)
|
||||
return rcList.Items, err
|
||||
})
|
||||
}
|
||||
|
||||
// GetOldRCsFromLists returns two sets of old RCs targeted by the given Deployment; get PodList and RCList with input functions.
|
||||
// Note that the first set of old RCs doesn't include the ones with no pods, and the second set of old RCs include all old RCs.
|
||||
func GetOldRCsFromLists(deployment extensions.Deployment, c client.Interface, getPodList func(string, api.ListOptions) (*api.PodList, error), getRcList func(string, api.ListOptions) ([]api.ReplicationController, error)) ([]*api.ReplicationController, []*api.ReplicationController, error) {
|
||||
func GetOldRCsFromLists(deployment extensions.Deployment, c clientset.Interface, getPodList func(string, api.ListOptions) (*api.PodList, error), getRcList func(string, api.ListOptions) ([]api.ReplicationController, error)) ([]*api.ReplicationController, []*api.ReplicationController, error) {
|
||||
namespace := deployment.ObjectMeta.Namespace
|
||||
// 1. Find all pods whose labels match deployment.Spec.Selector
|
||||
selector := labels.SelectorFromSet(deployment.Spec.Selector)
|
||||
@@ -95,17 +95,17 @@ func GetOldRCsFromLists(deployment extensions.Deployment, c client.Interface, ge
|
||||
|
||||
// GetNewRC returns an RC that matches the intent of the given deployment; get RCList from client interface.
|
||||
// Returns nil if the new RC doesnt exist yet.
|
||||
func GetNewRC(deployment extensions.Deployment, c client.Interface) (*api.ReplicationController, error) {
|
||||
func GetNewRC(deployment extensions.Deployment, c clientset.Interface) (*api.ReplicationController, error) {
|
||||
return GetNewRCFromList(deployment, c,
|
||||
func(namespace string, options api.ListOptions) ([]api.ReplicationController, error) {
|
||||
rcList, err := c.ReplicationControllers(namespace).List(options)
|
||||
rcList, err := c.Legacy().ReplicationControllers(namespace).List(options)
|
||||
return rcList.Items, err
|
||||
})
|
||||
}
|
||||
|
||||
// GetNewRCFromList returns an RC that matches the intent of the given deployment; get RCList with the input function.
|
||||
// Returns nil if the new RC doesnt exist yet.
|
||||
func GetNewRCFromList(deployment extensions.Deployment, c client.Interface, getRcList func(string, api.ListOptions) ([]api.ReplicationController, error)) (*api.ReplicationController, error) {
|
||||
func GetNewRCFromList(deployment extensions.Deployment, c clientset.Interface, getRcList func(string, api.ListOptions) ([]api.ReplicationController, error)) (*api.ReplicationController, error) {
|
||||
namespace := deployment.ObjectMeta.Namespace
|
||||
rcList, err := getRcList(namespace, api.ListOptions{LabelSelector: labels.SelectorFromSet(deployment.Spec.Selector)})
|
||||
if err != nil {
|
||||
@@ -157,7 +157,7 @@ func GetReplicaCountForRCs(replicationControllers []*api.ReplicationController)
|
||||
}
|
||||
|
||||
// Returns the number of available pods corresponding to the given RCs.
|
||||
func GetAvailablePodsForRCs(c client.Interface, rcs []*api.ReplicationController, minReadySeconds int) (int, error) {
|
||||
func GetAvailablePodsForRCs(c clientset.Interface, rcs []*api.ReplicationController, minReadySeconds int) (int, error) {
|
||||
allPods, err := getPodsForRCs(c, rcs)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -189,12 +189,12 @@ func getReadyPodsCount(pods []api.Pod, minReadySeconds int) int {
|
||||
return readyPodCount
|
||||
}
|
||||
|
||||
func getPodsForRCs(c client.Interface, replicationControllers []*api.ReplicationController) ([]api.Pod, error) {
|
||||
func getPodsForRCs(c clientset.Interface, replicationControllers []*api.ReplicationController) ([]api.Pod, error) {
|
||||
allPods := []api.Pod{}
|
||||
for _, rc := range replicationControllers {
|
||||
selector := labels.SelectorFromSet(rc.Spec.Selector)
|
||||
options := api.ListOptions{LabelSelector: selector}
|
||||
podList, err := c.Pods(rc.ObjectMeta.Namespace).List(options)
|
||||
podList, err := c.Legacy().Pods(rc.ObjectMeta.Namespace).List(options)
|
||||
if err != nil {
|
||||
return allPods, fmt.Errorf("error listing pods: %v", err)
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||
"k8s.io/kubernetes/pkg/client/testing/fake"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient/simple"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
@@ -231,7 +231,7 @@ func TestGetNewRC(t *testing.T) {
|
||||
Body: &test.rcList,
|
||||
},
|
||||
}
|
||||
rc, err := GetNewRC(newDeployment, c.Setup(t))
|
||||
rc, err := GetNewRC(newDeployment, c.Setup(t).Clientset)
|
||||
if err != nil {
|
||||
t.Errorf("In test case %s, got unexpected error %v", test.test, err)
|
||||
}
|
||||
@@ -314,7 +314,7 @@ func TestGetOldRCs(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
rcs, _, err := GetOldRCs(newDeployment, testclient.NewSimpleFake(test.objs...))
|
||||
rcs, _, err := GetOldRCs(newDeployment, fake.NewSimpleClientset(test.objs...))
|
||||
if err != nil {
|
||||
t.Errorf("In test case %s, got unexpected error %v", test.test, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user