跳到主要内容

52.context

PR #1452

Introduce a context object on RESTStorage to prepare for future changes

// UpdateAllContainers updates information about all containers.  Either called by Loop() below, or one-off.
func (p *PodCache) UpdateAllContainers() {
var ctx api.Context
pods, err := p.pods.ListPods(ctx, labels.Everything())
if err != nil {
glog.Errorf("Error synchronizing container list: %v", err)
return
}
for _, pod := range pods.Items {
err := p.updatePodInfo(pod.CurrentState.Host, pod.ID)
if err != nil && err != client.ErrPodInfoNotAvailable {
glog.Errorf("Error synchronizing container: %v", err)
}
}
}

PR #1457

Add a rate limiter, use it to rate limit docker pulls.

func (p throttledDockerPuller) Pull(image string) error {
if p.limiter.CanAccept() {
return p.puller.Pull(image)
}
return fmt.Errorf("pull QPS exceeded.")
}

PR #1465

Second step in decoupling the service controller, use the apiserver for writes too.

PR #1455

Start setting SelfLink

// Sets the SelfLink field of the object.
func (h *RESTHandler) setSelfLink(obj runtime.Object, req *http.Request) error {
newURL := *req.URL
newURL.Path = path.Join(h.canonicalPrefix, req.URL.Path)
newURL.RawQuery = ""
newURL.Fragment = ""
return h.selfLinker.SetSelfLink(obj, newURL.String())
}

PR #1475

Add GetReference()

func GetReference(obj runtime.Object) (*ObjectReference, error) {
jsonBase, err := runtime.FindJSONBase(obj)
if err != nil {
return nil, err
}
_, kind, err := Scheme.ObjectVersionAndKind(obj)
if err != nil {
return nil, err
}
version := versionFromSelfLink.FindStringSubmatch(jsonBase.SelfLink())
if len(version) < 2 {
return nil, fmt.Errorf("unexpected self link format: %v", jsonBase.SelfLink())
}
return &ObjectReference{
Kind: kind,
APIVersion: version[1],
// TODO: correct Name and UID when JSONBase makes a distinction
Name: jsonBase.ID(),
UID: jsonBase.ID(),
ResourceVersion: jsonBase.ResourceVersion(),
}, nil
}

PR #1458

Add the ability to turn off image pulling.

#469 introduced a change that makes kubelet always pull the image for a new container. This makes it impossible to run locally built images because they can't be pulled. Is this intentional?

        if !api.IsPullNever(container.ImagePullPolicy) {
present, err := kl.dockerPuller.IsImagePresent(container.Image)
if err != nil {
glog.Errorf("Failed to inspect image: %s: %#v skipping pod %s container %s", container.Image, err, podFullName, container.Name)
continue
}
if api.IsPullAlways(container.ImagePullPolicy) || !present {
if err := kl.dockerPuller.Pull(container.Image); err != nil {
glog.Errorf("Failed to pull image %s: %v skipping pod %s container %s.", container.Image, err, podFullName, container.Name)
continue
}
}
}