-
Notifications
You must be signed in to change notification settings - Fork 18
NETOBSERV-1905 Query UDNs without flows #688
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
base: main
Are you sure you want to change the base?
Changes from all commits
01c476e
25bcf22
b834c19
b566e33
96a8ce4
f5f922b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package handler | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/netobserv/network-observability-console-plugin/pkg/kubernetes/auth" | ||
"github.com/netobserv/network-observability-console-plugin/pkg/kubernetes/resources" | ||
"github.com/netobserv/network-observability-console-plugin/pkg/utils" | ||
|
||
kerr "k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
func (h *Handlers) GetUDNIdss(ctx context.Context) func(w http.ResponseWriter, r *http.Request) { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
token, err := auth.GetUserToken(r.Header) | ||
if err != nil { | ||
writeError(w, http.StatusInternalServerError, err.Error()) | ||
} | ||
|
||
cudns, err := resources.List(ctx, token, schema.GroupVersionResource{ | ||
Group: "k8s.ovn.org", | ||
Version: "v1", | ||
Resource: "clusteruserdefinednetworks", | ||
}) | ||
if err != nil { | ||
var k8sErr *kerr.StatusError | ||
if errors.As(err, &k8sErr) { | ||
writeError(w, int(k8sErr.ErrStatus.Code), err.Error()) | ||
} else { | ||
writeError(w, http.StatusInternalServerError, err.Error()) | ||
} | ||
} | ||
|
||
udns, err := resources.List(ctx, token, schema.GroupVersionResource{ | ||
Group: "k8s.ovn.org", | ||
Version: "v1", | ||
Resource: "userdefinednetworks", | ||
}) | ||
if err != nil { | ||
var k8sErr *kerr.StatusError | ||
if errors.As(err, &k8sErr) { | ||
writeError(w, int(k8sErr.ErrStatus.Code), err.Error()) | ||
} else { | ||
writeError(w, http.StatusInternalServerError, err.Error()) | ||
} | ||
} | ||
|
||
values := []string{} | ||
for _, cudn := range cudns { | ||
md := cudn.Object["metadata"].(map[string]interface{}) | ||
values = append(values, fmt.Sprintf("%s", md["name"])) | ||
} | ||
for _, udn := range udns { | ||
md := udn.Object["metadata"].(map[string]interface{}) | ||
values = append(values, fmt.Sprintf("%s.%s", md["namespace"], md["name"])) | ||
} | ||
writeJSON(w, http.StatusOK, utils.NonEmpty(utils.Dedup(values))) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
|
||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/client-go/dynamic" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Relying on |
||
"k8s.io/client-go/rest" | ||
) | ||
|
||
func List(ctx context.Context, token string, gvr schema.GroupVersionResource) ([]unstructured.Unstructured, error) { | ||
config, err := rest.InClusterConfig() | ||
if err != nil { | ||
return nil, err | ||
} | ||
config.BearerToken = token | ||
config.BearerTokenFile = "" | ||
|
||
dynamicClient, err := dynamic.NewForConfig(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Retrieve the custom resource | ||
list, err := dynamicClient.Resource(gvr).List(ctx, v1.ListOptions{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return list.Items, err | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
?
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.
Actually, I commited this but I will revert it as the
metadata
can contains other things than strings such as boolean