-
Notifications
You must be signed in to change notification settings - Fork 136
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
Signed-off-by: PoAn Yang <[email protected]>
- Loading branch information
1 parent
24c699f
commit 60037a6
Showing
10 changed files
with
289 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
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,94 @@ | ||
/* | ||
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() | ||
|
||
// Restart yunikorn and port-forward | ||
// Required to change node sort policy. | ||
ginkgo.By("Restart the scheduler pod") | ||
yunikorn.RestartYunikorn(&kClient) | ||
|
||
ginkgo.By("Port-forward scheduler pod after restart") | ||
yunikorn.RestorePortForwarding(&kClient) | ||
}) | ||
|
||
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 BeNumerically = gomega.BeNumerically | ||
var HaveOccurred = gomega.HaveOccurred | ||
var BeTrue = gomega.BeTrue |
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,144 @@ | ||
/* | ||
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/common" | ||
"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_Compressed_ConfigMap", func() { | ||
schedulerConfig := &configs.SchedulerConfig{ | ||
Partitions: []configs.PartitionConfig{{ | ||
Name: "default", | ||
Queues: []configs.QueueConfig{{ | ||
Name: "root", | ||
SubmitACL: "*", | ||
Parent: true, | ||
Queues: []configs.QueueConfig{{ | ||
Name: "queue1", | ||
SubmitACL: "*", | ||
}}, | ||
}}, | ||
}}, | ||
} | ||
|
||
// Wait for 1 second to set a new timestamp. If we don't wait for it, we may get a same timestamp. | ||
time.Sleep(1 * time.Second) | ||
ts, err := common.SetQueueTimestamp(schedulerConfig, "default", "root") | ||
Ω(err).NotTo(HaveOccurred()) | ||
|
||
schedulerConfigStr, err := common.ToYAML(schedulerConfig) | ||
Ω(err).NotTo(HaveOccurred()) | ||
|
||
// use gzip to compress | ||
var b bytes.Buffer | ||
gzWriter := gzip.NewWriter(&b) | ||
_, err = gzWriter.Write([]byte(schedulerConfigStr)) | ||
Ω(err).NotTo(HaveOccurred()) | ||
err = gzWriter.Close() | ||
Ω(err).NotTo(HaveOccurred()) | ||
|
||
var configMap *v1.ConfigMap | ||
configMap, err = kClient.GetConfigMaps(configmanager.YuniKornTestConfig.YkNamespace, | ||
configmanager.DefaultYuniKornConfigMap) | ||
Ω(err).NotTo(HaveOccurred()) | ||
Ω(configMap).NotTo(BeNil()) | ||
|
||
configMap.Data = map[string]string{} | ||
if configMap.BinaryData == nil { | ||
configMap.BinaryData = map[string][]byte{} | ||
} | ||
configMap.BinaryData[configmanager.DefaultPolicyGroup+".gz"] = b.Bytes() | ||
|
||
By("Updating the config map with BinaryData") | ||
_, err = kClient.UpdateConfigMap(configMap, configmanager.YuniKornTestConfig.YkNamespace) | ||
Ω(err).NotTo(HaveOccurred()) | ||
|
||
err = yunikorn.WaitForQueueTS("root", ts, 30*time.Second) | ||
Ω(err).NotTo(HaveOccurred()) | ||
|
||
checkSchedulerConfig(schedulerConfig) | ||
}) | ||
|
||
It("Verify_Compressed_ConfigMap_From_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)) | ||
reader := bytes.NewReader(queuesGz) | ||
gzReader, err := gzip.NewReader(reader) | ||
Ω(err).NotTo(HaveOccurred()) | ||
err = gzReader.Close() | ||
Ω(err).NotTo(HaveOccurred()) | ||
decompressedBytes, err := io.ReadAll(gzReader) | ||
Ω(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,33 @@ | ||
#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: | ||
# 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== |