Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Qiu <[email protected]>
  • Loading branch information
wenqiq committed Mar 21, 2024
1 parent 624fc41 commit b39ad49
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 56 deletions.
33 changes: 22 additions & 11 deletions test/performance/framework/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ package framework

//goland:noinspection ALL
import (
"bytes"
"context"
"fmt"
yamlutil "k8s.io/apimachinery/pkg/util/yaml"
"net"
"os"
"path"
"regexp"
"strings"
Expand All @@ -28,14 +31,12 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"

"antrea.io/antrea/pkg/ipam/ipallocator"
"antrea.io/antrea/test/e2e/providers"
"antrea.io/antrea/test/performance/config"
utils2 "antrea.io/antrea/test/performance/framework/utils"
"antrea.io/antrea/test/performance/framework/workload_pod"
"antrea.io/antrea/test/performance/utils"
)
Expand Down Expand Up @@ -75,7 +76,7 @@ func ScaleService(ctx context.Context, ch chan time.Duration, data *ScaleData) (
func renderServices(service *corev1.Service, num int) (svcs []*corev1.Service) {
for i := 0; i < num; i++ {
labelNum := i/2 + 1
svc := service
svc := &corev1.Service{Spec: service.Spec}
svc.Name = fmt.Sprintf("antrea-scale-svc-%d-%s", i, uuid.New().String())
svc.Spec.Selector = map[string]string{
fmt.Sprintf("%s%d", utils.SelectorLabelKeySuffix, labelNum): fmt.Sprintf("%s%d", utils.SelectorLabelValueSuffix, labelNum),
Expand Down Expand Up @@ -131,6 +132,22 @@ func retrieveCIDRs(provider providers.ProviderInterface, controlPlaneNodeName st
return res, nil
}

func unmarshallService(yamlFile string) (*corev1.Service, error) {
klog.InfoS("ReadYamlFile", "yamlFile", yamlFile)
podBytes, err := os.ReadFile(yamlFile)
if err != nil {
return nil, fmt.Errorf("error reading YAML file: %+v", err)
}
service := &corev1.Service{}

decoder := yamlutil.NewYAMLOrJSONDecoder(bytes.NewReader(podBytes), 100)

if err := decoder.Decode(service); err != nil {
return nil, fmt.Errorf("error decoding YAML file: %+v", err)
}
return service, nil
}

func scaleUp(ctx context.Context, data *ScaleData, ch chan time.Duration) (svcs []ServiceInfo, err error) {
provider := data.provider
controlPlaneNodeName := data.controlPlaneNodes[0]
Expand All @@ -157,19 +174,13 @@ func scaleUp(ctx context.Context, data *ScaleData, ch chan time.Duration) (svcs
_, ipNet, _ := net.ParseCIDR(svcCIDRIPv4)
allocator, err := ipallocator.NewCIDRAllocator(ipNet, []net.IP{net.ParseIP("10.96.0.1"), net.ParseIP("10.96.0.10")})

Check failure on line 175 in test/performance/framework/service.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (ubuntu-latest)

SA4006: this value of `err` is never used (staticcheck)

Check failure on line 175 in test/performance/framework/service.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (macos-latest)

SA4006: this value of `err` is never used (staticcheck)

var obj runtime.Object
obj, err = utils2.ReadYamlFile(path.Join(data.templateFilesPath, "service/service.yaml"))
var service *corev1.Service
service, err = unmarshallService(path.Join(data.templateFilesPath, "service/service.yaml"))
if err != nil {
err = fmt.Errorf("error reading Service template: %+v", err)
return
}

service, ok := obj.(*corev1.Service)
if !ok {
err = fmt.Errorf("error converting to Unstructured: %+v", "the template file is nil")
return
}

for _, ns := range nss {
klog.InfoS("Scale up Services", "Namespace", ns)
testPodIndex := 0
Expand Down
25 changes: 5 additions & 20 deletions test/performance/framework/service_test.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
package framework

import (
utils2 "antrea.io/antrea/test/performance/framework/utils"
"fmt"
corev1 "k8s.io/api/core/v1"
"testing"

"github.com/stretchr/testify/assert"
)

func TestRenderService(t *testing.T) {
var err error
defer func() {
fmt.Println(err)
}()
obj, err := utils2.ReadYamlFile("../../assets/service/service.yaml")
if err != nil {
err = fmt.Errorf("error reading Service template: %+v", err)
return
}

fmt.Println(obj, "0000")

service, ok := obj.(*corev1.Service)
if !ok {
err = fmt.Errorf("error converting to Unstructured: %+v", err)
return
}
fmt.Println(service)
obj, err := unmarshallService("../assets/service/service.yaml")
assert.NoError(t, err, "error reading Service template")
fmt.Println(obj)
}
25 changes: 0 additions & 25 deletions test/performance/framework/utils/praser.go
Original file line number Diff line number Diff line change
@@ -1,26 +1 @@
package utils

import (
"fmt"
"io/ioutil"
"k8s.io/klog/v2"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer/yaml"
)

func ReadYamlFile(yamlFile string) (runtime.Object, error) {
klog.InfoS("ReadYamlFile", "yamlFile", yamlFile)
podBytes, err := ioutil.ReadFile(yamlFile)
if err != nil {
return nil, fmt.Errorf("error reading YAML file: %+v", err)
}

decoder := yaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme)
obj, _, err := decoder.Decode(podBytes, nil, nil)
if err != nil {
return nil, fmt.Errorf("error decoding YAML file: %+v", err)
}
return obj, nil
}

0 comments on commit b39ad49

Please sign in to comment.