membphis commented on code in PR #12057:
URL: https://github.com/apache/apisix/pull/12057#discussion_r2006728770


##########
apisix/discovery/kubernetes/init.lua:
##########
@@ -283,6 +284,45 @@ local function read_env(key)
     return key
 end
 
+local function read_token(token_file)
+    local token, err = util.read_file(token_file)
+    if err then
+        return nil, err
+    end
+
+    -- remove possible extra whitespace
+    local trimmed_token = token:gsub("%s+", "")
+    return trimmed_token
+end
+
+
+local function update_token(handle)
+    if not handle.apiserver.token_file or handle.apiserver.token_file == "" 
then
+        return
+    end
+
+    local token_file_path = handle.apiserver.token_file
+    local attributes, err = lfs.attributes(token_file_path)
+    if not attributes then
+        core.log.error("failed to fetch ", token_file_path, " attributes: ", 
err)
+        return
+    end
+
+    local last_modification_time = attributes.modification
+    if handle.token_file_mtime == last_modification_time then
+        return
+    end
+
+    local token, err = read_token(token_file_path)
+    if err then
+        return nil, err

Review Comment:
   we only can choose one of them:
   
   ```
   if not attributes then
           core.log.error("failed to fetch ", token_file_path, " attributes: ", 
err)
           return
       end
   ```
   
   ```
   if err then
           return nil, err
   end



##########
apisix/discovery/kubernetes/init.lua:
##########
@@ -283,6 +284,45 @@ local function read_env(key)
     return key
 end
 
+local function read_token(token_file)
+    local token, err = util.read_file(token_file)
+    if err then
+        return nil, err
+    end
+
+    -- remove possible extra whitespace
+    local trimmed_token = token:gsub("%s+", "")

Review Comment:
   waiting



##########
apisix/discovery/kubernetes/init.lua:
##########
@@ -283,6 +284,45 @@ local function read_env(key)
     return key
 end
 
+local function read_token(token_file)
+    local token, err = util.read_file(token_file)
+    if err then
+        return nil, err
+    end
+
+    -- remove possible extra whitespace
+    local trimmed_token = token:gsub("%s+", "")
+    return trimmed_token
+end
+
+
+local function update_token(handle)
+    if not handle.apiserver.token_file or handle.apiserver.token_file == "" 
then
+        return

Review Comment:
   for `succ` or `fail`, we should return different value



##########
apisix/discovery/kubernetes/init.lua:
##########
@@ -283,6 +284,45 @@ local function read_env(key)
     return key
 end
 
+local function read_token(token_file)
+    local token, err = util.read_file(token_file)
+    if err then
+        return nil, err
+    end
+
+    -- remove possible extra whitespace
+    local trimmed_token = token:gsub("%s+", "")
+    return trimmed_token
+end
+
+
+local function update_token(handle)
+    if not handle.apiserver.token_file or handle.apiserver.token_file == "" 
then
+        return
+    end
+
+    local token_file_path = handle.apiserver.token_file
+    local attributes, err = lfs.attributes(token_file_path)
+    if not attributes then
+        core.log.error("failed to fetch ", token_file_path, " attributes: ", 
err)
+        return
+    end
+
+    local last_modification_time = attributes.modification
+    if handle.token_file_mtime == last_modification_time then
+        return
+    end
+
+    local token, err = read_token(token_file_path)
+    if err then
+        return nil, err
+    end
+
+    handle.apiserver.token = token
+    handle.token_file_mtime = last_modification_time
+    core.log.warn("kubernetes service account token has been updated")

Review Comment:
   use `log.info`、`log.notice` is suitable



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to