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

Decrease number of logs during cnf_install and cnf_uninstall #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions kubectl_client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -518,7 +518,7 @@
true
end
end
sleep 1

Check warning on line 521 in kubectl_client.cr

View workflow job for this annotation

GitHub Actions / build

Deprecated ::sleep. Use `::sleep(Time::Span)` instead
retries = retries + 1
end
if nodes == empty_json_any
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -1017,7 +1017,7 @@
key_created = false
value_matched = false
until (key_created && value_matched) || second_count > wait_count.to_i
sleep 3

Check warning on line 1020 in kubectl_client.cr

View workflow job for this annotation

GitHub Actions / build

Deprecated ::sleep. Use `::sleep(Time::Span)` instead
namespace = resource.dig?("metadata", "namespace")
if namespace
resource = KubectlClient::Get.resource(resource["kind"].as_s, resource.dig("metadata", "name").as_s)
Expand Down Expand Up @@ -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}" }
Copy link

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? The KubectlClient::Get.resource_wait_for_install part is a bit jarring.

Copy link
Collaborator Author

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.

end

sleep 1

Check warning on line 1066 in kubectl_client.cr

View workflow job for this annotation

GitHub Actions / build

Deprecated ::sleep. Use `::sleep(Time::Span)` instead
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}" }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end

sleep 1

Check warning on line 1089 in kubectl_client.cr

View workflow job for this annotation

GitHub Actions / build

Deprecated ::sleep. Use `::sleep(Time::Span)` instead
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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1546,4 +1551,3 @@
end
end
end

2 changes: 1 addition & 1 deletion shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2.0
shards:
docker_client:
git: https://github.com/cnf-testsuite/docker_client.git
version: 0.1.0+git.commit.32dacefbc3dfcf98c8126ff793c97a3038e9b122
version: 1.0.0

popcorn:
git: https://github.com/icyleaf/popcorn.git
Expand Down
1 change: 1 addition & 0 deletions src/constants.cr
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
Loading