Skip to content

Commit 4ca771d

Browse files
authored
Updates according to cnf-testsuite/kubectl_client#17 (#5)
Updates according to cnf-testsuite/kubectl_client#17 Signed-off-by: Rafal Lal <rafal.lal@tietoevry.com>
1 parent 85e60dd commit 4ca771d

File tree

4 files changed

+38
-23
lines changed

4 files changed

+38
-23
lines changed

shard.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2.0
22
shards:
33
cluster_tools:
44
git: https://github.com/cnf-testsuite/cluster_tools.git
5-
version: 1.0.0
5+
version: 1.0.11
66

77
docker_client:
88
git: https://github.com/cnf-testsuite/docker_client.git
@@ -18,15 +18,15 @@ shards:
1818

1919
helm:
2020
git: https://github.com/cnf-testsuite/helm.git
21-
version: 1.0.1
21+
version: 1.0.5
2222

2323
kernel_introspection:
2424
git: https://github.com/cnf-testsuite/kernel_introspection.git
2525
version: 0.1.0
2626

2727
kubectl_client:
2828
git: https://github.com/cnf-testsuite/kubectl_client.git
29-
version: 1.0.1
29+
version: 1.0.8
3030

3131
popcorn:
3232
git: https://github.com/icyleaf/popcorn.git

shard.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ targets:
1616
dependencies:
1717
kubectl_client:
1818
github: cnf-testsuite/kubectl_client
19-
version: ~> 1.0.0
19+
version: ~> 1.0.8
2020
kernel_introspection:
2121
github: cnf-testsuite/kernel_introspection
2222
version: ~> 0.1.0
2323
cluster_tools:
24-
# path: ../cluster_tools
2524
github: cnf-testsuite/cluster_tools
26-
version: ~> 1.0.0
25+
version: ~> 1.0.11
2726
helm:
2827
github: cnf-testsuite/helm
29-
version: ~> 1.0.0
28+
version: ~> 1.0.5

spec/netstat/k8s_spec.cr

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ require "../../src/netstat/k8s.cr"
88
describe "netstat" do
99
before_all do
1010
begin
11-
KubectlClient::Create.namespace("cnf-testsuite")
12-
rescue e : KubectlClient::Create::AlreadyExistsError
11+
KubectlClient::Apply.namespace("cnf-testsuite")
12+
rescue e : KubectlClient::ShellCMD::AlreadyExistsError
1313
end
1414
ClusterTools.install
1515
end
@@ -19,25 +19,28 @@ describe "netstat" do
1919
release_name = "wordpress"
2020
helm_chart_directory = "sample-cnfs/ndn-multi-db-connections-fail/wordpress"
2121

22-
after_all do
22+
after_all do
2323
resp = Helm.uninstall(release_name)
24-
KubectlClient::Delete.command("pvc/data-wordpress-mariadb-0")
25-
KubectlClient::Delete.command("pvc/wordpress")
24+
begin
25+
KubectlClient::Delete.resource("pvc", "data-wordpress-mariadb-0")
26+
KubectlClient::Delete.resource("pvc", "wordpress")
27+
rescue ex : KubectlClient::ShellCMD::NotFoundError
28+
end
2629
Log.info { resp }
2730
(resp[:status].exit_status == 0).should be_true
2831
end
2932

3033
it "should install" do
3134
helm_install(release_name, helm_chart_directory)
3235
end
33-
36+
3437
it "k8s_netstat should detect multiple pods conected to same db" do
35-
KubectlClient::Get.resource_wait_for_install(kind="Deployment", resource_name="wordpress", wait_count=180, namespace="default")
38+
KubectlClient::Wait.resource_wait_for_install(kind = "Deployment", resource_name = "wordpress", wait_count = 180, namespace = "default")
3639
violators = Netstat::K8s.get_multiple_pods_connected_to_mariadb_violators
3740
(Netstat::K8s.detect_multiple_pods_connected_to_mariadb_from_violators(violators)).should be_false
3841
end
3942
end
40-
43+
4144
describe "cnf with no database is used by two microservices" do
4245
# sample-cnfs/sample-statefulset-cnf
4346
release_name = "test"
@@ -47,23 +50,25 @@ describe "netstat" do
4750
Helm.helm_repo_add("bitnami", "https://charts.bitnami.com/bitnami")
4851
end
4952

50-
after_all do
53+
after_all do
5154
resp = Helm.uninstall(release_name)
52-
KubectlClient::Delete.command("pvc/data-wordpress-mariadb-0")
53-
KubectlClient::Delete.command("pvc/wordpress")
55+
begin
56+
KubectlClient::Delete.resource("pvc", "data-wordpress-mariadb-0")
57+
KubectlClient::Delete.resource("pvc", "wordpress")
58+
rescue ex : KubectlClient::ShellCMD::NotFoundError
59+
end
5460
Log.info { resp }
5561
(resp[:status].exit_status == 0).should be_true
5662
end
5763

5864
it "should install" do
5965
helm_install(release_name, helm_chart, nil, "--set mariadb.primary.persistence.enabled=false --set persistence.enabled=false")
6066
end
61-
67+
6268
it "k8s_netstat should detect mutiple pods NOT connected to same db" do
63-
KubectlClient::Get.resource_wait_for_install(kind="Deployment", resource_name="test-wordpress", wait_count=180, namespace="default")
69+
KubectlClient::Wait.resource_wait_for_install(kind = "Deployment", resource_name = "test-wordpress", wait_count = 180, namespace = "default")
6470
violators = Netstat::K8s.get_multiple_pods_connected_to_mariadb_violators
6571
(Netstat::K8s.detect_multiple_pods_connected_to_mariadb_from_violators(violators)).should be_false
6672
end
6773
end
68-
6974
end

src/netstat/k8s.cr

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ module Netstat
1111

1212
db_pod_ips = self.get_pods_ips(db_pods)
1313
Log.info { "DB Pods ips #{db_pod_ips}" }
14-
db_pod_ips
14+
db_pod_ips
1515
end
1616

1717
def self.get_all_non_db_service_pod_ips
18-
cnf_services = KubectlClient::Get.services(all_namespaces: true)
18+
cnf_services = KubectlClient::Get.resource("services", all_namespaces: true)
1919
Log.info { "all namespace services: #{cnf_services}" }
2020

2121
db_pod_ips = self.get_all_db_pod_ips
@@ -107,6 +107,14 @@ module Netstat
107107
Log.info { "get_pod_network_info_from_node_via_container_id: node_name: #{node_name} container_id: #{container_id}" }
108108

109109
inspect = ClusterTools.exec_by_node("crictl inspect #{container_id}", node_name)
110+
if inspect.nil?
111+
return [] of NamedTuple(proto: String,
112+
recv: String,
113+
send: String,
114+
local_address: String,
115+
foreign_address: String,
116+
state: String)
117+
end
110118

111119
pid = JSON.parse(inspect["output"]).dig("info", "pid")
112120
Log.info { "Container PID: #{pid}" }
@@ -115,6 +123,9 @@ module Netstat
115123
parsed_netstat = (1..30).map {
116124
sleep 10
117125
netstat = ClusterTools.exec_by_node("nsenter -t #{pid} -n netstat -n", node_name)
126+
if netstat.nil?
127+
next
128+
end
118129
Log.info { "Container Netstat: #{netstat}" }
119130
Netstat.parse(netstat["output"])
120131
}.flatten.compact

0 commit comments

Comments
 (0)