forked from apache/yunikorn-k8shim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[YUNIKORN-2287] Decompress function doesn't need to decode base64 (ap…
…ache#752) Closes: apache#752 Signed-off-by: Chia-Ping Tsai <chia7712@gmail.com>
- Loading branch information
1 parent
ce8ac51
commit 57f11dc
Showing
10 changed files
with
284 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package configmap | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/ginkgo/v2/reporters" | ||
"github.com/onsi/gomega" | ||
|
||
"github.com/apache/yunikorn-k8shim/test/e2e/framework/configmanager" | ||
"github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/common" | ||
"github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/k8s" | ||
"github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/yunikorn" | ||
) | ||
|
||
func init() { | ||
configmanager.YuniKornTestConfig.ParseFlags() | ||
} | ||
|
||
func TestConfigMap(t *testing.T) { | ||
ginkgo.ReportAfterSuite("TestConfigMap", func(report ginkgo.Report) { | ||
err := common.CreateJUnitReportDir() | ||
Ω(err).NotTo(gomega.HaveOccurred()) | ||
err = reporters.GenerateJUnitReportWithConfig( | ||
report, | ||
filepath.Join(configmanager.YuniKornTestConfig.LogDir, "TEST-configmap_junit.xml"), | ||
reporters.JunitReportConfig{OmitSpecLabels: true}, | ||
) | ||
Ω(err).NotTo(HaveOccurred()) | ||
}) | ||
gomega.RegisterFailHandler(ginkgo.Fail) | ||
ginkgo.RunSpecs(t, "TestConfigMap", ginkgo.Label("TestConfigMap")) | ||
} | ||
|
||
var ( | ||
kClient k8s.KubeCtl | ||
restClient yunikorn.RClient | ||
) | ||
|
||
var _ = BeforeSuite(func() { | ||
|
||
kClient = k8s.KubeCtl{} | ||
Ω(kClient.SetClient()).To(BeNil()) | ||
|
||
restClient = yunikorn.RClient{} | ||
Ω(restClient).NotTo(BeNil()) | ||
|
||
yunikorn.EnsureYuniKornConfigsPresent() | ||
|
||
By("Port-forward the scheduler pod") | ||
err := kClient.PortForwardYkSchedulerPod() | ||
Ω(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
var _ = AfterSuite(func() {}) | ||
|
||
var Describe = ginkgo.Describe | ||
var It = ginkgo.It | ||
var By = ginkgo.By | ||
var BeforeEach = ginkgo.BeforeEach | ||
var AfterEach = ginkgo.AfterEach | ||
var BeforeSuite = ginkgo.BeforeSuite | ||
var AfterSuite = ginkgo.AfterSuite | ||
|
||
// Declarations for Gomega Matchers | ||
var Equal = gomega.Equal | ||
var Ω = gomega.Expect | ||
var BeNil = gomega.BeNil | ||
var HaveOccurred = gomega.HaveOccurred |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package configmap | ||
|
||
import ( | ||
"bytes" | ||
"compress/gzip" | ||
"io" | ||
"time" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
|
||
"github.com/apache/yunikorn-core/pkg/common/configs" | ||
"github.com/apache/yunikorn-k8shim/test/e2e/framework/configmanager" | ||
"github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/k8s" | ||
"github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/yunikorn" | ||
) | ||
|
||
var oldConfigMap = new(v1.ConfigMap) | ||
|
||
var _ = Describe("ConfigMap", func() { | ||
BeforeEach(func() { | ||
By("Get previous config") | ||
var err error | ||
oldConfigMap, err = kClient.GetConfigMaps(configmanager.YuniKornTestConfig.YkNamespace, | ||
configmanager.DefaultYuniKornConfigMap) | ||
Ω(err).NotTo(HaveOccurred()) | ||
Ω(oldConfigMap).NotTo(BeNil()) | ||
}) | ||
|
||
It("Verify_ConfigMap_File", func() { | ||
configMap, err := k8s.GetConfigMapObj("../testdata/yunikorn-configs.yaml") | ||
Ω(err).NotTo(HaveOccurred()) | ||
Ω(configMap).NotTo(BeNil()) | ||
|
||
By("Updating the config map with BinaryData") | ||
configMap.Namespace = configmanager.YuniKornTestConfig.YkNamespace | ||
_, err = kClient.UpdateConfigMap(configMap, configmanager.YuniKornTestConfig.YkNamespace) | ||
Ω(err).NotTo(HaveOccurred()) | ||
|
||
queues := configMap.Data[configmanager.DefaultPolicyGroup] | ||
|
||
schedulerConfig, err := configs.LoadSchedulerConfigFromByteArray([]byte(queues)) | ||
Ω(err).NotTo(HaveOccurred()) | ||
Ω(len(schedulerConfig.Partitions)).To(Equal(1)) | ||
Ω(len(schedulerConfig.Partitions[0].Queues)).To(Equal(1)) | ||
|
||
ts := schedulerConfig.Partitions[0].Queues[0].Properties["timestamp"] | ||
err = yunikorn.WaitForQueueTS("root", ts, 30*time.Second) | ||
Ω(err).NotTo(HaveOccurred()) | ||
|
||
checkSchedulerConfig(schedulerConfig) | ||
}) | ||
|
||
It("Verify_Compressed_ConfigMap_File", func() { | ||
configMap, err := k8s.GetConfigMapObj("../testdata/compressed_yunikorn-configs.yaml") | ||
Ω(err).NotTo(HaveOccurred()) | ||
Ω(configMap).NotTo(BeNil()) | ||
|
||
By("Updating the config map with BinaryData") | ||
configMap.Namespace = configmanager.YuniKornTestConfig.YkNamespace | ||
_, err = kClient.UpdateConfigMap(configMap, configmanager.YuniKornTestConfig.YkNamespace) | ||
Ω(err).NotTo(HaveOccurred()) | ||
|
||
queuesGz := configMap.BinaryData[configmanager.DefaultPolicyGroup+".gz"] | ||
Ω(len(queuesGz)).NotTo(Equal(0)) | ||
gzReader, err := gzip.NewReader(bytes.NewReader(queuesGz)) | ||
Ω(err).NotTo(HaveOccurred()) | ||
decompressedBytes, err := io.ReadAll(gzReader) | ||
Ω(err).NotTo(HaveOccurred()) | ||
err = gzReader.Close() | ||
Ω(err).NotTo(HaveOccurred()) | ||
|
||
schedulerConfig, err := configs.LoadSchedulerConfigFromByteArray(decompressedBytes) | ||
Ω(err).NotTo(HaveOccurred()) | ||
Ω(len(schedulerConfig.Partitions)).To(Equal(1)) | ||
Ω(len(schedulerConfig.Partitions[0].Queues)).To(Equal(1)) | ||
|
||
ts := schedulerConfig.Partitions[0].Queues[0].Properties["timestamp"] | ||
err = yunikorn.WaitForQueueTS("root", ts, 30*time.Second) | ||
Ω(err).NotTo(HaveOccurred()) | ||
|
||
checkSchedulerConfig(schedulerConfig) | ||
}) | ||
|
||
AfterEach(func() { | ||
yunikorn.RestoreConfigMapWrapper(oldConfigMap, "") | ||
}) | ||
}) | ||
|
||
func checkSchedulerConfig(schedulerConfig *configs.SchedulerConfig) { | ||
configDAOInfo, err := restClient.GetConfig() | ||
Ω(err).NotTo(HaveOccurred()) | ||
Ω(configDAOInfo).NotTo(BeNil()) | ||
Ω(configDAOInfo.Partitions).To(Equal(schedulerConfig.Partitions)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: yunikorn-configs | ||
binaryData: | ||
# Following command is used to generate queues.yaml which is compressed by gzip and encoded by base64. | ||
# The result is like the value in queues.yaml.gz. If updating the queues.yaml, please also update the queues.yaml.gz. | ||
# echo " | ||
# partitions: | ||
# - name: default | ||
# queues: | ||
# - name: root | ||
# submitacl: '*' | ||
# parent: true | ||
# properties: | ||
# timestamp: '1257894000' | ||
# queues: | ||
# - name: parent | ||
# submitacl: '*'" | gzip | base64 | ||
queues.yaml.gz: H4sIANGBiWUAA2WO2wrCMBBE3/sV81YQhCiKmr9ZdQuB5mKy+/+maptK5/Hscma6RFmcuBiK7YA9Anm2ePJAOkolwEtZ+XOdMn/kGOWHgKJ374Qeo0W/6xdc3RzEQrJygzkmrp1NOUWc5yLkUzUcjufL9XYyxjTV/4j1kG/J6rCZ8wavmg4s5AAAAA== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: yunikorn-configs | ||
data: | ||
queues.yaml: | | ||
partitions: | ||
- name: default | ||
queues: | ||
- name: root | ||
submitacl: '*' | ||
parent: true | ||
properties: | ||
timestamp: '1705067238' | ||
queues: | ||
- name: parent | ||
submitacl: '*' |