Serge Bazanski | be538db | 2020-11-12 00:22:42 +0100 | [diff] [blame] | 1 | // Copyright 2017 The kubecfg authors |
| 2 | // |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | package cmd |
| 17 | |
| 18 | import ( |
| 19 | "github.com/spf13/cobra" |
| 20 | |
| 21 | "code.hackerspace.pl/hscloud/cluster/tools/kartongips/pkg/kubecfg" |
| 22 | ) |
| 23 | |
| 24 | const ( |
| 25 | flagIgnoreUnknown = "ignore-unknown" |
| 26 | ) |
| 27 | |
| 28 | func init() { |
| 29 | RootCmd.AddCommand(validateCmd) |
| 30 | validateCmd.PersistentFlags().Bool(flagIgnoreUnknown, true, "Don't fail if the schema for a given resource type is not found") |
| 31 | } |
| 32 | |
| 33 | var validateCmd = &cobra.Command{ |
| 34 | Use: "validate", |
| 35 | Short: "Compare generated manifest against server OpenAPI spec", |
| 36 | Args: cobra.ArbitraryArgs, |
| 37 | RunE: func(cmd *cobra.Command, args []string) error { |
| 38 | flags := cmd.Flags() |
| 39 | var err error |
| 40 | |
| 41 | c := kubecfg.ValidateCmd{} |
| 42 | |
| 43 | _, c.Mapper, c.Discovery, err = getDynamicClients(cmd) |
| 44 | if err != nil { |
| 45 | return err |
| 46 | } |
| 47 | |
| 48 | c.IgnoreUnknown, err = flags.GetBool(flagIgnoreUnknown) |
| 49 | if err != nil { |
| 50 | return err |
| 51 | } |
| 52 | |
| 53 | objs, err := readObjs(cmd, args) |
| 54 | if err != nil { |
| 55 | return err |
| 56 | } |
| 57 | |
| 58 | return c.Run(objs, cmd.OutOrStdout()) |
| 59 | }, |
| 60 | } |