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/Support for Argo Rollouts #363

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
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,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.
- `argorollouts` - Gets unused Argo Rolouts for the specified namespace or all namespaces.
- `exporter` - Export Prometheus metrics.
- `version` - Print kor version information.

Expand Down Expand Up @@ -169,7 +170,7 @@ kor [subcommand] --help
| ConfigMaps | ConfigMaps not used in the following places:<br/>- Pods<br/>- Containers<br/>- ConfigMaps used through Volumes<br/>- ConfigMaps used through environment variables | ConfigMaps used by resources which don't explicitly state them in the config.<br/> e.g Grafana dashboards loaded dynamically OPA policies fluentd configs CRD configs |
| Secrets | Secrets not used in the following places:<br/>- Pods<br/>- Containers<br/>- Secrets used through volumes<br/>- Secrets used through environment variables<br/>- Secrets used by Ingress TLS<br/>- Secrets used by ServiceAccounts | Secrets used by resources which don't explicitly state them in the config e.g. secrets used by CRDs |
| Services | Services with no endpoints | |
| Deployments | Deployments with no Replicas | |
| Deployments | Deployments with no Replicas and non existent ArgoRollout Owner (WorkloadRef) | |
| ServiceAccounts | ServiceAccounts unused by Pods<br/>ServiceAccounts unused by roleBinding or clusterRoleBinding | |
| StatefulSets | Statefulsets with no Replicas | |
| Roles | Roles not used in roleBinding | |
Expand All @@ -181,11 +182,12 @@ kor [subcommand] --help
| CRDs | CRDs not used the cluster | |
| Pvs | PVs not bound to a PVC | |
| Pdbs | PDBs not used in Deployments<br/> PDBs not used in StatefulSets | |
| 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 |
| NetworkPolicies | NetworkPolicies with no Pods selected by podSelector or Ingress/Egress rules |
| 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 | |
| NetworkPolicies | NetworkPolicies with no Pods selected by podSelector or Ingress/Egress rules | |
| ArgoRollout | Argo Rollouts with WorkloadRef deployment non existent in cluster | When deployment from Argo Rollouts has deleted, replicasets keep pods alive, attention to this |

### Deleting Unused resources

Expand Down Expand Up @@ -250,6 +252,7 @@ Unused resources in namespace: "test"
| 6 | ConfigMap | unused-cm | ConfigMap is not used in any pod or container |
| 7 | ServiceAccount | my-service-account2 | ServiceAccount is not in use |
| 8 | Pdb | my-pdb | Pdb is not referencing any deployments or statefulsets |
| 9 | ArgoRollout | rollout-ref-deployment | Rollout has no deployments |
+---+----------------+----------------------------------------------+--------------------------------------------------------+
```

Expand Down Expand Up @@ -299,13 +302,14 @@ Unused resources in namespace: "ns1"
| 4 | Deployment | deploy1 |
+---+---------------+--------------------+
Unused resources in namespace: "ns2"
+---+---------------+--------------------+
| # | RESOURCE TYPE | RESOURCE NAME |
+---+---------------+--------------------+
| 1 | ReplicaSet | deploy2-79f48888c6 |
| 2 | ConfigMap | cm3 |
| 3 | Deployment | deploy2 |
+---+---------------+--------------------+
+---+---------------+-------------------------+
| # | RESOURCE TYPE | RESOURCE NAME |
+---+---------------+-------------------------+
| 1 | ReplicaSet | deploy2-79f48888c6 |
| 2 | ConfigMap | cm3 |
| 3 | Deployment | deploy2 |
| 4 | ArgoRollout | rollout-ref-deployment |
+---+---------------+-------------------------+
```

## In Cluster Usage
Expand Down
2 changes: 2 additions & 0 deletions charts/kor/templates/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ rules:
- replicasets
- daemonsets
- networkpolicies
- rollouts
verbs:
- get
- list
Expand Down Expand Up @@ -58,6 +59,7 @@ rules:
- replicasets
- daemonsets
- networkpolicies
- rollouts
{{/* cluster-scoped resources */}}
- namespaces
- clusterroles
Expand Down
3 changes: 2 additions & 1 deletion cmd/kor/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ var allCmd = &cobra.Command{
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
clientset := kor.GetKubeClient(kubeconfig)
clientsetargorollouts := kor.GetKubeClientArgoRollouts(kubeconfig)
apiExtClient := kor.GetAPIExtensionsClient(kubeconfig)
dynamicClient := kor.GetDynamicClient(kubeconfig)

if response, err := kor.GetUnusedAll(filterOptions, clientset, apiExtClient, dynamicClient, outputFormat, opts); err != nil {
if response, err := kor.GetUnusedAll(filterOptions, clientset, clientsetargorollouts, apiExtClient, dynamicClient, outputFormat, opts); err != nil {
fmt.Println(err)
} else {
utils.PrintLogo(outputFormat)
Expand Down
31 changes: 31 additions & 0 deletions cmd/kor/argorollouts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package kor

import (
"fmt"

"github.com/spf13/cobra"

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

var argoRolloutsCmd = &cobra.Command{
Use: "argorollouts",
Aliases: []string{"argorollouts"},
Short: "Gets unused argo rollouts",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
clientset := kor.GetKubeClient(kubeconfig)
clientsetargorollouts := kor.GetKubeClientArgoRollouts(kubeconfig)
if response, err := kor.GetUnusedArgoRollouts(filterOptions, clientset, clientsetargorollouts, outputFormat, opts); err != nil {
fmt.Println(err)
} else {
utils.PrintLogo(outputFormat)
fmt.Println(response)
}
},
}

func init() {
rootCmd.AddCommand(argoRolloutsCmd)
}
3 changes: 2 additions & 1 deletion cmd/kor/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ var deployCmd = &cobra.Command{
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
clientset := kor.GetKubeClient(kubeconfig)
if response, err := kor.GetUnusedDeployments(filterOptions, clientset, outputFormat, opts); err != nil {
clientsetargorollouts := kor.GetKubeClientArgoRollouts(kubeconfig)
if response, err := kor.GetUnusedDeployments(filterOptions, clientset, clientsetargorollouts, outputFormat, opts); err != nil {
fmt.Println(err)
} else {
utils.PrintLogo(outputFormat)
Expand Down
3 changes: 2 additions & 1 deletion cmd/kor/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ var exporterCmd = &cobra.Command{
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
clientset := kor.GetKubeClient(kubeconfig)
clientsetargorollouts := kor.GetKubeClientArgoRollouts(kubeconfig)
apiExtClient := kor.GetAPIExtensionsClient(kubeconfig)
dynamicClient := kor.GetDynamicClient(kubeconfig)

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

},
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/kor/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ var rootCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
resourceNames := args[0]
clientset := kor.GetKubeClient(kubeconfig)
clientsetargorollouts := kor.GetKubeClientArgoRollouts(kubeconfig)
apiExtClient := kor.GetAPIExtensionsClient(kubeconfig)
dynamicClient := kor.GetDynamicClient(kubeconfig)

if response, err := kor.GetUnusedMulti(resourceNames, filterOptions, clientset, apiExtClient, dynamicClient, outputFormat, opts); err != nil {
if response, err := kor.GetUnusedMulti(resourceNames, filterOptions, clientset, clientsetargorollouts, apiExtClient, dynamicClient, outputFormat, opts); err != nil {
fmt.Println(err)
} else {
utils.PrintLogo(outputFormat)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.22.0
toolchain go1.22.2

require (
github.com/argoproj/argo-rollouts v1.7.2
github.com/fatih/color v1.17.0
github.com/olekukonko/tablewriter v0.0.5
github.com/prometheus/client_golang v1.20.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/argoproj/argo-rollouts v1.7.2 h1:faDUH/qePerYRwsrHfVzNQkhjGBgXIiVYdVK8824kMo=
github.com/argoproj/argo-rollouts v1.7.2/go.mod h1:Te4HrUELxKiBpK8lgk77o4gTa3mv8pXCd8xdPprKrbs=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
Expand Down
Loading
Loading