1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-15 17:51:20 +00:00
kyverno/cmd/cli/kubectl-kyverno/main.go
Matt Veitas 5ef7581c5c
[Bug] [CLI] Restore warn-exit-code functionality for apply command (#9828)
* Restore warn-exite-code functionality for apply command

Signed-off-by: Matt Veitas <mveitas@gmail.com>

* Nove error handling

Signed-off-by: Matt Veitas <mveitas@gmail.com>

* Uncomment println statement

Signed-off-by: Matt Veitas <mveitas@gmail.com>

* Fixing linting

Signed-off-by: Matt Veitas <mveitas@gmail.com>

* Adding conformance tets for cli apply command with warn-exit-code

Signed-off-by: Matt Veitas <mveitas@gmail.com>

* Update path to kubectl-kyverno binary

Signed-off-by: Matt Veitas <mveitas@gmail.com>

* Add prepare-cli as needed dependency

Signed-off-by: Matt Veitas <mveitas@gmail.com>

* feat: install kubectl-kyverno in standard conformance tests

Signed-off-by: ShutingZhao <shuting@nirmata.com>

* fix: update chainsaw config

Signed-off-by: ShutingZhao <shuting@nirmata.com>

* fix: move CLI chainsaw tests to a separate action

Signed-off-by: ShutingZhao <shuting@nirmata.com>

* fix: CLI path

Signed-off-by: ShutingZhao <shuting@nirmata.com>

* fix: name

Signed-off-by: ShutingZhao <shuting@nirmata.com>

* fix: add chainsaw flag '--no-cluster'

Signed-off-by: ShutingZhao <shuting@nirmata.com>

* fix: CLI name

Signed-off-by: ShutingZhao <shuting@nirmata.com>

---------

Signed-off-by: Matt Veitas <mveitas@gmail.com>
Signed-off-by: ShutingZhao <shuting@nirmata.com>
Signed-off-by: shuting <shuting@nirmata.com>
Co-authored-by: ShutingZhao <shuting@nirmata.com>
2024-02-29 13:08:21 +00:00

45 lines
979 B
Go

package main
import (
"flag"
"fmt"
"os"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/apply"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/experimental"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/log"
"github.com/spf13/cobra"
)
func main() {
cmd, err := setup()
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
if err := cmd.Execute(); err != nil {
switch e := err.(type) {
case apply.WarnExitCodeError:
os.Exit(e.ExitCode)
default:
os.Exit(1)
}
}
}
func setup() (*cobra.Command, error) {
cmd := commands.RootCommand(experimental.IsEnabled())
if err := configureLogs(cmd); err != nil {
return nil, fmt.Errorf("Failed to setup logging (%w)", err)
}
return cmd, nil
}
func configureLogs(cli *cobra.Command) error {
if err := log.Configure(); err != nil {
return err
}
cli.PersistentFlags().AddGoFlagSet(flag.CommandLine)
return nil
}