-
Notifications
You must be signed in to change notification settings - Fork 3
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
Decrease number of logs during cnf_install and cnf_uninstall #15
Open
rafal-lal
wants to merge
1
commit into
main
Choose a base branch
from
rlal-cnf_install_decrease_logs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
|
||
module ShellCmd | ||
def self.run(cmd, log_prefix, force_output=false) | ||
Log.info { "#{log_prefix} command: #{cmd}" } | ||
Log.debug { "#{log_prefix} command: #{cmd}" } | ||
status = Process.run( | ||
cmd, | ||
shell: true, | ||
|
@@ -36,7 +36,7 @@ | |
|
||
# Don't have to output log line if stderr is empty | ||
if stderr.to_s.size > 1 | ||
Log.info { "#{log_prefix} stderr: #{stderr.to_s}" } | ||
Log.warn { "#{log_prefix} stderr: #{stderr.to_s}" } | ||
end | ||
{status: status, output: output.to_s, error: stderr.to_s} | ||
end | ||
|
@@ -518,7 +518,7 @@ | |
true | ||
end | ||
end | ||
sleep 1 | ||
retries = retries + 1 | ||
end | ||
if nodes == empty_json_any | ||
|
@@ -922,13 +922,13 @@ | |
case kind.downcase | ||
when "pod" | ||
pod_ready = KubectlClient::Get.pod_status(pod_name_prefix: resource_name, namespace: namespace, kubeconfig: kubeconfig).split(",")[2] | ||
Log.info { "pod_ready: #{pod_ready}"} | ||
return pod_ready == "true" | ||
|
||
when "replicaset", "deployment", "statefulset" | ||
desired = replica_count(kind, namespace, resource_name, "{.status.replicas}", kubeconfig) | ||
unavailable = replica_count(kind, namespace, resource_name, "{.status.unavailableReplicas}", kubeconfig) | ||
current = replica_count(kind, namespace, resource_name, "{.status.readyReplicas}", kubeconfig) | ||
Log.info { "current_replicas: #{current}, desired_replicas: #{desired}, unavailable_replicas: #{unavailable}" } | ||
Log.trace { "current_replicas: #{current}, desired_replicas: #{desired}, unavailable_replicas: #{unavailable}" } | ||
|
||
ready = current == desired | ||
|
||
|
@@ -944,7 +944,7 @@ | |
desired = replica_count(kind, namespace, resource_name, "{.status.desiredNumberScheduled}", kubeconfig) | ||
current = replica_count(kind, namespace, resource_name, "{.status.numberAvailable}", kubeconfig) | ||
unavailable = replica_count(kind, namespace, resource_name, "{.status.unavailableReplicas}", kubeconfig) | ||
Log.info { "current_replicas: #{current}, desired_replicas: #{desired}" } | ||
Log.trace { "current_replicas: #{current}, desired_replicas: #{desired}" } | ||
|
||
ready = current == desired | ||
|
||
|
@@ -960,7 +960,7 @@ | |
desired = replica_count(kind, namespace, resource_name, "{.status.replicas}", kubeconfig) | ||
current = replica_count(kind, namespace, resource_name, "{.status.readyReplicas}", kubeconfig) | ||
unavailable = replica_count(kind, namespace, resource_name, "{.status.unavailableReplicas}", kubeconfig) | ||
Log.info { "current_replicas: #{current}, desired_replicas: #{desired}" } | ||
Log.trace { "current_replicas: #{current}, desired_replicas: #{desired}" } | ||
|
||
ready = current == desired | ||
|
||
|
@@ -1017,7 +1017,7 @@ | |
key_created = false | ||
value_matched = false | ||
until (key_created && value_matched) || second_count > wait_count.to_i | ||
sleep 3 | ||
namespace = resource.dig?("metadata", "namespace") | ||
if namespace | ||
resource = KubectlClient::Get.resource(resource["kind"].as_s, resource.dig("metadata", "name").as_s) | ||
|
@@ -1059,32 +1059,36 @@ | |
is_ready = resource_ready?(kind, namespace, resource_name, kubeconfig) | ||
|
||
until is_ready || second_count > wait_count | ||
Log.info { "KubectlClient::Get.resource_wait_for_install attempt: #{second_count}; is_ready: #{is_ready}" } | ||
if second_count % RESOURCE_WAIT_LOG_INTERVAL == 0 | ||
Log.info { "KubectlClient::Get.resource_wait_for_install seconds elapsed: #{second_count}; is_ready: #{is_ready}" } | ||
end | ||
|
||
sleep 1 | ||
is_ready = resource_ready?(kind, namespace, resource_name, kubeconfig) | ||
second_count = second_count + 1 | ||
second_count += 1 | ||
end | ||
|
||
Log.info { "is_ready kind/resource #{kind}, #{resource_name}: #{is_ready}" } | ||
return is_ready | ||
end | ||
|
||
#TODO add parameter and functionality that checks for individual pods to be successfully terminated | ||
# TODO add parameter and functionality that checks for individual pods to be successfully terminated | ||
def self.resource_wait_for_uninstall(kind : String, resource_name : String, wait_count : Int32 = 180, namespace : String | Nil = "default") | ||
# Not all cnfs have #{kind}. some have only a pod. need to check if the | ||
# passed in pod has a deployment, if so, watch the deployment. Otherwise watch the pod | ||
# Not all CNFs have #{kind}. Some have only a pod. Need to check if the | ||
# passed in pod has a deployment, if so, watch the deployment. Otherwise watch the pod. | ||
Log.info { "resource_wait_for_uninstall kind: #{kind} resource_name: #{resource_name} namespace: #{namespace}" } | ||
empty_hash = {} of String => JSON::Any | ||
second_count = 0 | ||
|
||
resource_uninstalled = KubectlClient::Get.resource(kind, resource_name, namespace) | ||
Log.debug { "resource_uninstalled #{resource_uninstalled}" } | ||
until (resource_uninstalled && resource_uninstalled.as_h == empty_hash) || second_count > wait_count | ||
Log.info { "second_count = #{second_count}" } | ||
if second_count % RESOURCE_WAIT_LOG_INTERVAL == 0 | ||
Log.info { "KubectlClient::Get.resource_wait_for_uninstall seconds elapsed: #{second_count}" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
end | ||
|
||
sleep 1 | ||
resource_uninstalled = KubectlClient::Get.resource(kind, resource_name, namespace) | ||
Log.debug { "resource_uninstalled #{resource_uninstalled}" } | ||
second_count = second_count + 1 | ||
second_count += 1 | ||
end | ||
|
||
if (resource_uninstalled && resource_uninstalled.as_h == empty_hash) | ||
|
@@ -1142,16 +1146,17 @@ | |
# Check if the desired replicas is equal to the ready replicas. | ||
# Return true if yes. | ||
describe = Totem.from_yaml(resp) | ||
Log.info { "desired_is_available describe: #{describe.inspect}" } | ||
# TODO (rafal-lal): not sure if that is needed at all, will revisit later | ||
Log.trace { "desired_is_available describe: #{describe.inspect}" } | ||
desired_replicas = describe.get("status").as_h["replicas"].as_i | ||
Log.info { "desired_is_available desired_replicas: #{desired_replicas}" } | ||
Log.trace { "desired_is_available desired_replicas: #{desired_replicas}" } | ||
ready_replicas = describe.get("status").as_h["readyReplicas"]? | ||
unless ready_replicas.nil? | ||
ready_replicas = ready_replicas.as_i | ||
else | ||
ready_replicas = 0 | ||
end | ||
Log.info { "desired_is_available ready_replicas: #{ready_replicas}" } | ||
Log.trace { "desired_is_available ready_replicas: #{ready_replicas}" } | ||
return desired_replicas == ready_replicas | ||
when "pod" | ||
# Check if the pod status is ready. | ||
|
@@ -1546,4 +1551,3 @@ | |
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
module KubectlClient | ||
DEFAULT_LOCAL_BINARY_PATH = "tools/git/linux-amd64/docker" | ||
BASE_CONFIG = "./config.yml" | ||
RESOURCE_WAIT_LOG_INTERVAL = 10 | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could this be scoped through
Log.for
instead with a clearer message? TheKubectlClient::Get.resource_wait_for_install
part is a bit jarring.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.
I'm working on the log refactor in other PR, wanted to post a quick fix here.