From 2b91c1417c4acb5cdfbd235671ffa738a0252555 Mon Sep 17 00:00:00 2001 From: Dawn Chen Date: Mon, 5 Jan 2015 11:03:51 -0800 Subject: [PATCH] Create selfLink for pods from config files and indicate hostname as part of event source. --- pkg/kubectl/resource_printer.go | 5 +++-- pkg/kubelet/config/file.go | 5 +++++ pkg/kubelet/config/file_test.go | 3 +++ pkg/kubelet/util.go | 3 ++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/kubectl/resource_printer.go b/pkg/kubectl/resource_printer.go index e05b2c42be0..60d28933b5e 100644 --- a/pkg/kubectl/resource_printer.go +++ b/pkg/kubectl/resource_printer.go @@ -193,7 +193,7 @@ var replicationControllerColumns = []string{"CONTROLLER", "CONTAINER(S)", "IMAGE var serviceColumns = []string{"NAME", "LABELS", "SELECTOR", "IP", "PORT"} var minionColumns = []string{"NAME", "LABELS"} 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. 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 { _, 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.InvolvedObject.Name, event.InvolvedObject.Kind, event.InvolvedObject.FieldPath, event.Condition, event.Reason, + event.Source, event.Message, ) return err diff --git a/pkg/kubelet/config/file.go b/pkg/kubelet/config/file.go index fd08fced3ff..84667dad592 100644 --- a/pkg/kubelet/config/file.go +++ b/pkg/kubelet/config/file.go @@ -159,6 +159,11 @@ func extractFromFile(filename string) (api.BoundPod, error) { if len(pod.Namespace) == 0 { 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) { glog.Infof("Got pod from file %q: %#v", filename, pod) diff --git a/pkg/kubelet/config/file_test.go b/pkg/kubelet/config/file_test.go index 22d48e703dd..135bdea5467 100644 --- a/pkg/kubelet/config/file_test.go +++ b/pkg/kubelet/config/file_test.go @@ -124,6 +124,7 @@ func TestReadFromFile(t *testing.T) { Name: "test", UID: simpleSubdomainSafeHash(file.Name()), Namespace: "default", + SelfLink: "/api/v1beta2/pods/test?namespace=default", }, Spec: api.PodSpec{ 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)) defer os.Remove(file.Name()) + expectedPod.ObjectMeta.SelfLink = "/api/v1beta2/pods/" + expectedPod.Name + "?namespace=default" ch := make(chan interface{}, 1) c := sourceFile{file.Name(), ch} err = c.extractFromPath() @@ -226,6 +228,7 @@ func TestExtractFromDir(t *testing.T) { } ioutil.WriteFile(name, data, 0755) files[i] = file + pods[i].ObjectMeta.SelfLink = "/api/v1beta2/pods/" + pods[i].Name + "?namespace=default" } ch := make(chan interface{}, 1) diff --git a/pkg/kubelet/util.go b/pkg/kubelet/util.go index fdb6b4afd6f..5a400df46d3 100644 --- a/pkg/kubelet/util.go +++ b/pkg/kubelet/util.go @@ -130,8 +130,9 @@ func SetupEventSending(authPath string, apiServerList util.StringList) { glog.Errorf("Unable to make apiserver client: %v", err) } else { // Send events to APIserver if there is a client. + hostname := util.GetHostname("") glog.Infof("Sending events to APIserver.") - record.StartRecording(apiClient.Events(""), "kubelet") + record.StartRecording(apiClient.Events(""), "kubelet:"+hostname) } } }