-
Notifications
You must be signed in to change notification settings - Fork 96
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
add --exclude-namespace #30
Conversation
@yonahd Take a look when you have time. Thanks! |
Hopefully over the weekend I'll get to it. |
I will fix these in next few days. |
11b342b
to
2864b4d
Compare
@yonahd Please review again, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
2 small comments
2864b4d
to
1c583bf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest something like this
func SetNamespaceList(kubeClient *kubernetes.Clientset) []string {
namespaces := make([]string, 0)
includeNamespaceMap := make(map[string]struct{})
excludeNamespaceMap := make(map[string]struct{})
includeNamespaces := strings.Split(namespaceLists.IncludeListStr, ",")
excludeNamespaces := strings.Split(namespaceLists.ExcludeListStr, ",")
for _, ns := range excludeNamespaces {
excludeNamespaceMap[ns] = struct{}{}
}
for _, ns := range includeNamespaces {
includeNamespaceMap[ns] = struct{}{}
}
namespaceList, err := kubeClient.CoreV1().Namespaces().List(context.TODO(), metav1.ListOptions{})
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to retrieve namespaces: %v\n", err)
os.Exit(1)
}
if includeNamespaces[0] == "" {
if excludeNamespaces[0] != "" {
for _, ns := range namespaceList.Items {
if _, exists := excludeNamespaceMap[ns.Name]; !exists {
namespaces = append(namespaces, ns.Name)
}
}
return namespaces
}
for _, ns := range namespaceList.Items {
namespaces = append(namespaces, ns.Name)
}
return namespaces
}
if includeNamespaces[0] != "" {
fmt.Printf("Exclude namespaces can't be used together with include namespaces. Ignoring exclude flag\n")
}
namespaceExists := false
for includeNamespace := range includeNamespaceMap {
namespaceExists = false
for _, ns := range namespaceList.Items {
if ns.Name == includeNamespace {
namespaces = append(namespaces, ns.Name)
namespaceExists = true
break
}
}
if !namespaceExists {
fmt.Printf("Namespace '%s' from include list doesn't exist\n", includeNamespace)
}
}
return namespaces
}
Hey @linrl3 |
Yes. I've been busy in the past few days. I think I can write some code on the weekend. |
I think we should keep @yonahd How do you think? |
Yeah. It's my mistake in the declaration. |
1c583bf
to
0254d5f
Compare
0254d5f
to
a700ed3
Compare
Please have look when you are free @yonahd . I push again to:
I just run kor and get some output here:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
To solve #29