|
45 | 45 | #define FLB_KUBE_META_INIT_CONTAINER_STATUSES_KEY_LEN \ |
46 | 46 | (sizeof(FLB_KUBE_META_INIT_CONTAINER_STATUSES_KEY) - 1) |
47 | 47 | #define FLB_KUBE_TOKEN_BUF_SIZE 8192 /* 8KB */ |
48 | | -#define FLB_KUBE_TOKEN_TTL 600 /* 10 minutes */ |
49 | 48 |
|
50 | 49 | static int file_to_buffer(const char *path, |
51 | 50 | char **out_buf, size_t *out_size) |
@@ -161,17 +160,15 @@ static int get_http_auth_header(struct flb_kube *ctx) |
161 | 160 | if (ret == -1) { |
162 | 161 | flb_plg_warn(ctx->ins, "failed to run command %s", ctx->kube_token_command); |
163 | 162 | } |
164 | | - ctx->kube_token_create = time(NULL); |
165 | | - } |
| 163 | + } |
166 | 164 | else { |
167 | 165 | ret = file_to_buffer(ctx->token_file, &tk, &tk_size); |
168 | 166 | if (ret == -1) { |
169 | 167 | flb_plg_warn(ctx->ins, "cannot open %s", FLB_KUBE_TOKEN); |
170 | 168 | } |
171 | | - /* Token from token file will not expire */ |
172 | | - /* Set the creation time to 0 to aviod refresh */ |
173 | | - ctx->kube_token_create = 0; |
| 169 | + flb_plg_info(ctx->ins, " token updated", FLB_KUBE_TOKEN); |
174 | 170 | } |
| 171 | + ctx->kube_token_create = time(NULL); |
175 | 172 |
|
176 | 173 | /* Token */ |
177 | 174 | if (ctx->token != NULL) { |
@@ -210,19 +207,17 @@ static int refresh_token_if_needed(struct flb_kube *ctx) |
210 | 207 | int expired = 0; |
211 | 208 | int ret; |
212 | 209 |
|
213 | | - if (ctx->kube_token_command != NULL) { |
214 | | - if (ctx->kube_token_create > 0) { |
215 | | - if (time(NULL) > ctx->kube_token_create + FLB_KUBE_TOKEN_TTL) { |
216 | | - expired = FLB_TRUE; |
217 | | - } |
| 210 | + if (ctx->kube_token_create > 0) { |
| 211 | + if (time(NULL) > ctx->kube_token_create + ctx->kube_token_ttl) { |
| 212 | + expired = FLB_TRUE; |
218 | 213 | } |
219 | | - |
220 | | - if (expired || ctx->kube_token_create == 0) { |
221 | | - ret = get_http_auth_header(ctx); |
222 | | - if (ret == -1) { |
223 | | - flb_plg_warn(ctx->ins, "failed to set http auth header"); |
224 | | - return -1; |
225 | | - } |
| 214 | + } |
| 215 | + |
| 216 | + if (expired || ctx->kube_token_create == 0) { |
| 217 | + ret = get_http_auth_header(ctx); |
| 218 | + if (ret == -1) { |
| 219 | + flb_plg_warn(ctx->ins, "failed to set http auth header"); |
| 220 | + return -1; |
226 | 221 | } |
227 | 222 | } |
228 | 223 |
|
|
0 commit comments