forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
image.go
94 lines (84 loc) · 2.84 KB
/
image.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
package legacy
import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/kubernetes/pkg/apis/core"
corev1conversions "k8s.io/kubernetes/pkg/apis/core/v1"
"github.com/openshift/api/image/docker10"
"github.com/openshift/api/image/dockerpre012"
imagev1 "github.com/openshift/api/image/v1"
"github.com/openshift/origin/pkg/api/apihelpers"
"github.com/openshift/origin/pkg/image/apis/image"
imagev1helpers "github.com/openshift/origin/pkg/image/apis/image/v1"
)
// InstallLegacyImage this looks like a lot of duplication, but the code in the individual versions is living and may
// change. The code here should never change and needs to allow the other code to move independently.
func InstallInternalLegacyImage(scheme *runtime.Scheme) {
InstallExternalLegacyImage(scheme)
schemeBuilder := runtime.NewSchemeBuilder(
addUngroupifiedInternalImageTypes,
core.AddToScheme,
corev1conversions.AddToScheme,
addLegacyImageFieldSelectorKeyConversions,
imagev1helpers.RegisterDefaults,
imagev1helpers.RegisterConversions,
)
utilruntime.Must(schemeBuilder.AddToScheme(scheme))
}
func InstallExternalLegacyImage(scheme *runtime.Scheme) {
schemeBuilder := runtime.NewSchemeBuilder(
addUngroupifiedImageTypes,
docker10.AddToSchemeInCoreGroup,
dockerpre012.AddToSchemeInCoreGroup,
corev1.AddToScheme,
)
utilruntime.Must(schemeBuilder.AddToScheme(scheme))
}
func addUngroupifiedImageTypes(scheme *runtime.Scheme) error {
types := []runtime.Object{
&imagev1.Image{},
&imagev1.ImageList{},
&imagev1.ImageSignature{},
&imagev1.ImageStream{},
&imagev1.ImageStreamList{},
&imagev1.ImageStreamMapping{},
&imagev1.ImageStreamTag{},
&imagev1.ImageStreamTagList{},
&imagev1.ImageStreamImage{},
&imagev1.ImageStreamImport{},
}
scheme.AddKnownTypes(GroupVersion, types...)
return nil
}
func addUngroupifiedInternalImageTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(InternalGroupVersion,
&image.Image{},
&image.ImageList{},
&image.DockerImage{},
&image.ImageSignature{},
&image.ImageStream{},
&image.ImageStreamList{},
&image.ImageStreamMapping{},
&image.ImageStreamTag{},
&image.ImageStreamTagList{},
&image.ImageStreamImage{},
&image.ImageStreamImport{},
)
return nil
}
func addLegacyImageFieldSelectorKeyConversions(scheme *runtime.Scheme) error {
if err := scheme.AddFieldLabelConversionFunc(GroupVersion.String(), "ImageStream", legacyImageStreamFieldSelectorKeyConversionFunc); err != nil {
return err
}
return nil
}
func legacyImageStreamFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) {
switch label {
case "spec.dockerImageRepository",
"status.dockerImageRepository":
return label, value, nil
default:
return apihelpers.LegacyMetaV1FieldSelectorConversionWithName(label, value)
}
}