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

bump kubernetes to 1.9 #187

Merged
merged 1 commit into from
Aug 20, 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
  •  
  •  
  •  
1,252 changes: 495 additions & 757 deletions Godeps/Godeps.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pkg/condition/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"k8s.io/node-problem-detector/pkg/types"
problemutil "k8s.io/node-problem-detector/pkg/util"

"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/util/clock"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/clock"

"github.com/golang/glog"
)
Expand Down Expand Up @@ -151,7 +151,7 @@ func (c *conditionManager) needHeartbeat() bool {
func (c *conditionManager) sync() {
c.latestTry = c.clock.Now()
c.resyncNeeded = false
conditions := []api.NodeCondition{}
conditions := []v1.NodeCondition{}
for i := range c.conditions {
conditions = append(conditions, problemutil.ConvertToAPICondition(c.conditions[i]))
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/condition/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
"k8s.io/node-problem-detector/pkg/types"
problemutil "k8s.io/node-problem-detector/pkg/util"

"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/util/clock"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/clock"
)

func newTestManager() (*conditionManager, *problemclient.FakeProblemClient, *clock.FakeClock) {
Expand Down Expand Up @@ -98,7 +98,7 @@ func TestResync(t *testing.T) {
condition := newTestCondition("TestCondition")
m.conditions = map[string]types.Condition{condition.Type: condition}
m.sync()
expected := []api.NodeCondition{problemutil.ConvertToAPICondition(condition)}
expected := []v1.NodeCondition{problemutil.ConvertToAPICondition(condition)}
assert.Nil(t, fakeClient.AssertConditions(expected), "Condition should be updated via client")

assert.False(t, m.needResync(), "Should not resync before resync period")
Expand All @@ -118,7 +118,7 @@ func TestHeartbeat(t *testing.T) {
condition := newTestCondition("TestCondition")
m.conditions = map[string]types.Condition{condition.Type: condition}
m.sync()
expected := []api.NodeCondition{problemutil.ConvertToAPICondition(condition)}
expected := []v1.NodeCondition{problemutil.ConvertToAPICondition(condition)}
assert.Nil(t, fakeClient.AssertConditions(expected), "Condition should be updated via client")

assert.False(t, m.needHeartbeat(), "Should not heartbeat before heartbeat period")
Expand Down
2 changes: 1 addition & 1 deletion pkg/logcounter/log_counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"
"time"

"k8s.io/kubernetes/pkg/util/clock"
"k8s.io/apimachinery/pkg/util/clock"

"k8s.io/node-problem-detector/cmd/logcounter/options"
"k8s.io/node-problem-detector/pkg/logcounter/types"
Expand Down
2 changes: 1 addition & 1 deletion pkg/logcounter/log_counter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"testing"
"time"

"k8s.io/kubernetes/pkg/util/clock"
"k8s.io/apimachinery/pkg/util/clock"

"k8s.io/node-problem-detector/pkg/logcounter/types"
"k8s.io/node-problem-detector/pkg/systemlogmonitor"
Expand Down
16 changes: 8 additions & 8 deletions pkg/problemclient/fake_problem_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
Expand All @@ -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
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
51 changes: 28 additions & 23 deletions pkg/problemclient/problem_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand All @@ -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 {
Expand All @@ -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{}) {
Expand All @@ -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
Expand All @@ -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),
Expand Down
22 changes: 11 additions & 11 deletions pkg/problemclient/problem_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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",
},
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions pkg/problemdetector/problem_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"github.com/golang/glog"

"k8s.io/kubernetes/pkg/util/clock"
"k8s.io/apimachinery/pkg/util/clock"

"k8s.io/node-problem-detector/pkg/condition"
"k8s.io/node-problem-detector/pkg/problemclient"
Expand Down Expand Up @@ -78,8 +78,8 @@ func (p *problemDetector) Run() error {
for _, event := range status.Events {
p.client.Eventf(util.ConvertToAPIEventType(event.Severity), status.Source, event.Reason, event.Message)
}
for _, condition := range status.Conditions {
p.conditionManager.UpdateCondition(condition)
for _, cdt := range status.Conditions {
p.conditionManager.UpdateCondition(cdt)
}
}
}
Expand Down
34 changes: 17 additions & 17 deletions pkg/util/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,32 @@ package util
import (
"time"

"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"k8s.io/node-problem-detector/pkg/types"
)

// ConvertToAPICondition converts the internal node condition to api.NodeCondition.
func ConvertToAPICondition(condition types.Condition) api.NodeCondition {
return api.NodeCondition{
Type: api.NodeConditionType(condition.Type),
// ConvertToAPICondition converts the internal node condition to v1.NodeCondition.
func ConvertToAPICondition(condition types.Condition) v1.NodeCondition {
return v1.NodeCondition{
Type: v1.NodeConditionType(condition.Type),
Status: ConvertToAPIConditionStatus(condition.Status),
LastTransitionTime: ConvertToAPITimestamp(condition.Transition),
Reason: condition.Reason,
Message: condition.Message,
}
}

// ConvertToAPIConditionStatus converts the internal node condition status to api.ConditionStatus.
func ConvertToAPIConditionStatus(status types.ConditionStatus) api.ConditionStatus {
// ConvertToAPIConditionStatus converts the internal node condition status to v1.ConditionStatus.
func ConvertToAPIConditionStatus(status types.ConditionStatus) v1.ConditionStatus {
switch status {
case types.True:
return api.ConditionTrue
return v1.ConditionTrue
case types.False:
return api.ConditionFalse
return v1.ConditionFalse
case types.Unknown:
return api.ConditionUnknown
return v1.ConditionUnknown
default:
panic("unknown condition status")
}
Expand All @@ -54,16 +54,16 @@ func ConvertToAPIConditionStatus(status types.ConditionStatus) api.ConditionStat
func ConvertToAPIEventType(severity types.Severity) string {
switch severity {
case types.Info:
return api.EventTypeNormal
return v1.EventTypeNormal
case types.Warn:
return api.EventTypeWarning
return v1.EventTypeWarning
default:
// Should never get here, just in case
return api.EventTypeNormal
return v1.EventTypeNormal
}
}

// ConvertToAPITimestamp converts the timestamp to unversioned.Time
func ConvertToAPITimestamp(timestamp time.Time) unversioned.Time {
return unversioned.NewTime(timestamp)
// ConvertToAPITimestamp converts the timestamp to metav1.Time
func ConvertToAPITimestamp(timestamp time.Time) metav1.Time {
return metav1.NewTime(timestamp)
}
Loading