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

in_kubernetes_events: allow listening to a single namespace. #7560

Merged
merged 1 commit into from
Jul 3, 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
19 changes: 16 additions & 3 deletions plugins/in_kubernetes_events/kubernetes_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,19 @@ static struct flb_http_client *make_event_api_request(struct k8s_events *ctx,
struct flb_http_client *c;


if (continue_token == NULL && ctx->limit_request == 0) {
if (continue_token == NULL && ctx->limit_request == 0 && ctx->namespace == NULL) {
return flb_http_client(u_conn, FLB_HTTP_GET, K8S_EVENTS_KUBE_API_URI,
NULL, 0, ctx->api_host, ctx->api_port, NULL, 0);
NULL, 0, ctx->api_host, ctx->api_port, NULL, 0);
}

if (ctx->namespace == NULL) {
url = flb_sds_create(K8S_EVENTS_KUBE_API_URI);
} else {
url = flb_sds_create_size(strlen(K8S_EVENTS_KUBE_NAMESPACE_API_URI) +
strlen(ctx->namespace));
flb_sds_printf(&url, K8S_EVENTS_KUBE_NAMESPACE_API_URI, ctx->namespace);
}

url = flb_sds_create(K8S_EVENTS_KUBE_API_URI);
flb_sds_cat_safe(&url, "?", 1);
if (ctx->limit_request) {
if (continue_token != NULL) {
Expand Down Expand Up @@ -874,6 +881,12 @@ static struct flb_config_map config_map[] = {
"kubernetes retention time for events. Default: 1h"
},

{
FLB_CONFIG_MAP_STR, "kube_namespace", NULL,
0, FLB_TRUE, offsetof(struct k8s_events, namespace),
"kubernetes namespace to get events from, gets event from all namespaces by default."
},

#ifdef FLB_HAVE_SQLDB
{
FLB_CONFIG_MAP_STR, "db", NULL,
Expand Down
1 change: 1 addition & 0 deletions plugins/in_kubernetes_events/kubernetes_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct k8s_events {
int tls_debug;
int tls_verify;
int kube_token_ttl;
flb_sds_t namespace;

/* API Server end point */
char kube_url[1024];
Expand Down
5 changes: 4 additions & 1 deletion plugins/in_kubernetes_events/kubernetes_events_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
/* Kubernetes API server info */
#define K8S_EVENTS_KUBE_API_HOST "kubernetes.default.svc"
#define K8S_EVENTS_KUBE_API_PORT 443
#define K8S_EVENTS_KUBE_API_URI "/api/v1/events/"
// /apis/events.k8s.io/v1/events
// /apis/events.k8s.io/v1/namespaces/{namespace}/events
#define K8S_EVENTS_KUBE_API_URI "/api/v1/events"
#define K8S_EVENTS_KUBE_NAMESPACE_API_URI "/api/v1/namespaces/%s/events"

/* secrets */
#define K8S_EVENTS_KUBE_TOKEN "/var/run/secrets/kubernetes.io/serviceaccount/token"
Expand Down