Change route controller to use patch to set node condition.

This commit is contained in:
Random-Liu
2016-07-10 19:32:58 -07:00
parent d4df168186
commit 59ea5c088b
2 changed files with 38 additions and 39 deletions

View File

@@ -17,14 +17,17 @@ limitations under the License.
package node
import (
"encoding/json"
"fmt"
"net"
"os/exec"
"strings"
"time"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
)
func GetHostname(hostnameOverride string) string {
@@ -81,3 +84,21 @@ func GetZoneKey(node *api.Node) string {
// As a nice side-benefit, the null character is not printed by fmt.Print or glog
return region + ":\x00:" + failureDomain
}
// SetNodeCondition updates specific node condition with patch operation.
func SetNodeCondition(c clientset.Interface, node string, condition api.NodeCondition) error {
generatePatch := func(condition api.NodeCondition) ([]byte, error) {
raw, err := json.Marshal(&[]api.NodeCondition{condition})
if err != nil {
return nil, err
}
return []byte(fmt.Sprintf(`{"status":{"conditions":%s}}`, raw)), nil
}
condition.LastHeartbeatTime = unversioned.NewTime(time.Now())
patch, err := generatePatch(condition)
if err != nil {
return nil
}
_, err = c.Core().Nodes().PatchStatus(node, patch)
return err
}