Merge pull request #539 from aledbf/migrate-client-go
Migrate to client-go
This commit is contained in:
commit
12a0373d2e
2054 changed files with 414791 additions and 223145 deletions
|
|
@ -21,8 +21,9 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
api "k8s.io/client-go/pkg/api/v1"
|
||||
)
|
||||
|
||||
// IsValidService checks if exists a service with the specified name
|
||||
|
|
@ -31,7 +32,7 @@ func IsValidService(kubeClient clientset.Interface, name string) (*api.Service,
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return kubeClient.Core().Services(ns).Get(name)
|
||||
return kubeClient.Core().Services(ns).Get(name, meta_v1.GetOptions{})
|
||||
}
|
||||
|
||||
// IsValidConfigMap check if exists a configmap with the specified name
|
||||
|
|
@ -43,7 +44,7 @@ func IsValidConfigMap(kubeClient clientset.Interface, fullName string) (*api.Con
|
|||
return nil, err
|
||||
}
|
||||
|
||||
configMap, err := kubeClient.Core().ConfigMaps(ns).Get(name)
|
||||
configMap, err := kubeClient.Core().ConfigMaps(ns).Get(name, meta_v1.GetOptions{})
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("configmap not found: %v", err)
|
||||
|
|
@ -55,7 +56,7 @@ func IsValidConfigMap(kubeClient clientset.Interface, fullName string) (*api.Con
|
|||
|
||||
// IsValidNamespace chck if exists a namespace with the specified name
|
||||
func IsValidNamespace(kubeClient clientset.Interface, name string) (*api.Namespace, error) {
|
||||
return kubeClient.Core().Namespaces().Get(name)
|
||||
return kubeClient.Core().Namespaces().Get(name, meta_v1.GetOptions{})
|
||||
}
|
||||
|
||||
// IsValidSecret checks if exists a secret with the specified name
|
||||
|
|
@ -64,7 +65,7 @@ func IsValidSecret(kubeClient clientset.Interface, name string) (*api.Secret, er
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return kubeClient.Core().Secrets(ns).Get(name)
|
||||
return kubeClient.Core().Secrets(ns).Get(name, meta_v1.GetOptions{})
|
||||
}
|
||||
|
||||
// ParseNameNS parses a string searching a namespace and name
|
||||
|
|
@ -80,7 +81,7 @@ func ParseNameNS(input string) (string, string, error) {
|
|||
// GetNodeIP returns the IP address of a node in the cluster
|
||||
func GetNodeIP(kubeClient clientset.Interface, name string) string {
|
||||
var externalIP string
|
||||
node, err := kubeClient.Core().Nodes().Get(name)
|
||||
node, err := kubeClient.Core().Nodes().Get(name, meta_v1.GetOptions{})
|
||||
if err != nil {
|
||||
return externalIP
|
||||
}
|
||||
|
|
@ -120,7 +121,7 @@ func GetPodDetails(kubeClient clientset.Interface) (*PodInfo, error) {
|
|||
return nil, fmt.Errorf("unable to get POD information (missing POD_NAME or POD_NAMESPACE environment variable")
|
||||
}
|
||||
|
||||
pod, _ := kubeClient.Core().Pods(podNs).Get(podName)
|
||||
pod, _ := kubeClient.Core().Pods(podNs).Get(podName, meta_v1.GetOptions{})
|
||||
if pod == nil {
|
||||
return nil, fmt.Errorf("unable to get POD information")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,11 +17,12 @@ limitations under the License.
|
|||
package k8s
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
testclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
|
||||
"os"
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
testclient "k8s.io/client-go/kubernetes/fake"
|
||||
api "k8s.io/client-go/pkg/api/v1"
|
||||
)
|
||||
|
||||
func TestParseNameNS(t *testing.T) {
|
||||
|
|
@ -57,7 +58,7 @@ func TestParseNameNS(t *testing.T) {
|
|||
|
||||
func TestIsValidService(t *testing.T) {
|
||||
fk := testclient.NewSimpleClientset(&api.Service{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
Namespace: api.NamespaceDefault,
|
||||
Name: "demo",
|
||||
},
|
||||
|
|
@ -88,7 +89,7 @@ func TestIsValidService(t *testing.T) {
|
|||
func TestIsValidNamespace(t *testing.T) {
|
||||
|
||||
fk := testclient.NewSimpleClientset(&api.Namespace{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
Name: "default",
|
||||
},
|
||||
})
|
||||
|
|
@ -112,7 +113,7 @@ func TestIsValidNamespace(t *testing.T) {
|
|||
func TestIsValidConfigMap(t *testing.T) {
|
||||
|
||||
fk := testclient.NewSimpleClientset(&api.ConfigMap{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
Namespace: api.NamespaceDefault,
|
||||
Name: "demo",
|
||||
},
|
||||
|
|
@ -145,7 +146,7 @@ func TestIsValidConfigMap(t *testing.T) {
|
|||
|
||||
func TestIsValidSecret(t *testing.T) {
|
||||
fk := testclient.NewSimpleClientset(&api.Secret{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
Namespace: api.NamespaceDefault,
|
||||
Name: "demo",
|
||||
},
|
||||
|
|
@ -184,7 +185,7 @@ func TestGetNodeIP(t *testing.T) {
|
|||
|
||||
// node not exist
|
||||
{testclient.NewSimpleClientset(&api.NodeList{Items: []api.Node{{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
Name: "demo",
|
||||
},
|
||||
Status: api.NodeStatus{
|
||||
|
|
@ -199,7 +200,7 @@ func TestGetNodeIP(t *testing.T) {
|
|||
|
||||
// node exist
|
||||
{testclient.NewSimpleClientset(&api.NodeList{Items: []api.Node{{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
Name: "demo",
|
||||
},
|
||||
Status: api.NodeStatus{
|
||||
|
|
@ -215,7 +216,7 @@ func TestGetNodeIP(t *testing.T) {
|
|||
// search the correct node
|
||||
{testclient.NewSimpleClientset(&api.NodeList{Items: []api.Node{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
Name: "demo1",
|
||||
},
|
||||
Status: api.NodeStatus{
|
||||
|
|
@ -228,7 +229,7 @@ func TestGetNodeIP(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
Name: "demo2",
|
||||
},
|
||||
Status: api.NodeStatus{
|
||||
|
|
@ -244,7 +245,7 @@ func TestGetNodeIP(t *testing.T) {
|
|||
|
||||
// get NodeExternalIP
|
||||
{testclient.NewSimpleClientset(&api.NodeList{Items: []api.Node{{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
Name: "demo",
|
||||
},
|
||||
Status: api.NodeStatus{
|
||||
|
|
@ -262,7 +263,7 @@ func TestGetNodeIP(t *testing.T) {
|
|||
|
||||
// get NodeLegacyHostIP
|
||||
{testclient.NewSimpleClientset(&api.NodeList{Items: []api.Node{{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
Name: "demo",
|
||||
},
|
||||
Status: api.NodeStatus{
|
||||
|
|
@ -307,7 +308,7 @@ func TestGetPodDetails(t *testing.T) {
|
|||
// success to get PodInfo
|
||||
fkClient := testclient.NewSimpleClientset(
|
||||
&api.PodList{Items: []api.Pod{{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
Name: "testpod",
|
||||
Namespace: api.NamespaceDefault,
|
||||
Labels: map[string]string{
|
||||
|
|
@ -317,7 +318,7 @@ func TestGetPodDetails(t *testing.T) {
|
|||
},
|
||||
}}},
|
||||
&api.NodeList{Items: []api.Node{{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
Name: "demo",
|
||||
},
|
||||
Status: api.NodeStatus{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue