Create selfLink for pods from config files and indicate hostname as part of event source.

This commit is contained in:
Dawn Chen 2015-01-05 11:03:51 -08:00
parent 3a4d5fd6a2
commit 2b91c1417c
4 changed files with 13 additions and 3 deletions

View File

@ -193,7 +193,7 @@ var replicationControllerColumns = []string{"CONTROLLER", "CONTAINER(S)", "IMAGE
var serviceColumns = []string{"NAME", "LABELS", "SELECTOR", "IP", "PORT"} var serviceColumns = []string{"NAME", "LABELS", "SELECTOR", "IP", "PORT"}
var minionColumns = []string{"NAME", "LABELS"} var minionColumns = []string{"NAME", "LABELS"}
var statusColumns = []string{"STATUS"} var statusColumns = []string{"STATUS"}
var eventColumns = []string{"TIME", "NAME", "KIND", "SUBOBJECT", "CONDITION", "REASON", "MESSAGE"} var eventColumns = []string{"TIME", "NAME", "KIND", "SUBOBJECT", "CONDITION", "REASON", "SOURCE", "MESSAGE"}
// addDefaultHandlers adds print handlers for default Kubernetes types. // addDefaultHandlers adds print handlers for default Kubernetes types.
func (h *HumanReadablePrinter) addDefaultHandlers() { func (h *HumanReadablePrinter) addDefaultHandlers() {
@ -339,13 +339,14 @@ func printStatus(status *api.Status, w io.Writer) error {
func printEvent(event *api.Event, w io.Writer) error { func printEvent(event *api.Event, w io.Writer) error {
_, err := fmt.Fprintf( _, err := fmt.Fprintf(
w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n", w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
event.Timestamp.Time.Format(time.RFC1123Z), event.Timestamp.Time.Format(time.RFC1123Z),
event.InvolvedObject.Name, event.InvolvedObject.Name,
event.InvolvedObject.Kind, event.InvolvedObject.Kind,
event.InvolvedObject.FieldPath, event.InvolvedObject.FieldPath,
event.Condition, event.Condition,
event.Reason, event.Reason,
event.Source,
event.Message, event.Message,
) )
return err return err

View File

@ -159,6 +159,11 @@ func extractFromFile(filename string) (api.BoundPod, error) {
if len(pod.Namespace) == 0 { if len(pod.Namespace) == 0 {
pod.Namespace = api.NamespaceDefault pod.Namespace = api.NamespaceDefault
} }
// TODO(dchen1107): BoundPod is not type of runtime.Object. Once we allow kubelet talks
// about Pod directly, we can use SelfLinker defined in package: latest
// Currently just simply follow the same format in resthandler.go
pod.ObjectMeta.SelfLink = fmt.Sprintf("/api/v1beta2/pods/%s?namespace=%s",
pod.Name, pod.Namespace)
if glog.V(4) { if glog.V(4) {
glog.Infof("Got pod from file %q: %#v", filename, pod) glog.Infof("Got pod from file %q: %#v", filename, pod)

View File

@ -124,6 +124,7 @@ func TestReadFromFile(t *testing.T) {
Name: "test", Name: "test",
UID: simpleSubdomainSafeHash(file.Name()), UID: simpleSubdomainSafeHash(file.Name()),
Namespace: "default", Namespace: "default",
SelfLink: "/api/v1beta2/pods/test?namespace=default",
}, },
Spec: api.PodSpec{ Spec: api.PodSpec{
Containers: []api.Container{{Image: "test/image", TerminationMessagePath: "/dev/termination-log"}}, Containers: []api.Container{{Image: "test/image", TerminationMessagePath: "/dev/termination-log"}},
@ -161,6 +162,7 @@ func TestExtractFromValidDataFile(t *testing.T) {
file := writeTestFile(t, os.TempDir(), "test_pod_config", string(text)) file := writeTestFile(t, os.TempDir(), "test_pod_config", string(text))
defer os.Remove(file.Name()) defer os.Remove(file.Name())
expectedPod.ObjectMeta.SelfLink = "/api/v1beta2/pods/" + expectedPod.Name + "?namespace=default"
ch := make(chan interface{}, 1) ch := make(chan interface{}, 1)
c := sourceFile{file.Name(), ch} c := sourceFile{file.Name(), ch}
err = c.extractFromPath() err = c.extractFromPath()
@ -226,6 +228,7 @@ func TestExtractFromDir(t *testing.T) {
} }
ioutil.WriteFile(name, data, 0755) ioutil.WriteFile(name, data, 0755)
files[i] = file files[i] = file
pods[i].ObjectMeta.SelfLink = "/api/v1beta2/pods/" + pods[i].Name + "?namespace=default"
} }
ch := make(chan interface{}, 1) ch := make(chan interface{}, 1)

View File

@ -130,8 +130,9 @@ func SetupEventSending(authPath string, apiServerList util.StringList) {
glog.Errorf("Unable to make apiserver client: %v", err) glog.Errorf("Unable to make apiserver client: %v", err)
} else { } else {
// Send events to APIserver if there is a client. // Send events to APIserver if there is a client.
hostname := util.GetHostname("")
glog.Infof("Sending events to APIserver.") glog.Infof("Sending events to APIserver.")
record.StartRecording(apiClient.Events(""), "kubelet") record.StartRecording(apiClient.Events(""), "kubelet:"+hostname)
} }
} }
} }