forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclt.go
137 lines (114 loc) · 3.27 KB
/
clt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package cluster
import (
"fmt"
"sync"
g "github.com/onsi/ginkgo"
reale2e "k8s.io/kubernetes/test/e2e"
e2e "k8s.io/kubernetes/test/e2e/framework"
exutil "github.com/openshift/origin/test/extended/util"
)
var viperConfig string
const (
defaultThreadCount int = 10
channelSize int = 1024
)
var _ = g.Describe("[sig-scalability][Feature:Performance][Serial][Slow] Load cluster", func() {
defer g.GinkgoRecover()
var oc = exutil.NewCLIWithoutNamespace("cl")
g.BeforeEach(func() {
var err error
viperConfig = reale2e.GetViperConfig()
e2e.Logf("Using config %v", viperConfig)
err = ParseConfig(viperConfig, false)
if err != nil {
e2e.Failf("Error parsing config: %v", err)
}
})
g.It("concurrently with templates", func() {
var namespaces []string
project := ConfigContext.ClusterLoader.Projects
if project == nil {
e2e.Failf("Invalid config file.\nFile: %v", project)
}
numWorkers := ConfigContext.ClusterLoader.Threads
if numWorkers == 0 {
numWorkers = defaultThreadCount
}
work := make(chan ProjectMeta, channelSize)
ns := make(chan string)
var wg sync.WaitGroup
for i := 0; i < numWorkers; i++ {
go clWorker(work, ns, &wg, oc)
}
for _, p := range project {
for j := 0; j < p.Number; j++ {
wg.Add(1)
unit := ProjectMeta{j, p, viperConfig}
work <- unit
namespace := <-ns
namespaces = append(namespaces, namespace)
}
}
wg.Wait()
e2e.Logf("Worker creations completed, closing channels.")
close(work)
close(ns)
if err := postCreateWait(oc, namespaces); err != nil {
e2e.Failf("Error in postCreateWait: %v", err)
}
})
})
func clWorker(in <-chan ProjectMeta, out chan<- string, wg *sync.WaitGroup, oc *exutil.CLI) {
for {
p, ok := <-in
if !ok {
e2e.Logf("Channel closed")
return
}
var allArgs []string
if p.NodeSelector != "" {
allArgs = append(allArgs, "--node-selector")
allArgs = append(allArgs, p.NodeSelector)
}
nsName := fmt.Sprintf("%s%d", p.Basename, p.Counter)
allArgs = append(allArgs, nsName)
// Check to see if the project exists
projectExists, _ := ProjectExists(oc, nsName)
if !projectExists {
e2e.Logf("Project %s does not exist.", nsName)
}
// Based on configuration handle project existance
switch p.IfExists {
case IF_EXISTS_REUSE:
e2e.Logf("Configuration requested reuse of project %v", nsName)
case IF_EXISTS_DELETE:
e2e.Logf("Configuration requested deletion of project %v", nsName)
if projectExists {
err := DeleteProject(oc, nsName, checkDeleteProjectInterval, checkDeleteProjectTimeout)
e2e.Logf("Error deleting project: %v", err)
}
default:
e2e.Failf("Unsupported ifexists value '%v' for project %v", p.IfExists, p)
}
if p.IfExists == IF_EXISTS_REUSE && projectExists {
// do nothing
} else {
// Create namespaces as defined in Cluster Loader config
err := oc.Run("adm", "new-project").Args(allArgs...).Execute()
if err != nil {
e2e.Logf("Error creating project: %v", err)
} else {
out <- nsName
e2e.Logf("Created new namespace: %v", nsName)
}
}
// Create templates as defined
for _, template := range p.Templates {
err := CreateSimpleTemplates(oc, nsName, p.ViperConfig, template)
if err != nil {
e2e.Logf("Error creating template: %v", err)
}
}
wg.Done()
}
}