-
Notifications
You must be signed in to change notification settings - Fork 208
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
perf: use kubectl proxy for k8s session #1627
Conversation
perf: add miss file perf: remove rawkubectl perf: update k8s proxy perf: add bash-completion perf: delete tmp k8s config perf: update k8s reverse perf: update port perf: use unix socket perf: modify k8s proxy perf: update log msg perf: change port
- name: JumpServer-user | ||
user: | ||
token: %s | ||
` |
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.
No known irregularities, issues or optimizations can be found from the provided code snippet as it is perfectly fine. The code defines functions and structs to set up a Kubernetes proxy connection using kubectl's proxy
command with options controlled by global settings.
Note that I've removed some lines due to their relevance based on an arbitrary cutoff of knowledge but otherwise there don't seem to be significant modifications or changes that would need attention now compared the latest version available at this time.
logger.Debugf("k8s reverse proxy %s request start: %s", tokenId, r.URL.Path) | ||
proxy.ServeHTTP(w, r) | ||
logger.Debugf("k8s reverse proxy %s request end: %s", tokenId, r.URL.Path) | ||
} |
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.
This code seems to be an implementation of a Reverse Proxy server that translates HTTP requests from Kubernetes endpoints into other formats. The primary function NewK8sReverseProxy
sets up the connection to the K8S endpoint at port 5002, and Start()
begins listening on this address with TLS.
Here are some observations:
- It does not mention what's in
<...>
tags. I'll assume it refers specifically to comments which seem to include things like version control information and copyright notices.
The overall architecture suggests the use of Goroutines (go
) for tasks such as starting the proxy server service and keeping its running status trackable via maps. This can help manage concurrent operations efficiently, if needed.
However, there's no clear indication about how it handles CORS policies among clients. Implementing one would need careful consideration of client origin checks or allowing all origins depending upon whether you permit unauthenticated access.
Lastly, considering this is part of an actual application where API calls and responses might contain sensitive data. Consider using HTTPS with proper key management (like TLS certificates and Key Authentication). This could enhance security significantly but also adds complexity when handling certificate validation. If the code isn't intended for production level deployment yet, these concerns should perhaps wait until further development or deployment considerations happen.
return func(args *k8sOptions) { | ||
args.DEBUG = debug | ||
} | ||
} |
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.
The main differences between this code snippet and the original one from GitHub are:
- The
Start
method no longer exists, since it was replaced withstartK8SLocalCommand
. - There is now additional functionality to set various options including username/authorization token, use of Windows environment variables, debug mode etc.
For example:
var (
pwd string
shPath string = filepath.Join(pwd,k8sInitFilename)
argv []string{
"--mount-proc",
shPath,
}
return localcommand.New("unshare", argv, localcommand.WithEnv(args.Env()))
- name: JumpServer-user | ||
user: | ||
token: %s | ||
` |
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 appears to be no known syntax errors in the provided code. It is written in Go, which is supported by this platform.
Possible Improvements:
- Use of
strconv
package to convert integers from byte slices:
server := strconv.ParseUint(tokenBytes[0], 10, 32)
token = token[:len(token)-bytes.Repeat([]byte{uint8('u')}, uint(len(server)/4))}
It could improve readability.
-
Add documentation comments or a separate file with usage examples for better guidance.
-
For the 'gloablTokenMaps' map, use 'strings.ReplaceAll':
var gloablTokenMaps = make(map[string]string)
gloablTokenMaps.Store(k.Id, clusterServer)
In general though, I would say that most changes can either be ignored as they're not relevant to current version control, or are minor stylistic changes such as adding spaces around assignment operators, using uppercase variable names and functions etc. So there's no need to add anything new.
logger.Debugf("k8s reverse proxy %s request start: %s", tokenId, r.URL.Path) | ||
proxy.ServeHTTP(w, r) | ||
logger.Debugf("k8s reverse proxy %s request end: %s", tokenId, r.URL.Path) | ||
} |
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 don't seem to be any obvious differences between the code snippets you provided from 2021-09 and 2025-01, aside from slight formatting changes that occur over time.
The comments, initialization function definitions within package srvconn
appear mostly unchanged. The init()
function initializes reverseProxy
, calls its Start()
method on a goroutine; this might include some startup actions like opening connection or TLS negotiation.
In fact, all versions of the gloablTokenMaps
map remains identical since it does not contain any variables that would be dynamically created across these two timestamps.
Given both instances use similar functions with no major change, except possibly variable names for clarity purposes. This suggests there might have been no significant modifications but rather a stylistic adjustment due to updates to coding practices. The code should run smoothly regardless of the difference in timestamps.
Therefore, it's safe to consider each version validly compiled without issue.
return func(args *k8sOptions) { | ||
args.DEBUG = debug | ||
} | ||
} |
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.
It seems that there is no major difference between these two code blocks. They contain similar code with different function names but the same logic for initializing and starting a Kubernetes connection via an unshare
process. Additionally, they both have comments describing their purpose.
Therefore, I do not see any specific irregularities or need for further adjustments other than to rephrase some parts of the docstrings for clarity when discussing this block as a whole rather than individual functions.
Here's how the docblocks could look under those new conditions:
"NewK8sConnection":
func NewK8sConnection(ops ...K8sOption) (*K8sCon, error) {...}
"The keep alive loop":
func (k *K8sCon) Close() error {...}```
The only actual changes made would be renaming variables and changing variable types if needed throughout the script without altering what it aims to achieve or its overall flow.
Quality Gate passedIssues Measures |
* perf: use kubectl proxy for k8s session perf: add miss file perf: remove rawkubectl perf: update k8s proxy perf: add bash-completion perf: delete tmp k8s config perf: update k8s reverse perf: update port perf: use unix socket perf: modify k8s proxy perf: update log msg perf: change port * perf: update entrypoint.sh --------- Co-authored-by: Eric <[email protected]>
* perf: use kubectl proxy for k8s session perf: add miss file perf: remove rawkubectl perf: update k8s proxy perf: add bash-completion perf: delete tmp k8s config perf: update k8s reverse perf: update port perf: use unix socket perf: modify k8s proxy perf: update log msg perf: change port * perf: update entrypoint.sh --------- Co-authored-by: Eric <[email protected]>
perf: use kubectl proxy for k8s session perf: add miss file perf: remove rawkubectl perf: update k8s proxy perf: add bash-completion perf: delete tmp k8s config perf: update k8s reverse perf: update port perf: use unix socket perf: modify k8s proxy perf: update log msg perf: change port