-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3862cb
commit 06063e6
Showing
3 changed files
with
48 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var namespace string | ||
|
||
var checkCmd = &cobra.Command{ | ||
Use: "check", | ||
Short: "Check if a namespace has no resources", | ||
Long: `This command checks a given namespace to see if it contains any resources.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// 이곳에서 kubectl 명령어를 실행하여 네임스페이스의 리소스를 검사합니다. | ||
if namespace == "" { | ||
fmt.Println("Please provide a namespace.") | ||
return | ||
} | ||
|
||
// `kubectl get all` 명령어로 네임스페이스를 검사하는 예시입니다. | ||
out, err := exec.Command("kubectl", "get", "all", "-n", namespace).Output() | ||
if err != nil { | ||
fmt.Printf("Error checking namespace: %v\n", err) | ||
return | ||
} | ||
|
||
fmt.Printf("Resources in namespace %s:\n%s\n", namespace, string(out)) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(checkCmd) | ||
|
||
// 플래그 추가 (예: --namespace) | ||
checkCmd.Flags().StringVarP(&namespace, "namespace", "n", "", "Namespace to inspect") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,24 @@ | ||
/* | ||
Copyright © 2024 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
|
||
|
||
// rootCmd represents the base command when called without any subcommands | ||
var rootCmd = &cobra.Command{ | ||
Use: "kubectl-ns-inspect", | ||
Short: "A brief description of your application", | ||
Long: `A longer description that spans multiple lines and likely contains | ||
examples and usage of using your application. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
// Uncomment the following line if your bare application | ||
// has an action associated with it: | ||
// Run: func(cmd *cobra.Command, args []string) { }, | ||
Short: "Inspect if a namespace has no resources", | ||
Long: `This plugin inspects a given Kubernetes namespace to check if it contains any resources.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("kubectl-ns-inspect is a Kubernetes plugin to check namespaces.") | ||
}, | ||
} | ||
|
||
// Execute adds all child commands to the root command and sets flags appropriately. | ||
// This is called by main.main(). It only needs to happen once to the rootCmd. | ||
func Execute() { | ||
err := rootCmd.Execute() | ||
if err != nil { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
// Here you will define your flags and configuration settings. | ||
// Cobra supports persistent flags, which, if defined here, | ||
// will be global for your application. | ||
|
||
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.kubectl-ns-inspect.yaml)") | ||
|
||
// Cobra also supports local flags, which will only run | ||
// when this action is called directly. | ||
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters