Kubelet file read both ContainerManifest and Pod
This commit is contained in:
@@ -25,11 +25,13 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
@@ -120,3 +122,58 @@ func tryDecodePodList(data []byte, source string, isFile bool) (parsed bool, pod
|
||||
}
|
||||
return true, *newPods, err
|
||||
}
|
||||
|
||||
func tryDecodeSingleManifest(data []byte) (parsed bool, manifest v1beta1.ContainerManifest, pod api.Pod, err error) {
|
||||
// TODO: should be api.Scheme.Decode
|
||||
// This is awful. DecodeInto() expects to find an APIObject, which
|
||||
// Manifest is not. We keep reading manifest for now for compat, but
|
||||
// we will eventually change it to read Pod (at which point this all
|
||||
// becomes nicer). Until then, we assert that the ContainerManifest
|
||||
// structure on disk is always v1beta1. Read that, convert it to a
|
||||
// "current" ContainerManifest (should be ~identical), then convert
|
||||
// that to a Pod (which is a well-understood conversion). This
|
||||
// avoids writing a v1beta1.ContainerManifest -> api.Pod
|
||||
// conversion which would be identical to the api.ContainerManifest ->
|
||||
// api.Pod conversion.
|
||||
if err = yaml.Unmarshal(data, &manifest); err != nil {
|
||||
return false, manifest, pod, err
|
||||
}
|
||||
newManifest := api.ContainerManifest{}
|
||||
if err = api.Scheme.Convert(&manifest, &newManifest); err != nil {
|
||||
return false, manifest, pod, err
|
||||
}
|
||||
if errs := validation.ValidateManifest(&newManifest); len(errs) > 0 {
|
||||
err = fmt.Errorf("invalid manifest: %v", errs)
|
||||
return false, manifest, pod, err
|
||||
}
|
||||
if err = api.Scheme.Convert(&newManifest, &pod); err != nil {
|
||||
return true, manifest, pod, err
|
||||
}
|
||||
// Success.
|
||||
return true, manifest, pod, nil
|
||||
}
|
||||
|
||||
func tryDecodeManifestList(data []byte) (parsed bool, manifests []v1beta1.ContainerManifest, pods api.PodList, err error) {
|
||||
// TODO: should be api.Scheme.Decode
|
||||
// See the comment in tryDecodeSingle().
|
||||
if err = yaml.Unmarshal(data, &manifests); err != nil {
|
||||
return false, manifests, pods, err
|
||||
}
|
||||
newManifests := []api.ContainerManifest{}
|
||||
if err = api.Scheme.Convert(&manifests, &newManifests); err != nil {
|
||||
return false, manifests, pods, err
|
||||
}
|
||||
for i := range newManifests {
|
||||
manifest := &newManifests[i]
|
||||
if errs := validation.ValidateManifest(manifest); len(errs) > 0 {
|
||||
err = fmt.Errorf("invalid manifest: %v", errs)
|
||||
return false, manifests, pods, err
|
||||
}
|
||||
}
|
||||
list := api.ContainerManifestList{Items: newManifests}
|
||||
if err = api.Scheme.Convert(&list, &pods); err != nil {
|
||||
return true, manifests, pods, err
|
||||
}
|
||||
// Success.
|
||||
return true, manifests, pods, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user