bump kubernetes to 1.9

This commit is contained in:
Andy Xie
2018-07-09 14:59:51 +08:00
parent f479d09e58
commit 89cfb5261d
2259 changed files with 464333 additions and 732600 deletions
+8 -8
View File
@@ -21,20 +21,20 @@ import (
"reflect"
"sync"
"k8s.io/kubernetes/pkg/api"
"k8s.io/api/core/v1"
)
// FakeProblemClient is a fake problem client for debug.
type FakeProblemClient struct {
sync.Mutex
conditions map[api.NodeConditionType]api.NodeCondition
conditions map[v1.NodeConditionType]v1.NodeCondition
errors map[string]error
}
// NewFakeProblemClient creates a new fake problem client.
func NewFakeProblemClient() *FakeProblemClient {
return &FakeProblemClient{
conditions: make(map[api.NodeConditionType]api.NodeCondition),
conditions: make(map[v1.NodeConditionType]v1.NodeCondition),
errors: make(map[string]error),
}
}
@@ -48,8 +48,8 @@ func (f *FakeProblemClient) InjectError(fun string, err error) {
// AssertConditions asserts that the internal conditions in fake problem client should match
// the expected conditions.
func (f *FakeProblemClient) AssertConditions(expected []api.NodeCondition) error {
conditions := map[api.NodeConditionType]api.NodeCondition{}
func (f *FakeProblemClient) AssertConditions(expected []v1.NodeCondition) error {
conditions := map[v1.NodeConditionType]v1.NodeCondition{}
for _, condition := range expected {
conditions[condition.Type] = condition
}
@@ -60,7 +60,7 @@ func (f *FakeProblemClient) AssertConditions(expected []api.NodeCondition) error
}
// SetConditions is a fake mimic of SetConditions, it only update the internal condition cache.
func (f *FakeProblemClient) SetConditions(conditions []api.NodeCondition) error {
func (f *FakeProblemClient) SetConditions(conditions []v1.NodeCondition) error {
f.Lock()
defer f.Unlock()
if err, ok := f.errors["SetConditions"]; ok {
@@ -73,13 +73,13 @@ func (f *FakeProblemClient) SetConditions(conditions []api.NodeCondition) error
}
// GetConditions is a fake mimic of GetConditions, it returns the conditions cached internally.
func (f *FakeProblemClient) GetConditions(types []api.NodeConditionType) ([]*api.NodeCondition, error) {
func (f *FakeProblemClient) GetConditions(types []v1.NodeConditionType) ([]*v1.NodeCondition, error) {
f.Lock()
defer f.Unlock()
if err, ok := f.errors["GetConditions"]; ok {
return nil, err
}
conditions := []*api.NodeCondition{}
conditions := []*v1.NodeCondition{}
for _, t := range types {
condition, ok := f.conditions[t]
if ok {
+28 -23
View File
@@ -23,13 +23,17 @@ import (
"os"
"path/filepath"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/client/record"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util/clock"
typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/clock"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/record"
"github.com/golang/glog"
"k8s.io/heapster/common/kubernetes"
"k8s.io/node-problem-detector/cmd/options"
"k8s.io/node-problem-detector/pkg/version"
@@ -38,19 +42,19 @@ import (
// Client is the interface of problem client
type Client interface {
// GetConditions get all specifiec conditions of current node.
GetConditions(conditionTypes []api.NodeConditionType) ([]*api.NodeCondition, error)
GetConditions(conditionTypes []v1.NodeConditionType) ([]*v1.NodeCondition, error)
// SetConditions set or update conditions of current node.
SetConditions(conditions []api.NodeCondition) error
SetConditions(conditions []v1.NodeCondition) error
// Eventf reports the event.
Eventf(eventType string, source, reason, messageFmt string, args ...interface{})
}
type nodeProblemClient struct {
nodeName string
client *client.Client
client typedcorev1.CoreV1Interface
clock clock.Clock
recorders map[string]record.EventRecorder
nodeRef *api.ObjectReference
nodeRef *v1.ObjectReference
}
// NewClientOrDie creates a new problem client, panics if error occurs.
@@ -67,19 +71,19 @@ func NewClientOrDie(npdo *options.NodeProblemDetectorOptions) Client {
cfg.UserAgent = fmt.Sprintf("%s/%s", filepath.Base(os.Args[0]), version.Version())
// TODO(random-liu): Set QPS Limit
c.client = client.NewOrDie(cfg)
c.client = clientset.NewForConfigOrDie(cfg).CoreV1()
c.nodeName = npdo.NodeName
c.nodeRef = getNodeRef(c.nodeName)
c.recorders = make(map[string]record.EventRecorder)
return c
}
func (c *nodeProblemClient) GetConditions(conditionTypes []api.NodeConditionType) ([]*api.NodeCondition, error) {
node, err := c.client.Nodes().Get(c.nodeName)
func (c *nodeProblemClient) GetConditions(conditionTypes []v1.NodeConditionType) ([]*v1.NodeCondition, error) {
node, err := c.client.Nodes().Get(c.nodeName, metav1.GetOptions{})
if err != nil {
return nil, err
}
conditions := []*api.NodeCondition{}
conditions := []*v1.NodeCondition{}
for _, conditionType := range conditionTypes {
for _, condition := range node.Status.Conditions {
if condition.Type == conditionType {
@@ -90,16 +94,16 @@ func (c *nodeProblemClient) GetConditions(conditionTypes []api.NodeConditionType
return conditions, nil
}
func (c *nodeProblemClient) SetConditions(newConditions []api.NodeCondition) error {
func (c *nodeProblemClient) SetConditions(newConditions []v1.NodeCondition) error {
for i := range newConditions {
// Each time we update the conditions, we update the heart beat time
newConditions[i].LastHeartbeatTime = unversioned.NewTime(c.clock.Now())
newConditions[i].LastHeartbeatTime = metav1.NewTime(c.clock.Now())
}
patch, err := generatePatch(newConditions)
if err != nil {
return err
}
return c.client.Patch(api.StrategicMergePatchType).Resource("nodes").Name(c.nodeName).SubResource("status").Body(patch).Do().Error()
return c.client.RESTClient().Patch(types.StrategicMergePatchType).Resource("nodes").Name(c.nodeName).SubResource("status").Body(patch).Do().Error()
}
func (c *nodeProblemClient) Eventf(eventType, source, reason, messageFmt string, args ...interface{}) {
@@ -113,7 +117,7 @@ func (c *nodeProblemClient) Eventf(eventType, source, reason, messageFmt string,
}
// generatePatch generates condition patch
func generatePatch(conditions []api.NodeCondition) ([]byte, error) {
func generatePatch(conditions []v1.NodeCondition) ([]byte, error) {
raw, err := json.Marshal(&conditions)
if err != nil {
return nil, err
@@ -122,16 +126,17 @@ func generatePatch(conditions []api.NodeCondition) ([]byte, error) {
}
// getEventRecorder generates a recorder for specific node name and source.
func getEventRecorder(c *client.Client, nodeName, source string) record.EventRecorder {
func getEventRecorder(c typedcorev1.CoreV1Interface, nodeName, source string) record.EventRecorder {
eventBroadcaster := record.NewBroadcaster()
recorder := eventBroadcaster.NewRecorder(api.EventSource{Component: source, Host: nodeName})
eventBroadcaster.StartRecordingToSink(c.Events(""))
eventBroadcaster.StartLogging(glog.V(4).Infof)
recorder := eventBroadcaster.NewRecorder(legacyscheme.Scheme, v1.EventSource{Component: source, Host: nodeName})
eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: c.Events("")})
return recorder
}
func getNodeRef(nodeName string) *api.ObjectReference {
func getNodeRef(nodeName string) *v1.ObjectReference {
// TODO(random-liu): Get node to initialize the node reference
return &api.ObjectReference{
return &v1.ObjectReference{
Kind: "Node",
Name: nodeName,
UID: types.UID(nodeName),
+11 -11
View File
@@ -22,10 +22,10 @@ import (
"testing"
"time"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/client/record"
"k8s.io/kubernetes/pkg/util/clock"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/client-go/tools/record"
"github.com/stretchr/testify/assert"
)
@@ -48,18 +48,18 @@ func newFakeProblemClient() *nodeProblemClient {
func TestGeneratePatch(t *testing.T) {
now := time.Now()
update := []api.NodeCondition{
update := []v1.NodeCondition{
{
Type: "TestType1",
Status: api.ConditionTrue,
LastTransitionTime: unversioned.NewTime(now),
Status: v1.ConditionTrue,
LastTransitionTime: metav1.NewTime(now),
Reason: "TestReason1",
Message: "TestMessage1",
},
{
Type: "TestType2",
Status: api.ConditionFalse,
LastTransitionTime: unversioned.NewTime(now),
Status: v1.ConditionFalse,
LastTransitionTime: metav1.NewTime(now),
Reason: "TestReason2",
Message: "TestMessage2",
},
@@ -79,8 +79,8 @@ func TestEvent(t *testing.T) {
fakeRecorder := record.NewFakeRecorder(1)
client := newFakeProblemClient()
client.recorders[testSource] = fakeRecorder
client.Eventf(api.EventTypeWarning, testSource, "test reason", "test message")
expected := fmt.Sprintf("%s %s %s", api.EventTypeWarning, "test reason", "test message")
client.Eventf(v1.EventTypeWarning, testSource, "test reason", "test message")
expected := fmt.Sprintf("%s %s %s", v1.EventTypeWarning, "test reason", "test message")
got := <-fakeRecorder.Events
if expected != got {
t.Errorf("expected event %q, got %q", expected, got)