FrankYang0529 commented on PR #752:
URL: https://github.com/apache/yunikorn-k8shim/pull/752#issuecomment-1878943093

   > see comment in the jira would be nice to document why the decode is removed
   
   I don't have a good reference to show why the configmap in Golang object is 
already decoded, but I may be able to proof that if object from our utility 
function 
[GetConfigMapObj](https://github.com/apache/yunikorn-k8shim/blob/3ab3b2d03dd21896e803dc871df706d2563e7064/test/e2e/framework/helpers/k8s/k8s_utils.go#L626)
 is decoded, then object from object from 
[CoreV1().ConfigMaps(namespace).Get](https://github.com/apache/yunikorn-k8shim/blob/3ab3b2d03dd21896e803dc871df706d2563e7064/pkg/client/kubeclient.go#L156)
 is decoded too. The reason is that both functions use same serializers.
   
   ### GetConfigMapObj
   
   1. It uses 
[scheme.Codecs.UniversalDeserializer().Decode](https://github.com/apache/yunikorn-k8shim/blob/3ab3b2d03dd21896e803dc871df706d2563e7064/test/e2e/framework/helpers/common/deserializer.go#L28).
   2. `Codecs` is from 
[serializer.NewCodecFactory](https://github.com/kubernetes/client-go/blob/bec45d3c69b597c35e0246cce5c5001127edf994/kubernetes/scheme/register.go#L81).
   3. In `NewCodecFactory`, it gets `serializers` from 
[newSerializersForScheme](https://github.com/kubernetes/apimachinery/blob/194b6f8ddf62f55d1b8d997223e94ace2c1def31/pkg/runtime/serializer/codec_factory.go#L182).
   4. In 
[newCodecFactory](https://github.com/kubernetes/apimachinery/blob/194b6f8ddf62f55d1b8d997223e94ace2c1def31/pkg/runtime/serializer/codec_factory.go#L183),
 it collects all `serializers` as 
[decoders](https://github.com/kubernetes/apimachinery/blob/194b6f8ddf62f55d1b8d997223e94ace2c1def31/pkg/runtime/serializer/codec_factory.go#L193-L194)
 and sets it as `runtime.Decoder` to 
[universal](https://github.com/kubernetes/apimachinery/blob/194b6f8ddf62f55d1b8d997223e94ace2c1def31/pkg/runtime/serializer/codec_factory.go#L235).
   5. The `universal` is a `runtime.Decoder` from 
[recognizer.NewDecoder](https://github.com/kubernetes/apimachinery/blob/194b6f8ddf62f55d1b8d997223e94ace2c1def31/pkg/runtime/serializer/recognizer/recognizer.go#L45-L49).
   6. In 
[recognizer.Decoder.Decode](https://github.com/kubernetes/apimachinery/blob/194b6f8ddf62f55d1b8d997223e94ace2c1def31/pkg/runtime/serializer/recognizer/recognizer.go#L80-L128),
 it tries all `serializers`.
   
   ### CoreV1().ConfigMaps(namespace).Get
   
   1. In `CoreV1().ConfigMaps(namespace).Get`, it calls 
[Do](https://github.com/kubernetes/client-go/blob/bec45d3c69b597c35e0246cce5c5001127edf994/kubernetes/typed/core/v1/configmap.go#L78).
   2. In `Do`, it calls 
[Request.transformResponse](https://github.com/kubernetes/client-go/blob/bec45d3c69b597c35e0246cce5c5001127edf994/rest/request.go#L1040).
   3. In `transformResponse`, it calls 
[r.c.content.Negotiator.Decoder](https://github.com/kubernetes/client-go/blob/bec45d3c69b597c35e0246cce5c5001127edf994/rest/request.go#L1114).
   4. In `Decoder`, [it checks media type and content type, and gets 
`serializer` from 
`SerializerInfo`.](https://github.com/kubernetes/apimachinery/blob/194b6f8ddf62f55d1b8d997223e94ace2c1def31/pkg/runtime/negotiate.go#L58-L68)
   5. The `SerializerInfo` is from 
[SerializerInfoForMediaType](https://github.com/kubernetes/apimachinery/blob/194b6f8ddf62f55d1b8d997223e94ace2c1def31/pkg/runtime/codec.go#L265-L277).
 The `SerializerInfoForMediaType` is just a utility function to check which 
`mediaTypes` match to `contentType`, so we have to check where `mediaTypes` 
from.
   7. The `mediaTypes` is from 
[n.serializer.SupportedMediaTypes](https://github.com/kubernetes/apimachinery/blob/194b6f8ddf62f55d1b8d997223e94ace2c1def31/pkg/runtime/negotiate.go#L59).
   8. In 
[DecoderToVersion](https://github.com/kubernetes/apimachinery/blob/194b6f8ddf62f55d1b8d997223e94ace2c1def31/pkg/runtime/serializer/codec_factory.go#L334-L338),
 the `serializer` is equal to `runtime.Decoder`.
   
   If we can proof the `runtime.Decoder` in both functions are same, then they 
will have same behavior - getting a decoded configmap. We have to check which 
structure implements `SupportedMediaTypes`.
   
   1. In k8shim, we get `kubernetes.Clientset` from 
[kubernetes.NewForConfig](https://github.com/apache/yunikorn-k8shim/blob/3ab3b2d03dd21896e803dc871df706d2563e7064/pkg/client/kubeclient.go#L45).
   2. In `NewForConfig`, it calls 
[NewForConfigAndClient](https://github.com/kubernetes/client-go/blob/bec45d3c69b597c35e0246cce5c5001127edf994/kubernetes/clientset.go#L473).
   3. In `NewForConfigAndClient`, it calls 
[corev1.NewForConfigAndClient](https://github.com/kubernetes/client-go/blob/bec45d3c69b597c35e0246cce5c5001127edf994/kubernetes/clientset.go#L583).
   4. In `corev1.NewForConfigAndClient`.
   4-1a. In `corev1.NewForConfigAndClient`, it calls 
[setConfigDefaults](https://github.com/kubernetes/client-go/blob/bec45d3c69b597c35e0246cce5c5001127edf994/kubernetes/typed/core/v1/core_client.go#L137).
   4-1b. In `setConfigDefaults`, it sets `NegotiatedSerializer` as 
[scheme.Codecs.WithoutConversion](https://github.com/kubernetes/client-go/blob/bec45d3c69b597c35e0246cce5c5001127edf994/kubernetes/typed/core/v1/core_client.go#L166).
 The `scheme.Codecs` is same as first step in `k8s.GetConfigMapObj`.
   4-1c. In `WithoutConversion`, it return 
[WithoutConversionCodecFactory{f}](https://github.com/kubernetes/apimachinery/blob/194b6f8ddf62f55d1b8d997223e94ace2c1def31/pkg/runtime/serializer/codec_factory.go#L245-L247).
 This structure has `DecoderToVersion` function in step 7 (last list).
   4-2a. In `corev1.NewForConfigAndClient`, it calls 
[rest.RESTClientForConfigAndClient](https://github.com/kubernetes/client-go/blob/bec45d3c69b597c35e0246cce5c5001127edf994/kubernetes/typed/core/v1/core_client.go#L140).
   4-2b. In `rest.RESTClientForConfigAndClient`, it sets `Negotiator` as 
[runtime.NewClientNegotiator](https://github.com/kubernetes/client-go/blob/bec45d3c69b597c35e0246cce5c5001127edf994/rest/config.go#L374).
 This function uses `config.NegotiatedSerializer` which is equal to step 4-1b.
   
   Finally, `NegotiatedSerializer` is 
[WithoutConversionCodecFactory](https://github.com/kubernetes/apimachinery/blob/194b6f8ddf62f55d1b8d997223e94ace2c1def31/pkg/runtime/serializer/codec_factory.go#L319-L338)
 and it also is 
[CodecFactory](https://github.com/kubernetes/apimachinery/blob/194b6f8ddf62f55d1b8d997223e94ace2c1def31/pkg/runtime/serializer/codec_factory.go#L176-L184).
 The 
[SupportedMediaTypes](https://github.com/kubernetes/apimachinery/blob/194b6f8ddf62f55d1b8d997223e94ace2c1def31/pkg/runtime/serializer/codec_factory.go#L250-L252)
 in `CodecFactory` returns `f.accepts` which gets same serializers as 
`f.universal`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to