Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YUNIKORN-2287] Decompress function doesn't need to decode base64 #752

Closed
wants to merge 1 commit into from

Conversation

FrankYang0529
Copy link
Member

What is this PR for?

Fix Decompress function and check the following case can run:

  1. Use gzip to compress and use base64 to encode the config
echo "
partitions:
  - name: default
    placementrules:
      - name: tag
        value: namespace
        create: true
    queues:
      - name: root
        submitacl: '*'
        queues:
          - name: parent
            submitacl: '*'" | gzip | base64
  1. Set the result to queues.yaml.gz in binaryData field.

What type of PR is it?

  • - Bug Fix

What is the Jira issue?

https://issues.apache.org/jira/browse/YUNIKORN-2287

How should this be tested?

Covered by e2e test.

Copy link

codecov bot commented Dec 22, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (ce8ac51) 71.30% compared to head (7a21656) 71.32%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #752      +/-   ##
==========================================
+ Coverage   71.30%   71.32%   +0.02%     
==========================================
  Files          43       43              
  Lines        7600     7592       -8     
==========================================
- Hits         5419     5415       -4     
+ Misses       1979     1976       -3     
+ Partials      202      201       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@FrankYang0529 FrankYang0529 force-pushed the YUNIKORN-2287 branch 5 times, most recently from 60037a6 to 04a43c3 Compare December 29, 2023 03:40
@chia7712
Copy link
Contributor

@FrankYang0529 I have another idea before reviewing. If this function is never in production, can we just get rid of it to simplify our code base?

@wilfred-s @craigcondit WDYT?

Copy link
Contributor

@wilfred-s wilfred-s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor tweaks, see comment in the jira would be nice to document why the decode is removed

@@ -0,0 +1,33 @@
#Licensed to the Apache Software Foundation (ASF) under one
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space between # and the wording on all lines

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other test data also need to add space to it. Do we want to fix this together in this PR?

https://github.com/apache/yunikorn-k8shim/blob/master/test/e2e/testdata/sleeppod_template.yaml

metadata:
name: yunikorn-configs
binaryData:
# echo "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain what this commented info is about

@chia7712
Copy link
Contributor

chia7712 commented Jan 4, 2024

why the decode is removed

@wilfred-s did you feel that decode is a kind of behavior change of k8s? This yunikorn feature is already existent for a period of time. We have to keep compatibility for previous k8s if previous k8s does not do base64 decoding.

If the base64 decoding happens way down in the k8s always, it seems we have not got binarydata work in yunikorn. That is to say, that yunikorn feature is nonexistent actually :)

In short, removing this feature seems to be acceptable. The benefit includes

  1. don't worry for k8s compatibility (if it exists)
  2. simplify code base

@chia7712
Copy link
Contributor

chia7712 commented Jan 4, 2024

Oh, the PR #675 got merged into 1.4.0 on 2023.09.19

My compatibility concern was redundant as the target k8s is almost equal to current version.

It seems there is no +1 on removing this feature, and maintaining this feature is ok to me.

@FrankYang0529 please address the comments and I will take a look later also.

@FrankYang0529
Copy link
Member Author

FrankYang0529 commented Jan 5, 2024

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 is decoded, then object from CoreV1().ConfigMaps(namespace).Get is decoded too. The reason is that both functions use same serializers.

GetConfigMapObj

  1. It uses scheme.Codecs.UniversalDeserializer().Decode.
  2. Codecs is from serializer.NewCodecFactory.
  3. In NewCodecFactory, it gets serializers from newSerializersForScheme.
  4. In newCodecFactory, it collects all serializers as decoders and sets it as runtime.Decoder to universal.
  5. The universal is a runtime.Decoder from recognizer.NewDecoder.
  6. In recognizer.Decoder.Decode, it tries all serializers.

CoreV1().ConfigMaps(namespace).Get

  1. In CoreV1().ConfigMaps(namespace).Get, it calls Do.
  2. In Do, it calls Request.transformResponse.
  3. In transformResponse, it calls r.c.content.Negotiator.Decoder.
  4. In Decoder, it checks media type and content type, and gets serializer from SerializerInfo.
  5. The SerializerInfo is from SerializerInfoForMediaType. The SerializerInfoForMediaType is just a utility function to check which mediaTypes match to contentType, so we have to check where mediaTypes from.
  6. The mediaTypes is from n.serializer.SupportedMediaTypes.
  7. In DecoderToVersion, 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.
  2. In NewForConfig, it calls NewForConfigAndClient.
  3. In NewForConfigAndClient, it calls corev1.NewForConfigAndClient.
  4. In corev1.NewForConfigAndClient.
    4-1a. In corev1.NewForConfigAndClient, it calls setConfigDefaults.
    4-1b. In setConfigDefaults, it sets NegotiatedSerializer as scheme.Codecs.WithoutConversion. The scheme.Codecs is same as first step in k8s.GetConfigMapObj.
    4-1c. In WithoutConversion, it return WithoutConversionCodecFactory{f}. This structure has DecoderToVersion function in step 7 (last list).
    4-2a. In corev1.NewForConfigAndClient, it calls rest.RESTClientForConfigAndClient.
    4-2b. In rest.RESTClientForConfigAndClient, it sets Negotiator as runtime.NewClientNegotiator. This function uses config.NegotiatedSerializer which is equal to step 4-1b.

Finally, NegotiatedSerializer is WithoutConversionCodecFactory and it also is CodecFactory. The SupportedMediaTypes in CodecFactory returns f.accepts which gets same serializers as f.universal.

@craigcondit
Copy link
Contributor

see comment in the jira would be nice to document why the decode is removed

I think there's more than enough comments in the JIRA relating to why this is not needed. Removing an unnecessary line of code from the PR doesn't warrant a comment either. What would it mean to a reader a year from now? (probably nothing at all).

@chia7712
Copy link
Contributor

chia7712 commented Jan 5, 2024

@FrankYang0529 could you please fix the conflicts?

Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FrankYang0529 thanks for this fix. please take a look at following comments.

test/e2e/bin_packing/bin_packing_test.go Outdated Show resolved Hide resolved
test/e2e/configmap/configmap_suite_test.go Outdated Show resolved Hide resolved
@chia7712
Copy link
Contributor

chia7712 commented Jan 6, 2024

@FrankYang0529 please rebase PR as #761 is already merged.

@FrankYang0529
Copy link
Member Author

The e2e failed case is Verify_basic_preemption which is not related to this PR and is filed in another JIRA YUNIKORN-2313.

Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FrankYang0529 thanks for updating patch. a couple of comments below.

test/e2e/configmap/configmap_suite_test.go Outdated Show resolved Hide resolved
test/e2e/configmap/configmap_suite_test.go Outdated Show resolved Hide resolved
test/e2e/configmap/configmap_suite_test.go Outdated Show resolved Hide resolved
Ω(oldConfigMap).NotTo(BeNil())
})

It("Verify_Compressed_ConfigMap", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me this e2e should focus on the way that YuniKorn loads the config file. Hence, loading the file is more suitable for this e2e rather than creating a compressed file directly. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that we just use Verify_Compressed_ConfigMap_From_File and remove Verify_Compressed_ConfigMap?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, it seems we should remove Verify_Compressed_ConfigMap and then add a new e2e to load non-compressed config file.

@chia7712
Copy link
Contributor

@FrankYang0529 please fix conflicts and rebase code

splitKey := strings.Split(key, ".")
compressionAlgo := splitKey[len(splitKey)-1]
if strings.EqualFold(compressionAlgo, constants.GzipSuffix) {
reader := bytes.NewReader(decodedValue)
reader := bytes.NewReader(value)
gzReader, err := gzip.NewReader(reader)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about gzReader, err := gzip.NewReader(bytes.NewReader(value))?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, updated it. Thank you.

Signed-off-by: PoAn Yang <payang@apache.org>
Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chia7712 chia7712 closed this in 57f11dc Jan 14, 2024
@FrankYang0529 FrankYang0529 deleted the YUNIKORN-2287 branch January 15, 2024 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants