@@ -39,7 +39,7 @@ import (
3939)
4040
4141// convertFunc is the user defined function for any conversion. The code in this file is a
42- // template that can be use for any CR conversion given this function.
42+ // template that can be used for any CR conversion given this function.
4343type convertFunc func (Object * unstructured.Unstructured , version string ) (* unstructured.Unstructured , metav1.Status )
4444
4545func statusErrorWithMessage (msg string , params ... interface {}) metav1.Status {
@@ -55,37 +55,6 @@ func statusSucceed() metav1.Status {
5555 }
5656}
5757
58- // doConversionV1beta1 converts the requested objects in the v1beta1 ConversionRequest using the given conversion function and
59- // returns a conversion response. Failures are reported with the Reason in the conversion response.
60- func doConversionV1beta1 (convertRequest * v1beta1.ConversionRequest , convert convertFunc ) * v1beta1.ConversionResponse {
61- var convertedObjects []runtime.RawExtension
62- for _ , obj := range convertRequest .Objects {
63- cr := unstructured.Unstructured {}
64- if err := cr .UnmarshalJSON (obj .Raw ); err != nil {
65- klog .Error (err )
66- return & v1beta1.ConversionResponse {
67- Result : metav1.Status {
68- Message : fmt .Sprintf ("failed to unmarshall object (%v) with error: %v" , string (obj .Raw ), err ),
69- Status : metav1 .StatusFailure ,
70- },
71- }
72- }
73- convertedCR , status := convert (& cr , convertRequest .DesiredAPIVersion )
74- if status .Status != metav1 .StatusSuccess {
75- klog .Error (status .String ())
76- return & v1beta1.ConversionResponse {
77- Result : status ,
78- }
79- }
80- convertedCR .SetAPIVersion (convertRequest .DesiredAPIVersion )
81- convertedObjects = append (convertedObjects , runtime.RawExtension {Object : convertedCR })
82- }
83- return & v1beta1.ConversionResponse {
84- ConvertedObjects : convertedObjects ,
85- Result : statusSucceed (),
86- }
87- }
88-
8958// doConversionV1 converts the requested objects in the v1 ConversionRequest using the given conversion function and
9059// returns a conversion response. Failures are reported with the Reason in the conversion response.
9160func doConversionV1 (convertRequest * v1.ConversionRequest , convert convertFunc ) * v1.ConversionResponse {
@@ -145,21 +114,6 @@ func serve(w http.ResponseWriter, r *http.Request, convert convertFunc) {
145114
146115 var responseObj runtime.Object
147116 switch * gvk {
148- case v1beta1 .SchemeGroupVersion .WithKind ("ConversionReview" ):
149- convertReview , ok := obj .(* v1beta1.ConversionReview )
150- if ! ok {
151- msg := fmt .Sprintf ("Expected v1beta1.ConversionReview but got: %T" , obj )
152- klog .Errorf ("%s" , msg )
153- http .Error (w , msg , http .StatusBadRequest )
154- return
155- }
156- convertReview .Response = doConversionV1beta1 (convertReview .Request , convert )
157- convertReview .Response .UID = convertReview .Request .UID
158- klog .V (2 ).Info (fmt .Sprintf ("sending response: %v" , convertReview .Response ))
159-
160- // reset the request, it is not needed in a response.
161- convertReview .Request = & v1beta1.ConversionRequest {}
162- responseObj = convertReview
163117 case v1 .SchemeGroupVersion .WithKind ("ConversionReview" ):
164118 convertReview , ok := obj .(* v1.ConversionReview )
165119 if ! ok {
0 commit comments