forked from vmware-tanzu/sonobuoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mode.go
131 lines (115 loc) · 3.25 KB
/
mode.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
/*
Copyright 2018 Heptio Inc.
Licensed 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 client
import (
"fmt"
"strings"
"github.com/heptio/sonobuoy/pkg/plugin"
)
// Mode identifies a specific mode of running Sonobuoy.
// A mode is a defined configuration of plugins and E2E Focus and Config.
// Modes form the base level defaults, which can then be overriden by the e2e flags
// and the config flag.
type Mode string
const (
// Quick runs a single E2E test and the systemd log tests.
Quick Mode = "Quick"
// Conformance runs all of the E2E tests and the systemd log tests.
Conformance Mode = "Conformance"
// Extended run all of the E2E tests, the systemd log tests, and
// Heptio's E2E Tests.
Extended Mode = "Extended"
)
const defaultSkipList = `Alpha|\[(Disruptive|Feature:[^\]]+|Flaky)\]`
var modeMap = map[string]Mode{
string(Conformance): Conformance,
string(Quick): Quick,
// Removing until the extended tests are open sourced
// string(Extended): Extended,
}
// ModeConfig represents the sonobuoy configuration for a given mode.
type ModeConfig struct {
// E2EConfig is the focus and skip vars for the conformance tests.
E2EConfig E2EConfig
// Selectors are the plugins selected by this mode.
Selectors []plugin.Selection
}
// String needed for pflag.Value
func (m *Mode) String() string { return string(*m) }
// Type needed for pflag.Value
func (m *Mode) Type() string { return "Mode" }
// Set the name with a given string. Returns error on unknown mode.
func (m *Mode) Set(str string) error {
// Allow lowercase "conformance", "quick" etc in command line
upcase := strings.Title(str)
mode, ok := modeMap[upcase]
if !ok {
return fmt.Errorf("unknown mode %s", str)
}
*m = mode
return nil
}
// Get returns the ModeConfig associated with a mode name, or nil
// if there's no associated mode
func (m *Mode) Get() *ModeConfig {
switch *m {
case Conformance:
return &ModeConfig{
E2EConfig: E2EConfig{
Focus: `\[Conformance\]`,
Skip: defaultSkipList,
Parallel: "1",
},
Selectors: []plugin.Selection{
{Name: "e2e"},
{Name: "systemd-logs"},
},
}
case Quick:
return &ModeConfig{
E2EConfig: E2EConfig{
Focus: "Pods should be submitted and removed",
Skip: defaultSkipList,
Parallel: "1",
},
Selectors: []plugin.Selection{
{Name: "e2e"},
},
}
case Extended:
return &ModeConfig{
E2EConfig: E2EConfig{
Focus: `\[Conformance\]`,
Skip: defaultSkipList,
Parallel: "1",
},
Selectors: []plugin.Selection{
{Name: "e2e"},
{Name: "systemd-logs"},
{Name: "heptio-e2e"},
},
}
default:
return nil
}
}
// GetModes gets a list of all available modes.
func GetModes() []string {
keys := make([]string, len(modeMap))
i := 0
for k := range modeMap {
keys[i] = k
i++
}
return keys
}