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

Chef 11169 optimize k8s container connection v2 #22

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

sathish-progress
Copy link
Contributor

Optimise the Persistent connection to K8s container

Description

  • Uses PTY to open a pseudo terminal with persistent connection to a K8s Container
  • User Kubectl exec with shell to login to pod for an interactive session
  • Keeps the session for the whole process and ability to reconnect

Related Issue

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New content (non-breaking change)
  • Breaking change (a content change which would break existing functionality or processes)

Checklist:

  • I have read the CONTRIBUTING document.

This allows to use only single session

Signed-off-by: Sathish Babu <[email protected]>
Signed-off-by: Sathish Babu <[email protected]>
Signed-off-by: Sathish Babu <[email protected]>
Signed-off-by: Sathish Babu <[email protected]>
Signed-off-by: Sathish Babu <[email protected]>
Signed-off-by: Sathish Babu <[email protected]>
Signed-off-by: Sathish Babu <[email protected]>
Signed-off-by: Sathish Babu <[email protected]>
- set reader, writer and PID
- define reconnect logic
- load session at class level

Signed-off-by: Sathish Babu <[email protected]>
Signed-off-by: Sathish Babu <[email protected]>
Signed-off-by: Sathish Babu <[email protected]>
Signed-off-by: Sathish Babu <[email protected]>
Signed-off-by: Sathish Babu <[email protected]>
Train::Extras::CommandResult.new("", "", 1)
end

private
def strip_ansi_sequences(text)
text.gsub(/\e\[.*?m/, "").gsub(/\e\]0;.*?\a/, "").gsub(/\e\[A/, "").gsub(/\e\[C/, "").gsub(/\e\[K/, "")

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on a
library input
may run slow on strings starting with 'e]0;' and with many repetitions of 'e]0;'.
Train::Extras::CommandResult.new("", "", 1)
end

private
def strip_ansi_sequences(text)
text.gsub(/\e\[.*?m/, "").gsub(/\e\]0;.*?\a/, "").gsub(/\e\[A/, "").gsub(/\e\[C/, "").gsub(/\e\[K/, "")

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on a
library input
may run slow on strings starting with 'e[' and with many repetitions of 'e['.
Train::Extras::CommandResult.new(res.stdout, res.stderr, res.exitstatus)
rescue Errno::ENOENT => _e
def connect
@reader, @writer, @pid = PTY.spawn("kubectl exec --stdin --tty #{@pod} -n #{@namespace} -c #{@container_name} -- /bin/bash")

Check warning

Code scanning / CodeQL

Unsafe shell command constructed from library input Medium

This string construction which depends on
library input
is later used in a
shell command
.
This string construction which depends on
library input
is later used in a
shell command
.
This string construction which depends on
library input
is later used in a
shell command
.
This string construction which depends on
library input
is later used in a
shell command
.
This string construction which depends on
library input
is later used in a
shell command
.
This string construction which depends on
library input
is later used in a
shell command
.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant