@@ -21,6 +21,7 @@ import (
21
21
22
22
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
23
23
"k8s.io/apimachinery/pkg/runtime"
24
+ "k8s.io/apimachinery/pkg/runtime/schema"
24
25
"k8s.io/kube-openapi/pkg/util/proto"
25
26
"sigs.k8s.io/structured-merge-diff/typed"
26
27
"sigs.k8s.io/structured-merge-diff/value"
@@ -93,7 +94,7 @@ func (c *typeConverter) ObjectToTyped(obj runtime.Object) (typed.TypedValue, err
93
94
gvk := obj .GetObjectKind ().GroupVersionKind ()
94
95
t := c .parser .Type (gvk )
95
96
if t == nil {
96
- return nil , fmt . Errorf ( "no corresponding type for %v" , gvk )
97
+ return nil , newNoCorrespondingTypeError ( gvk )
97
98
}
98
99
return t .FromUnstructured (u )
99
100
}
@@ -108,7 +109,7 @@ func (c *typeConverter) YAMLToTyped(from []byte) (typed.TypedValue, error) {
108
109
gvk := unstructured .GetObjectKind ().GroupVersionKind ()
109
110
t := c .parser .Type (gvk )
110
111
if t == nil {
111
- return nil , fmt . Errorf ( "no corresponding type for %v" , gvk )
112
+ return nil , newNoCorrespondingTypeError ( gvk )
112
113
}
113
114
return t .FromYAML (typed .YAMLObject (string (from )))
114
115
}
@@ -125,3 +126,23 @@ func valueToObject(value *value.Value) (runtime.Object, error) {
125
126
}
126
127
return & unstructured.Unstructured {Object : u }, nil
127
128
}
129
+
130
+ type noCorrespondingTypeErr struct {
131
+ gvk schema.GroupVersionKind
132
+ }
133
+
134
+ func newNoCorrespondingTypeError (gvk schema.GroupVersionKind ) error {
135
+ return & noCorrespondingTypeErr {gvk : gvk }
136
+ }
137
+
138
+ func (k * noCorrespondingTypeErr ) Error () string {
139
+ return fmt .Sprintf ("no corresponding type for %v" , k .gvk )
140
+ }
141
+
142
+ func isNoCorrespondingTypeError (err error ) bool {
143
+ if err == nil {
144
+ return false
145
+ }
146
+ _ , ok := err .(* noCorrespondingTypeErr )
147
+ return ok
148
+ }
0 commit comments