Skip to content
This repository has been archived by the owner on Apr 1, 2023. It is now read-only.

update automaticmanagednamespace to dynamic generate namespace name #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions clusterloader2/pkg/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"k8s.io/perf-tests/clusterloader2/pkg/config"
"k8s.io/perf-tests/clusterloader2/pkg/errors"
"k8s.io/perf-tests/clusterloader2/pkg/framework/client"
"k8s.io/perf-tests/clusterloader2/pkg/util"

// ensure auth plugins are loaded
_ "k8s.io/client-go/plugin/pkg/client/auth"
Expand Down Expand Up @@ -107,7 +108,7 @@ func (f *Framework) CreateAutomanagedNamespaces(namespaceCount int) error {
return fmt.Errorf("automanaged namespaces already created")
}
for i := 1; i <= namespaceCount; i++ {
name := fmt.Sprintf("%v-%d", f.automanagedNamespacePrefix, i)
name := fmt.Sprintf("%s-%v", util.RandomDNS1123String(6), f.automanagedNamespacePrefix)
if err := client.CreateNamespace(f.clientSets.GetClient(), name); err != nil {
return err
}
Expand Down Expand Up @@ -158,7 +159,37 @@ func (f *Framework) deleteNamespace(namespace string) error {
func (f *Framework) DeleteAutomanagedNamespaces() *errors.ErrorList {
var wg wait.Group
errList := errors.NewErrorList()
for i := 1; i <= f.automanagedNamespaceCount; i++ {
automanagedNamespacesList, staleNamespaces, err := f.ListAutomanagedNamespaces()
if err != nil {
errList.Append(err)
return errList
}
if len(automanagedNamespacesList) > 0 {
for namespaceIndex := range automanagedNamespacesList {
nsName := automanagedNamespacesList[namespaceIndex]
wg.Start(func() {
if err := f.deleteNamespace(nsName); err != nil {
errList.Append(err)
return
}
})
}

}

if len(staleNamespaces) > 0 {
for namespaceIndex := range staleNamespaces {
nsName := staleNamespaces[namespaceIndex]
wg.Start(func() {
if err := f.deleteNamespace(nsName); err != nil {
errList.Append(err)
return
}
})
}

}
/*for i := 1; i <= automanagedNamespacesList; i++ {
name := fmt.Sprintf("%v-%d", f.automanagedNamespacePrefix, i)
wg.Start(func() {
if err := f.deleteNamespace(name); err != nil {
Expand All @@ -167,6 +198,7 @@ func (f *Framework) DeleteAutomanagedNamespaces() *errors.ErrorList {
}
})
}
*/
wg.Wait()
f.automanagedNamespaceCount = 0
return errList
Expand Down Expand Up @@ -248,7 +280,8 @@ func (f *Framework) ApplyTemplatedManifests(manifestGlob string, templateMapping
}

func (f *Framework) isAutomanagedNamespace(name string) (bool, error) {
return regexp.MatchString(f.automanagedNamespacePrefix+"-[1-9][0-9]*", name)
//return regexp.MatchString(f.automanagedNamespacePrefix+"-[1-9][0-9]*", name)
return regexp.MatchString("[a-zA-Z0-9]{6,}-"+f.automanagedNamespacePrefix, name)
}

func (f *Framework) isStaleAutomanagedNamespace(name string) bool {
Expand Down
16 changes: 11 additions & 5 deletions clusterloader2/pkg/test/simple_test_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ package test
import (
"fmt"
"io/ioutil"
"k8s.io/perf-tests/clusterloader2/pkg/measurement"
"path"
"strings"
"time"

"k8s.io/perf-tests/clusterloader2/pkg/measurement"

"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -52,7 +53,8 @@ func createSimpleTestExecutor() TestExecutor {

// ExecuteTest executes test based on provided configuration.
func (ste *simpleTestExecutor) ExecuteTest(ctx Context, conf *api.Config) *errors.ErrorList {
ctx.GetClusterFramework().SetAutomanagedNamespacePrefix(fmt.Sprintf("test-%s", util.RandomDNS1123String(6)))
//ctx.GetClusterFramework().SetAutomanagedNamespacePrefix(fmt.Sprintf("%s-test", util.RandomDNS1123String(6)))
ctx.GetClusterFramework().SetAutomanagedNamespacePrefix("testns")
klog.Infof("AutomanagedNamespacePrefix: %s", ctx.GetClusterFramework().GetAutomanagedNamespacePrefix())
defer cleanupResources(ctx)
ctx.GetTuningSetFactory().Init(conf.TuningSets)
Expand Down Expand Up @@ -170,15 +172,19 @@ func (ste *simpleTestExecutor) ExecuteStep(ctx Context, step *api.Step) *errors.
func (ste *simpleTestExecutor) ExecutePhase(ctx Context, phase *api.Phase) *errors.ErrorList {
// TODO: add tuning set
errList := errors.NewErrorList()
nsList := createNamespacesList(ctx, phase.NamespaceRange)
automanagedNamespacesList, _, err := ctx.GetClusterFramework().ListAutomanagedNamespaces()
if err != nil {
return errors.NewErrorList(fmt.Errorf("automanaged namespaces listing failed: %v", err))
}
//nsList := createNamespacesList(ctx, phase.NamespaceRange)
tuningSet, err := ctx.GetTuningSetFactory().CreateTuningSet(phase.TuningSet)
if err != nil {
return errors.NewErrorList(fmt.Errorf("tuning set creation error: %v", err))
}

var actions []func()
for namespaceIndex := range nsList {
nsName := nsList[namespaceIndex]
for namespaceIndex := range automanagedNamespacesList {
nsName := automanagedNamespacesList[namespaceIndex]
instancesStates := make([]*state.InstancesState, 0)
// Updating state (DesiredReplicaCount) of every object in object bundle.
for j := range phase.ObjectBundle {
Expand Down