Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/crd argo rollouts #375

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 85 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Kor is a tool to discover unused Kubernetes resources. Currently, Kor can identi
- StorageClasses
- NetworkPolicies
- RoleBindings
- Argo Rollouts
- Argo Rollouts Analysis template
- Argo Rollouts Cluster Analysis template

![Kor Screenshot](/images/show_reason_screenshot.png)

Expand Down Expand Up @@ -125,6 +128,7 @@ Kor provides various subcommands to identify and list unused resources. The avai
- `daemonset`- Gets unused DaemonSets for the specified namespace or all namespaces.
- `finalizer` - Gets unused pending deletion resources for the specified namespace or all namespaces.
- `networkpolicy` - Gets unused NetworkPolicies for the specified namespace or all namespaces.
- `argo-rollouts, argo-rollouts-analysis-templates, argo-rollouts-cluster-analysis-templates` - Gets unsed argo-rollouts, analysis-templates and cluster-analysis-templates
- `exporter` - Export Prometheus metrics.
- `version` - Print kor version information.

Expand All @@ -147,7 +151,9 @@ Kor provides various subcommands to identify and list unused resources. The avai
--slack-auth-token string Slack auth token to send notifications to. --slack-auth-token requires --slack-channel to be set.
--slack-channel string Slack channel to send notifications to. --slack-channel requires --slack-auth-token to be set.
--slack-webhook-url string Slack webhook URL to send notifications to
--include-third-party-crds To get unused argo-rollouts, analysis-templates and cluster-analysis-templates
-v, --verbose Verbose output (print empty namespaces)

```

To use a specific subcommand, run `kor [subcommand] [flags]`.
Expand All @@ -156,6 +162,13 @@ To use a specific subcommand, run `kor [subcommand] [flags]`.
kor all --include-namespaces my-namespace
```

To get all with Argo Rollouts

```sh
kor all --include-namespaces my-namespace --include-third-party-crds argo-rollouts,argo-rollouts-analysis-templates,argo-rollouts-cluster-analysis-templates
```


For more information about each subcommand and its available flags, you can use the `--help` flag.

```sh
Expand All @@ -179,13 +192,16 @@ kor [subcommand] --help
| Ingresses | Ingresses not pointing at any Service | |
| Hpas | HPAs not used in Deployments<br/> HPAs not used in StatefulSets | |
| CRDs | CRDs not used the cluster | |
| Pvs | PVs not bound to a PVC | |
| Pdbs | PDBs not used in Deployments / StatefulSets (templates) or in arbitrary Pods<br/>PDBs with empty selectors (match every pod) but no running pods in namespace | |
| Pvs | PVs not bound to a PVC
| Pdbs | PDBs not used in Deployments / StatefulSets (templates) or in arbitrary Pods<br/>PDBs with empty selectors (match every pod) but no running pods in namespace | |
| Jobs | Jobs status is completed<br/> Jobs status is suspended<br/> Jobs failed with backoff limit exceeded (including indexed jobs) <br/> Jobs failed with dedaline exceeded | |
| ReplicaSets | replicaSets that specify replicas to 0 and has already completed it's work |
| DaemonSets | DaemonSets not scheduled on any nodes |
| StorageClasses | StorageClasses not used by any PVs/PVCs |
| StorageClasses | StorageClasses not used by any PVs/PVCs
| NetworkPolicies | NetworkPolicies with no Pods selected by podSelector or Ingress/Egress rules |
| ArgoRollouts | ArgoRollouts not used by any deployment |
| ArgoRollouts-AnalysisTemplate | Analysys template not used by any Argo Rollout |
| ArgoRollouts-ClusterAnalysisTemplate | Cluster analysys template not used by any Argo Rollout |

### Deleting Unused resources

Expand Down Expand Up @@ -253,6 +269,45 @@ Unused resources in namespace: "test"
+---+----------------+----------------------------------------------+--------------------------------------------------------+
```

```sh
kor all --include-third-party-crds argo-rollouts,argo-rollouts-analysis-templates,argo-rollouts-cluster-analysis-templates --show-reason --show-reason
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this additional example

```
```
Unused resources in namespace: "default"
+---+-------------------------------+------------------------------------+------------------------------------------------+
| # | RESOURCE TYPE | RESOURCE NAME | REASON |
+---+-------------------------------+------------------------------------+------------------------------------------------+
| 1 | ServiceAccount | bookinfo-gateway-istio | ServiceAccount is not in use |
| 2 | ConfigMap | istio-ca-root-cert | ConfigMap is not used in any pod or container |
| 3 | Pvc | devlake-mysql-data-devlake-mysql-0 | PVC is not in use |
| 4 | ReplicaSet | rollout-canary-679b8b5b4c | ReplicaSet is not in use |
| 5 | ArgoRollout | rollout-canary | Rollout has 0 replicas |
| 6 | ArgoRollouts-AnalysisTemplate | pass | Argo Rollouts Analysis Templates is not in use |
+---+-------------------------------+------------------------------------+------------------------------------------------+

Unused resources in namespace: ""
+----+--------------------------------------+----------------------------------+--------------------------------------------------------------+
| # | RESOURCE TYPE | RESOURCE NAME | REASON |
+----+--------------------------------------+----------------------------------+--------------------------------------------------------------+
| 1 | ArgoRollouts-ClusterAnalysisTemplate | always-pass | Argo Rollouts Cluster Analysis Templates is not in use |
| 2 | ArgoRollouts-ClusterAnalysisTemplate | alert-template | Argo Rollouts Cluster Analysis Templates is not in use |
| 3 | Pv | mongo-data-pv | Persistent Volume is not in use |
| 4 | Pv | config | Persistent Volume is not in use |
| 5 | ClusterRole | cert-manager-cluster-view | ClusterRole is not used by any RoleBinding or |
| | | | ClusterRoleBinding |
| 6 | ClusterRole | cert-manager-view | ClusterRole is not used by any RoleBinding or |
| | | | ClusterRoleBinding |
| 7 | ClusterRole | cert-manager-edit | ClusterRole is not used by any RoleBinding or |
| | | | ClusterRoleBinding |
| 8 | ClusterRole | argo-rollouts-aggregate-to-admin | ClusterRole is not used by any RoleBinding or |
| | | | ClusterRoleBinding |
| 9 | ClusterRole | argo-rollouts-aggregate-to-edit | ClusterRole is not used by any RoleBinding or |
| | | | ClusterRoleBinding |
| 10 | ClusterRole | argo-rollouts-aggregate-to-view | ClusterRole is not used by any RoleBinding or |
| | | | ClusterRoleBinding |
+----+--------------------------------------+----------------------------------+--------------------------------------------------------------+
```

#### Group by resource

```sh
Expand Down Expand Up @@ -283,6 +338,33 @@ Unused ReplicaSets:
+---+-----------+--------------------+
```

```sh
kor all --include-third-party-crds argo-rollouts,argo-rollouts-analysis-templates,argo-rollouts-cluster-analysis-templates --group-by=resource --output=table
```
```**
Unused ArgoRollouts:
+---+-----------+----------------+
| # | NAMESPACE | RESOURCE NAME |
+---+-----------+----------------+
| 1 | default | rollout-canary |
+---+-----------+----------------+

Unused ArgoRollouts-AnalysisTemplates:
+---+-----------+---------------+
| # | NAMESPACE | RESOURCE NAME |
+---+-----------+---------------+
| 1 | default | pass |
+---+-----------+---------------+

Unused ArgoRollouts-ClusterAnalysisTemplates:
+---+-----------+----------------+
| # | NAMESPACE | RESOURCE NAME |
+---+-----------+----------------+
| 1 | | always-pass |
| 2 | | alert-template |
+---+-----------+----------------+
```

#### Group by namespace

```sh
Expand Down
2 changes: 1 addition & 1 deletion charts/kor/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ annotations:
- name: Chart Source
url: https://github.com/yonahd/kor/tree/main/charts/kor
- name: Grafana Dashboard
url: https://grafana.com/grafana/dashboards/19863-kor-dashboard/
url: https://grafana.com/grafana/dashboards/19863-kor-dashboard/
2 changes: 1 addition & 1 deletion charts/kor/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ serviceAccount:
annotations: {}
# -- The name of the service account to use.
# -- If not set and create is true, a name is generated using the fullname template
name: ""
name: ""
11 changes: 6 additions & 5 deletions cmd/kor/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/cobra"

"github.com/yonahd/kor/pkg/clusterconfig"
"github.com/yonahd/kor/pkg/kor"
"github.com/yonahd/kor/pkg/utils"
)
Expand All @@ -14,11 +15,11 @@ var allCmd = &cobra.Command{
Short: "Gets unused resources",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
clientset := kor.GetKubeClient(kubeconfig)
apiExtClient := kor.GetAPIExtensionsClient(kubeconfig)
dynamicClient := kor.GetDynamicClient(kubeconfig)

if response, err := kor.GetUnusedAll(filterOptions, clientset, apiExtClient, dynamicClient, outputFormat, opts); err != nil {
clientset := clusterconfig.GetKubeClient(kubeconfig)
apiExtClient := clusterconfig.GetAPIExtensionsClient(kubeconfig)
dynamicClient := clusterconfig.GetDynamicClient(kubeconfig)
clientsetinterface, _ := clusterconfig.GetKubeClientForCrds(kubeconfig, clientset)
if response, err := kor.GetUnusedAll(filterOptions, clientset, apiExtClient, dynamicClient, clientsetinterface, outputFormat, opts); err != nil {
fmt.Println(err)
} else {
utils.PrintLogo(outputFormat)
Expand Down
3 changes: 2 additions & 1 deletion cmd/kor/clusterroles.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/cobra"

"github.com/yonahd/kor/pkg/clusterconfig"
"github.com/yonahd/kor/pkg/kor"
"github.com/yonahd/kor/pkg/utils"
)
Expand All @@ -15,7 +16,7 @@ var clusterRoleCmd = &cobra.Command{
Short: "Gets unused cluster roles",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
clientset := kor.GetKubeClient(kubeconfig)
clientset := clusterconfig.GetKubeClient(kubeconfig)

if response, err := kor.GetUnusedClusterRoles(filterOptions, clientset, outputFormat, opts); err != nil {
fmt.Println(err)
Expand Down
3 changes: 2 additions & 1 deletion cmd/kor/configmaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/cobra"

"github.com/yonahd/kor/pkg/clusterconfig"
"github.com/yonahd/kor/pkg/kor"
"github.com/yonahd/kor/pkg/utils"
)
Expand All @@ -15,7 +16,7 @@ var configmapCmd = &cobra.Command{
Short: "Gets unused configmaps",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
clientset := kor.GetKubeClient(kubeconfig)
clientset := clusterconfig.GetKubeClient(kubeconfig)
if response, err := kor.GetUnusedConfigmaps(filterOptions, clientset, outputFormat, opts); err != nil {
fmt.Println(err)
} else {
Expand Down
5 changes: 3 additions & 2 deletions cmd/kor/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/cobra"

"github.com/yonahd/kor/pkg/clusterconfig"
"github.com/yonahd/kor/pkg/kor"
"github.com/yonahd/kor/pkg/utils"
)
Expand All @@ -15,8 +16,8 @@ var crdCmd = &cobra.Command{
Short: "Gets unused crds",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
apiExtClient := kor.GetAPIExtensionsClient(kubeconfig)
dynamicClient := kor.GetDynamicClient(kubeconfig)
apiExtClient := clusterconfig.GetAPIExtensionsClient(kubeconfig)
dynamicClient := clusterconfig.GetDynamicClient(kubeconfig)
if response, err := kor.GetUnusedCrds(filterOptions, apiExtClient, dynamicClient, outputFormat, opts); err != nil {
fmt.Println(err)
} else {
Expand Down
3 changes: 2 additions & 1 deletion cmd/kor/daemonsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/cobra"

"github.com/yonahd/kor/pkg/clusterconfig"
"github.com/yonahd/kor/pkg/kor"
"github.com/yonahd/kor/pkg/utils"
)
Expand All @@ -15,7 +16,7 @@ var dsCmd = &cobra.Command{
Short: "Gets unused daemonSets",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
clientset := kor.GetKubeClient(kubeconfig)
clientset := clusterconfig.GetKubeClient(kubeconfig)

if response, err := kor.GetUnusedDaemonSets(filterOptions, clientset, outputFormat, opts); err != nil {
fmt.Println(err)
Expand Down
3 changes: 2 additions & 1 deletion cmd/kor/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/cobra"

"github.com/yonahd/kor/pkg/clusterconfig"
"github.com/yonahd/kor/pkg/kor"
"github.com/yonahd/kor/pkg/utils"
)
Expand All @@ -15,7 +16,7 @@ var deployCmd = &cobra.Command{
Short: "Gets unused deployments",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
clientset := kor.GetKubeClient(kubeconfig)
clientset := clusterconfig.GetKubeClient(kubeconfig)
if response, err := kor.GetUnusedDeployments(filterOptions, clientset, outputFormat, opts); err != nil {
fmt.Println(err)
} else {
Expand Down
10 changes: 6 additions & 4 deletions cmd/kor/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kor
import (
"github.com/spf13/cobra"

"github.com/yonahd/kor/pkg/clusterconfig"
"github.com/yonahd/kor/pkg/kor"
)

Expand All @@ -13,11 +14,12 @@ var exporterCmd = &cobra.Command{
Short: "start prometheus exporter",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
clientset := kor.GetKubeClient(kubeconfig)
apiExtClient := kor.GetAPIExtensionsClient(kubeconfig)
dynamicClient := kor.GetDynamicClient(kubeconfig)
clientset := clusterconfig.GetKubeClient(kubeconfig)
clientsetinterface, _ := clusterconfig.GetKubeClientForCrds(kubeconfig, clientset)
apiExtClient := clusterconfig.GetAPIExtensionsClient(kubeconfig)
dynamicClient := clusterconfig.GetDynamicClient(kubeconfig)

kor.Exporter(filterOptions, clientset, apiExtClient, dynamicClient, "json", opts, resourceList)
kor.Exporter(filterOptions, clientset, apiExtClient, dynamicClient, clientsetinterface, "json", opts, resourceList)

},
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/kor/finalizers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/cobra"

"github.com/yonahd/kor/pkg/clusterconfig"
"github.com/yonahd/kor/pkg/kor"
)

Expand All @@ -14,8 +15,8 @@ var finalizerCmd = &cobra.Command{
Short: "Gets resources waiting for finalizers to delete",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
clientset := kor.GetKubeClient(kubeconfig)
dynamicClient := kor.GetDynamicClient(kubeconfig)
clientset := clusterconfig.GetKubeClient(kubeconfig)
dynamicClient := clusterconfig.GetDynamicClient(kubeconfig)

if response, err := kor.GetUnusedfinalizers(filterOptions, clientset, dynamicClient, outputFormat, opts); err != nil {
fmt.Println(err)
Expand Down
3 changes: 2 additions & 1 deletion cmd/kor/hpas.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/cobra"

"github.com/yonahd/kor/pkg/clusterconfig"
"github.com/yonahd/kor/pkg/kor"
"github.com/yonahd/kor/pkg/utils"
)
Expand All @@ -15,7 +16,7 @@ var hpaCmd = &cobra.Command{
Short: "Gets unused hpas",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
clientset := kor.GetKubeClient(kubeconfig)
clientset := clusterconfig.GetKubeClient(kubeconfig)

if response, err := kor.GetUnusedHpas(filterOptions, clientset, outputFormat, opts); err != nil {
fmt.Println(err)
Expand Down
Loading
Loading