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

Helm secret exception #20

Merged
merged 5 commits into from
Aug 8, 2023
Merged
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
5 changes: 2 additions & 3 deletions cmd/kor/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ var rootCmd = &cobra.Command{
Short: "kor - a CLI to to discover unused Kubernetes resources",
Long: `kor is a CLI to to discover unused Kubernetes resources
kor can currently discover unused configmaps and secrets`,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
cmd.Help()
}

},
}

Expand Down
9 changes: 8 additions & 1 deletion pkg/kor/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
"k8s.io/utils/strings/slices"
)

var exceptionSecretTypes = []string{
`helm.sh/release.v1`,
}

func getSATokens(clientset *kubernetes.Clientset, namespace string) ([]string, error) {
// Retrieve secrets in all namespaces with type "kubernetes.io/service-account-token"
secrets, err := clientset.CoreV1().Secrets(namespace).List(context.TODO(), metav1.ListOptions{
Expand Down Expand Up @@ -106,7 +111,9 @@ func retrieveSecretNames(kubeClient *kubernetes.Clientset, namespace string) ([]
}
names := make([]string, 0, len(secrets.Items))
for _, secret := range secrets.Items {
names = append(names, secret.Name)
if !slices.Contains(exceptionSecretTypes, string(secret.Type)) {
names = append(names, secret.Name)
}
}
return names, nil
}
Expand Down
Loading