mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
Make kubelet's file source go through conversion
See comments for details. Same problem exists in HTTP source, but I want to float this for review first.
This commit is contained in:
parent
ffb2b62726
commit
4ff2865cd1
@ -29,6 +29,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
@ -145,13 +146,26 @@ func extractFromFile(filename string) (api.BoundPod, error) {
|
||||
return pod, err
|
||||
}
|
||||
|
||||
manifest := &api.ContainerManifest{}
|
||||
// TODO: use api.Scheme.DecodeInto
|
||||
if err := yaml.Unmarshal(data, manifest); err != nil {
|
||||
// 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 BoundPod (which is a well-understood conversion). This
|
||||
// avoids writing a v1beta1.ContainerManifest -> api.BoundPod
|
||||
// conversion which would be identical to the api.ContainerManifest ->
|
||||
// api.BoundPod conversion.
|
||||
oldManifest := &v1beta1.ContainerManifest{}
|
||||
if err := yaml.Unmarshal(data, oldManifest); err != nil {
|
||||
return pod, fmt.Errorf("can't unmarshal file %q: %v", filename, err)
|
||||
}
|
||||
|
||||
if err := api.Scheme.Convert(manifest, &pod); err != nil {
|
||||
newManifest := &api.ContainerManifest{}
|
||||
if err := api.Scheme.Convert(oldManifest, newManifest); err != nil {
|
||||
return pod, fmt.Errorf("can't convert pod from file %q: %v", filename, err)
|
||||
}
|
||||
if err := api.Scheme.Convert(newManifest, &pod); err != nil {
|
||||
return pod, fmt.Errorf("can't convert pod from file %q: %v", filename, err)
|
||||
}
|
||||
|
||||
|
@ -26,27 +26,28 @@ import (
|
||||
"time"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
func ExampleManifestAndPod(id string) (api.ContainerManifest, api.BoundPod) {
|
||||
manifest := api.ContainerManifest{
|
||||
func ExampleManifestAndPod(id string) (v1beta1.ContainerManifest, api.BoundPod) {
|
||||
manifest := v1beta1.ContainerManifest{
|
||||
ID: id,
|
||||
UUID: types.UID(id),
|
||||
Containers: []api.Container{
|
||||
Containers: []v1beta1.Container{
|
||||
{
|
||||
Name: "c" + id,
|
||||
Image: "foo",
|
||||
TerminationMessagePath: "/somepath",
|
||||
},
|
||||
},
|
||||
Volumes: []api.Volume{
|
||||
Volumes: []v1beta1.Volume{
|
||||
{
|
||||
Name: "host-dir",
|
||||
Source: api.VolumeSource{
|
||||
HostPath: &api.HostPath{"/dir/path"},
|
||||
Source: v1beta1.VolumeSource{
|
||||
HostDir: &v1beta1.HostPath{"/dir/path"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -120,7 +121,7 @@ func TestReadFromFile(t *testing.T) {
|
||||
"version": "v1beta1",
|
||||
"uuid": "12345",
|
||||
"id": "test",
|
||||
"containers": [{ "image": "test/image" }]
|
||||
"containers": [{ "image": "test/image", imagePullPolicy: "PullAlways"}]
|
||||
}`)
|
||||
defer os.Remove(file.Name())
|
||||
|
||||
@ -137,7 +138,13 @@ func TestReadFromFile(t *testing.T) {
|
||||
SelfLink: "",
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{{Image: "test/image", TerminationMessagePath: "/dev/termination-log"}},
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "test/image",
|
||||
TerminationMessagePath: "/dev/termination-log",
|
||||
ImagePullPolicy: api.PullAlways,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
@ -224,7 +231,7 @@ func TestExtractFromDir(t *testing.T) {
|
||||
manifest, expectedPod := ExampleManifestAndPod("1")
|
||||
manifest2, expectedPod2 := ExampleManifestAndPod("2")
|
||||
|
||||
manifests := []api.ContainerManifest{manifest, manifest2}
|
||||
manifests := []v1beta1.ContainerManifest{manifest, manifest2}
|
||||
pods := []api.BoundPod{expectedPod, expectedPod2}
|
||||
files := make([]*os.File, len(manifests))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user