forked from ksonnet/ksonnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.go
101 lines (83 loc) · 3.16 KB
/
validate.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
// Copyright 2017 The kubecfg authors
//
//
// 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 clicmd
import (
"github.com/pkg/errors"
"github.com/spf13/viper"
"github.com/spf13/cobra"
"github.com/ksonnet/ksonnet/pkg/actions"
"github.com/ksonnet/ksonnet/pkg/client"
)
const (
vValidateComponent = "validate-component"
valShortDesc = "Check generated component manifests against the server's API"
)
var (
validateClientConfig *client.Config
)
func init() {
RootCmd.AddCommand(validateCmd)
addEnvCmdFlags(validateCmd)
bindJsonnetFlags(validateCmd, "validate")
validateClientConfig = client.NewDefaultClientConfig(ka)
validateClientConfig.BindClientGoFlags(validateCmd)
viper.BindPFlag(vValidateComponent, validateCmd.Flag(flagComponent))
}
var validateCmd = &cobra.Command{
Use: "validate <env-name> [-c <component-name>]",
Short: valShortDesc,
RunE: func(cmd *cobra.Command, args []string) error {
var envName string
if len(args) == 1 {
envName = args[0]
}
m := map[string]interface{}{
actions.OptionApp: ka,
actions.OptionEnvName: envName,
actions.OptionModule: "",
actions.OptionComponentNames: viper.GetStringSlice(vValidateComponent),
actions.OptionClientConfig: validateClientConfig,
}
if err := extractJsonnetFlags("validate"); err != nil {
return errors.Wrap(err, "handle jsonnet flags")
}
return runAction(actionValidate, m)
},
Long: `
The ` + "`validate`" + ` command checks that an application or file is compliant with the
server APIs Kubernetes specification. Note that this command actually communicates
*with* the server for the specified ` + "`<env-name>`" + `, so it only works if your
$KUBECONFIG specifies a valid kubeconfig file.
When NO component is specified (no ` + "`-c`" + ` flag), this command checks all of
the files in the ` + "`components/`" + ` directory. This is the same as what would
get deployed to your cluster with ` + "`ks apply <env-name>`" + `.
When a component IS specified via the ` + "`-c`" + ` flag, this command only checks
the manifest for that particular component.
### Related Commands
* ` + "`ks show` " + `— ` + showShortDesc + `
* ` + "`ks apply` " + `— ` + applyShortDesc + `
### Syntax
`,
Example: `
# Validate all resources described in the ksonnet app, against the server
# specified by the 'dev' environment.
# NOTE: Make sure your current $KUBECONFIG matches the 'dev' cluster info
ksonnet validate dev
# Validate resources from the 'redis' component only, against the server specified
# by the 'prod' environment
# NOTE: Make sure your current $KUBECONFIG matches the 'prod' cluster info
ksonnet validate prod -c redis
`,
}