-
Notifications
You must be signed in to change notification settings - Fork 787
/
compliance_run.go
94 lines (82 loc) · 2.36 KB
/
compliance_run.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
package compliance
import (
"github.com/heptio/sonobuoy/pkg/client"
"github.com/heptio/sonobuoy/pkg/config"
"github.com/jenkins-x/jx-logging/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/cmd/helper"
"github.com/jenkins-x/jx/v2/pkg/cmd/opts"
"github.com/jenkins-x/jx/v2/pkg/cmd/templates"
"github.com/pkg/errors"
"github.com/spf13/cobra"
v1 "k8s.io/api/core/v1"
)
var (
complianceRuntLong = templates.LongDesc(`
Runs the compliance tests
`)
complianceRunExample = templates.Examples(`
# Run the compliance tests
jx compliance run
`)
)
// ComplianceRunOptions options for "compliance run" command
type ComplianceRunOptions struct {
*opts.CommonOptions
}
// NewCmdComplianceRun creates a command object for the "compliance run" action, which
// starts the E2E compliance tests
func NewCmdComplianceRun(commonOpts *opts.CommonOptions) *cobra.Command {
options := &ComplianceRunOptions{
CommonOptions: commonOpts,
}
cmd := &cobra.Command{
Use: "run",
Short: "Runs the compliance tests",
Long: complianceRuntLong,
Example: complianceRunExample,
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
helper.CheckErr(err)
},
}
return cmd
}
// Run implements the "compliance run" command
func (o *ComplianceRunOptions) Run() error {
cc, err := o.ComplianceClient()
if err != nil {
return errors.Wrap(err, "could not create the compliance client")
}
cfg := o.config()
if err := cc.Run(cfg); err != nil {
return errors.Wrap(err, "failed to start the compliance tests")
}
log.Logger().Infof("Compliance tests started in namespace %q", complianceNamespace)
return nil
}
func (o *ComplianceRunOptions) config() *client.RunConfig {
modeName := client.CertifiedConformance
mode := modeName.Get()
genCfg := &client.GenConfig{
E2EConfig: &mode.E2EConfig,
Config: o.getConfigWithMode(modeName),
EnableRBAC: true,
ImagePullPolicy: string(v1.PullAlways),
KubeConformanceImage: kubeConformanceImage,
}
return &client.RunConfig{
GenConfig: *genCfg,
}
}
func (o *ComplianceRunOptions) getConfigWithMode(mode client.Mode) *config.Config {
cfg := config.New()
modeConfig := mode.Get()
if modeConfig != nil {
cfg.PluginSelections = modeConfig.Selectors
cfg.Namespace = complianceNamespace
cfg.WorkerImage = complianceWorkerImage
}
return cfg
}