forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conversion.go
112 lines (104 loc) · 3.86 KB
/
conversion.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package api
import (
"github.com/fsouza/go-dockerclient"
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)
func init() {
err := kapi.Scheme.AddConversionFuncs(
// Convert docker client object to internal object
func(in *docker.Image, out *DockerImage, s conversion.Scope) error {
if err := s.Convert(in.Config, &out.Config, conversion.AllowDifferentFieldTypeNames); err != nil {
return err
}
if err := s.Convert(&in.ContainerConfig, &out.ContainerConfig, conversion.AllowDifferentFieldTypeNames); err != nil {
return err
}
out.ID = in.ID
out.Parent = in.Parent
out.Comment = in.Comment
out.Created = util.NewTime(in.Created)
out.Container = in.Container
out.DockerVersion = in.DockerVersion
out.Author = in.Author
out.Architecture = in.Architecture
out.Size = in.Size
return nil
},
func(in *DockerImage, out *docker.Image, s conversion.Scope) error {
if err := s.Convert(&in.Config, &out.Config, conversion.AllowDifferentFieldTypeNames); err != nil {
return err
}
if err := s.Convert(&in.ContainerConfig, &out.ContainerConfig, conversion.AllowDifferentFieldTypeNames); err != nil {
return err
}
out.ID = in.ID
out.Parent = in.Parent
out.Comment = in.Comment
out.Created = in.Created.Time
out.Container = in.Container
out.DockerVersion = in.DockerVersion
out.Author = in.Author
out.Architecture = in.Architecture
out.Size = in.Size
return nil
},
func(in *ImageStream, out *ImageRepository, s conversion.Scope) error {
if err := s.Convert(&in.ObjectMeta, &out.ObjectMeta, 0); err != nil {
return err
}
out.DockerImageRepository = in.Spec.DockerImageRepository
if in.Spec.Tags != nil && out.Tags == nil {
out.Tags = make(map[string]string)
}
for tag, tagRef := range in.Spec.Tags {
value := tagRef.DockerImageReference
if len(value) == 0 && tagRef.From != nil && len(tagRef.From.Kind) == 0 {
value = tagRef.From.Name
}
out.Tags[tag] = value
}
return s.Convert(&in.Status, &out.Status, 0)
},
func(in *ImageRepository, out *ImageStream, s conversion.Scope) error {
if err := s.Convert(&in.ObjectMeta, &out.ObjectMeta, 0); err != nil {
return err
}
out.Spec.DockerImageRepository = in.DockerImageRepository
if in.Tags != nil && out.Spec.Tags == nil {
out.Spec.Tags = make(map[string]TagReference)
}
for tag, value := range in.Tags {
out.Spec.Tags[tag] = TagReference{DockerImageReference: value}
}
return s.Convert(&in.Status, &out.Status, 0)
},
func(in *ImageStreamStatus, out *ImageRepositoryStatus, s conversion.Scope) error {
out.DockerImageRepository = in.DockerImageRepository
out.Tags = in.Tags
return nil
},
func(in *ImageRepositoryStatus, out *ImageStreamStatus, s conversion.Scope) error {
out.DockerImageRepository = in.DockerImageRepository
out.Tags = in.Tags
return nil
},
func(in *ImageStreamMapping, out *ImageRepositoryMapping, s conversion.Scope) error {
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields|conversion.AllowDifferentFieldTypeNames)
},
func(in *ImageRepositoryMapping, out *ImageStreamMapping, s conversion.Scope) error {
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields|conversion.AllowDifferentFieldTypeNames)
},
func(in *ImageStreamTag, out *ImageRepositoryTag, s conversion.Scope) error {
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields|conversion.AllowDifferentFieldTypeNames)
},
func(in *ImageRepositoryTag, out *ImageStreamTag, s conversion.Scope) error {
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields|conversion.AllowDifferentFieldTypeNames)
},
)
if err != nil {
// If one of the conversion functions is malformed, detect it immediately.
panic(err)
}
}