Update k8s client version to 4.0.0 (#351)
Move to client-go v4.0.0 from 1.5.
This commit is contained in:
committed by
Soam Vasani
parent
e4d42797e6
commit
a25c167d23
+16
-17
@@ -19,7 +19,6 @@ package kubewatcher
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
@@ -28,13 +27,13 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"k8s.io/client-go/1.5/kubernetes"
|
||||
"k8s.io/client-go/1.5/pkg/api"
|
||||
apierrs "k8s.io/client-go/1.5/pkg/api/errors"
|
||||
"k8s.io/client-go/1.5/pkg/api/meta"
|
||||
"k8s.io/client-go/1.5/pkg/runtime"
|
||||
"k8s.io/client-go/1.5/pkg/types"
|
||||
"k8s.io/client-go/1.5/pkg/watch"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
|
||||
"github.com/fission/fission"
|
||||
"github.com/fission/fission/publisher"
|
||||
@@ -152,7 +151,7 @@ func createKubernetesWatch(kubeClient *kubernetes.Clientset, w *tpr.Kuberneteswa
|
||||
var watchTimeoutSec int64 = 120
|
||||
|
||||
// TODO populate labelselector and fieldselector
|
||||
listOptions := api.ListOptions{
|
||||
listOptions := metav1.ListOptions{
|
||||
ResourceVersion: resourceVersion,
|
||||
TimeoutSeconds: &watchTimeoutSec,
|
||||
}
|
||||
@@ -160,17 +159,17 @@ func createKubernetesWatch(kubeClient *kubernetes.Clientset, w *tpr.Kuberneteswa
|
||||
// TODO handle the full list of types
|
||||
switch strings.ToUpper(w.Spec.Type) {
|
||||
case "POD":
|
||||
wi, err = kubeClient.Core().Pods(w.Spec.Namespace).Watch(listOptions)
|
||||
wi, err = kubeClient.CoreV1().Pods(w.Spec.Namespace).Watch(listOptions)
|
||||
case "SERVICE":
|
||||
wi, err = kubeClient.Core().Services(w.Spec.Namespace).Watch(listOptions)
|
||||
wi, err = kubeClient.CoreV1().Services(w.Spec.Namespace).Watch(listOptions)
|
||||
case "REPLICATIONCONTROLLER":
|
||||
wi, err = kubeClient.Core().ReplicationControllers(w.Spec.Namespace).Watch(listOptions)
|
||||
wi, err = kubeClient.CoreV1().ReplicationControllers(w.Spec.Namespace).Watch(listOptions)
|
||||
case "JOB":
|
||||
wi, err = kubeClient.Batch().Jobs(w.Spec.Namespace).Watch(listOptions)
|
||||
wi, err = kubeClient.BatchV1().Jobs(w.Spec.Namespace).Watch(listOptions)
|
||||
default:
|
||||
msg := fmt.Sprintf("Error: unknown obj type '%v'", w.Spec.Type)
|
||||
log.Println(msg)
|
||||
err = errors.New(msg)
|
||||
err = errors.NewBadRequest(msg)
|
||||
}
|
||||
return wi, err
|
||||
}
|
||||
@@ -253,11 +252,11 @@ func (ws *watchSubscription) restartWatch() error {
|
||||
}
|
||||
|
||||
func getResourceVersion(obj runtime.Object) (string, error) {
|
||||
meta, err := meta.Accessor(obj)
|
||||
m, err := meta.Accessor(obj)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return meta.GetResourceVersion(), nil
|
||||
return m.GetResourceVersion(), nil
|
||||
}
|
||||
|
||||
func (ws *watchSubscription) eventDispatchLoop() {
|
||||
@@ -288,7 +287,7 @@ func (ws *watchSubscription) eventDispatchLoop() {
|
||||
}
|
||||
|
||||
if ev.Type == watch.Error {
|
||||
e := apierrs.FromObject(ev.Object)
|
||||
e := errors.FromObject(ev.Object)
|
||||
log.Println("Watch error, retrying in a second: %v", e)
|
||||
// Start from the beginning to get around "too old resource version"
|
||||
ws.lastResourceVersion = ""
|
||||
|
||||
Reference in New Issue
Block a user