mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
Merge pull request #10320 from yujuhong/kubelet_logging
Kubelet: add and modify some logging messsages
This commit is contained in:
commit
9363285b4a
@ -27,6 +27,7 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
|
||||||
kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
|
kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
|
||||||
kubeletTypes "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/types"
|
kubeletTypes "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/types"
|
||||||
|
kubeletUtil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/util"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/config"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/config"
|
||||||
utilerrors "github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
|
utilerrors "github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
|
||||||
@ -186,6 +187,7 @@ func (s *podStorage) Merge(source string, change interface{}) error {
|
|||||||
|
|
||||||
// recordFirstSeenTime records the first seen time of this pod.
|
// recordFirstSeenTime records the first seen time of this pod.
|
||||||
func recordFirstSeenTime(pod *api.Pod) {
|
func recordFirstSeenTime(pod *api.Pod) {
|
||||||
|
glog.V(4).Infof("Receiving a new pod %q", kubeletUtil.FormatPodName(pod))
|
||||||
pod.Annotations[kubelet.ConfigFirstSeenAnnotationKey] = kubeletTypes.NewTimestamp().GetString()
|
pod.Annotations[kubelet.ConfigFirstSeenAnnotationKey] = kubeletTypes.NewTimestamp().GetString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/rkt"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/rkt"
|
||||||
kubeletTypes "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/types"
|
kubeletTypes "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/types"
|
||||||
|
kubeletUtil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/util"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||||
@ -1401,7 +1402,7 @@ func (kl *Kubelet) SyncPods(allPods []*api.Pod, podSyncTypes map[types.UID]SyncP
|
|||||||
// Handles pod admission.
|
// Handles pod admission.
|
||||||
pods := kl.admitPods(allPods, podSyncTypes)
|
pods := kl.admitPods(allPods, podSyncTypes)
|
||||||
|
|
||||||
glog.V(4).Infof("Desired: %#v", pods)
|
glog.V(4).Infof("Desired pods: %s", kubeletUtil.FormatPodNames(pods))
|
||||||
var err error
|
var err error
|
||||||
desiredPods := make(map[types.UID]empty)
|
desiredPods := make(map[types.UID]empty)
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
|
kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
|
||||||
kubeletTypes "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/types"
|
kubeletTypes "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/types"
|
||||||
|
kubeletUtil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/util"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
@ -125,7 +126,7 @@ func (s *statusManager) SetPodStatus(pod *api.Pod, status api.PodStatus) {
|
|||||||
s.podStatuses[podFullName] = status
|
s.podStatuses[podFullName] = status
|
||||||
s.podStatusChannel <- podStatusSyncRequest{pod, status}
|
s.podStatusChannel <- podStatusSyncRequest{pod, status}
|
||||||
} else {
|
} else {
|
||||||
glog.V(3).Infof("Ignoring same pod status for %q - old: %+v new: %+v", podFullName, oldStatus, status)
|
glog.V(3).Infof("Ignoring same status for pod %q, status: %+v", kubeletUtil.FormatPodName(pod), status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +166,7 @@ func (s *statusManager) syncBatch() error {
|
|||||||
_, err = s.kubeClient.Pods(pod.Namespace).UpdateStatus(statusPod)
|
_, err = s.kubeClient.Pods(pod.Namespace).UpdateStatus(statusPod)
|
||||||
// TODO: handle conflict as a retry, make that easier too.
|
// TODO: handle conflict as a retry, make that easier too.
|
||||||
if err == nil {
|
if err == nil {
|
||||||
glog.V(3).Infof("Status for pod %q updated successfully", pod.Name)
|
glog.V(3).Infof("Status for pod %q updated successfully", kubeletUtil.FormatPodName(pod))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,5 +179,5 @@ func (s *statusManager) syncBatch() error {
|
|||||||
// to clear the channel. Even if this delete never runs subsequent container
|
// to clear the channel. Even if this delete never runs subsequent container
|
||||||
// changes on the node should trigger updates.
|
// changes on the node should trigger updates.
|
||||||
go s.DeletePodStatus(podFullName)
|
go s.DeletePodStatus(podFullName)
|
||||||
return fmt.Errorf("error updating status for pod %q: %v", pod.Name, err)
|
return fmt.Errorf("error updating status for pod %q: %v", kubeletUtil.FormatPodName(pod), err)
|
||||||
}
|
}
|
||||||
|
18
pkg/kubelet/util/doc.go
Normal file
18
pkg/kubelet/util/doc.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Utility functions.
|
||||||
|
package util
|
44
pkg/kubelet/util/format.go
Normal file
44
pkg/kubelet/util/format.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FormatPodName returns a string representating a pod in a human readable
|
||||||
|
// format. This function currently is the same as GetPodFullName in
|
||||||
|
// kubelet/containers, but may differ in the future. As opposed to
|
||||||
|
// GetPodFullName, FormatPodName is mainly used for logging.
|
||||||
|
func FormatPodName(pod *api.Pod) string {
|
||||||
|
// Use underscore as the delimiter because it is not allowed in pod name
|
||||||
|
// (DNS subdomain format), while allowed in the container name format.
|
||||||
|
return fmt.Sprintf("%s_%s", pod.Name, pod.Namespace)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FormatPodNames returns a string representating a list of pods in a human
|
||||||
|
// readable format.
|
||||||
|
func FormatPodNames(pods []*api.Pod) string {
|
||||||
|
podStrings := make([]string, 0, len(pods))
|
||||||
|
for _, pod := range pods {
|
||||||
|
podStrings = append(podStrings, FormatPodName(pod))
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(strings.Join(podStrings, ", "))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user