oci-logging-analytics-kubernetes-discovery 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/oci-loganalytics-kubernetes-discovery +74 -27
- data/lib/config/oci_client_retry_config.rb +11 -8
- data/lib/discover/infrastructure.rb +79 -27
- data/lib/discover/object.rb +19 -4
- data/lib/dto/infra/load_balancer_payload.rb +32 -0
- data/lib/dto/infra/node_pool_payload.rb +28 -0
- data/lib/dto/infra/{node_pool_entity_payload.rb → resource_payload.rb} +6 -6
- data/lib/dto/infra/subnet_payload.rb +34 -0
- data/lib/dto/infra_objects_payload.rb +3 -3
- data/lib/dto/kubernetes_objects_payload.rb +19 -15
- data/lib/dto/state.rb +7 -3
- data/lib/enum/infrastructure_resource_discovery.rb +1 -0
- data/lib/enum/object_client_mapping_enum.rb +1 -1
- data/lib/enum/stack_job_lifecycle_state_enum.rb +14 -0
- data/lib/enum/stack_job_operation_enum.rb +10 -0
- data/lib/infra_resources.rb +142 -41
- data/lib/objects_resources.rb +16 -6
- data/lib/oci_loganalytics_resources_discovery.rb +105 -57
- data/lib/util/kube_client.rb +1 -0
- data/lib/util/kubectl_ops.rb +1 -1
- data/lib/util/log_analytics.rb +2 -2
- data/lib/util/oci_clients.rb +137 -78
- data/lib/util/service_logs.rb +559 -0
- data/lib/util/state_manager.rb +12 -2
- data/lib/util/string_utils.rb +48 -0
- data/lib/version.rb +1 -1
- metadata +9 -7
- data/lib/dto/infra/cluster_entity_payload.rb +0 -22
- data/lib/dto/infra/load_balancers_entity_payload.rb +0 -22
- data/lib/dto/infra/subnet_entity_payload.rb +0 -22
- data/lib/dto/infra/vcn_entity_payload.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40cb1255cc1125f85989f0abea5d0c6afb113327ed376c5920e2c3bc05124807
|
4
|
+
data.tar.gz: 2b7538d6052d87229aebdf934d51800e711d6da4017a9184c6bf0c3e236f3705
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 889778a1de60813ec7c955b027f0b5668706d6484c980cf861a4c05de76b237043dcb47ff01a841aa191b1d8fcd90a47c45ce7652574f8c2fe614faabcd264e5
|
7
|
+
data.tar.gz: e5d84ff26835e2102c0bc7b25f1b5e7aee4a49ac083c14c7e1d3d910af1e69dbfd97e9669cd6763b46a87661b8158c5217b10b7fe605a3ef4e8fff4a1cec8e1c
|
@@ -4,6 +4,7 @@
|
|
4
4
|
## The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
5
5
|
|
6
6
|
require 'optparse'
|
7
|
+
require 'base64'
|
7
8
|
|
8
9
|
require_relative '../lib/oci_loganalytics_resources_discovery'
|
9
10
|
require_relative '../lib/util/logging'
|
@@ -21,9 +22,9 @@ app_config = {}
|
|
21
22
|
DISCOVERY_OPTIONS = %w[infra object].freeze
|
22
23
|
LOG_FMT_OPTIONS = %w[text json].freeze
|
23
24
|
CHUNK_LIMIT_DEFAULT = 1000
|
25
|
+
STACK_OPERATION_TIMEOUT_DEFAULT = 300 # Timeout unit is in seconds
|
24
26
|
|
25
27
|
optparse = OptionParser.new do |param|
|
26
|
-
# TODO: Naming of the gem and command.
|
27
28
|
param.banner = "\nUsage: oci-loganalytics-kubernetes-discovery [options]"
|
28
29
|
|
29
30
|
# Mandatory Fields
|
@@ -60,10 +61,18 @@ optparse = OptionParser.new do |param|
|
|
60
61
|
param.on('--secret_dir SECRET_DIR', 'Path to Kubernetes service account token file to access Kubernetes API') { |o| kube_config[:secret_dir] = o }
|
61
62
|
|
62
63
|
# Discovery
|
63
|
-
param.on('--discovery DISCOVERY_MODE', "Discovery mode to be used: #{format_option_selections(DISCOVERY_OPTIONS)}") { |o| app_config[:mode] = o.downcase }
|
64
|
+
param.on('--discovery DISCOVERY_MODE', "[Deprecated] Discovery mode to be used: #{format_option_selections(DISCOVERY_OPTIONS)}") { |o| app_config[:mode] = o.downcase }
|
64
65
|
param.on('--chunk_limit CHUNK_SIZE', Integer, "Max number of objects that can be fetched via K8s GET API call. Default: #{CHUNK_LIMIT_DEFAULT}") { |o| app_config[:chunk_limit] = o }
|
65
66
|
param.on('--skip_upload', 'Flag to skip uploading data to OCI Logging Analytics [ONLY FOR INTERNAL TESTING]') { |_o| app_config[:skip_upload] = true }
|
66
67
|
param.on('--collect_warning_events_only', 'Flag to collect only warning event logs') { |_o| app_config[:collect_warning_events_only] = true }
|
68
|
+
param.on('--tenancy_ocid TENANCY_OCID', 'Tenancy OCID') { |o| app_config[:tenancy_ocid] = o }
|
69
|
+
|
70
|
+
# Stack operations
|
71
|
+
param.on('--rms_template_base64_encoded RMS_TEMPLATE_BASE64_ENCODED', 'Base64 encoded ZIP file of RMS template for OCI service log collection') { |o| app_config[:rms_template_base64_encoded] = o }
|
72
|
+
param.on('--stack_operation_timeout STACK_OPERATION_TIMEOUT', "Maximum amount of time (in seconds) the job should wait while checking the status of stack APPLY operation. Default: #{STACK_OPERATION_TIMEOUT_DEFAULT}") { |o| app_config[:stack_operation_timeout] = o }
|
73
|
+
param.on('--enable_service_log', 'Flag to enable or disable the creation of a stack for collecting OCI service logs associated with OKE cluster') { |_o| app_config[:enable_service_log] = true }
|
74
|
+
param.on('--oci_tags_base64 OCI_TAGS_BASE64', 'Freeform and defined tags provided to the job') { |o| app_config[:oci_tags] = o }
|
75
|
+
param.on('--probe_all_compartments', 'Flag that determines whether to iterate through all compartments or only the cluster compartment while discovering node pools') { |_o| app_config[:probe_all_compartments] = true }
|
67
76
|
|
68
77
|
# Logging and threading
|
69
78
|
param.on('--log_format LOG_FORMAT', "Log format to be used: #{format_option_selections(LOG_FMT_OPTIONS)}") { |o| app_config[:log_format] = o }
|
@@ -90,17 +99,9 @@ begin
|
|
90
99
|
missing = mandatory.select { |param| cluster_config[param].nil? || cluster_config[param].empty? } # .empty gates 'key=' edge case
|
91
100
|
raise OptionParser::MissingArgument, missing.join(', ') unless missing.empty?
|
92
101
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
raise OptionParser::InvalidOption, "--discovery=#{app_config[:mode]}"
|
97
|
-
end
|
98
|
-
|
99
|
-
# Threads valid only for object discovery (not for infrastrucutre discovery).
|
100
|
-
if app_config[:mode] == DISCOVERY_OPTIONS.first && app_config[:enable_threading]
|
101
|
-
logger.info("Multi-threading is only supported for mode: #{DISCOVERY_OPTIONS.second}")
|
102
|
-
raise OptionParser::InvalidOption, '--enable_threading'
|
103
|
-
end
|
102
|
+
if app_config[:enable_service_log] && app_config[:rms_template_base64_encoded].nil?
|
103
|
+
logger.error('RMS template must be provided for infrastructure discovery when OCI service log creation is enabled.')
|
104
|
+
raise OptionParser::MissingArgument, '--rms_template_base64_encoded'
|
104
105
|
end
|
105
106
|
|
106
107
|
# Valid auth input check.
|
@@ -110,7 +111,7 @@ begin
|
|
110
111
|
end
|
111
112
|
|
112
113
|
if auth_config[:auth_type] == Enum::AuthTypeEnum::CONFIG
|
113
|
-
raise OptionParser::MissingArgument, '--config_file_location'
|
114
|
+
raise OptionParser::MissingArgument, '--config_file_location' if auth_config[:config_file_location].nil?
|
114
115
|
end
|
115
116
|
end
|
116
117
|
|
@@ -122,14 +123,42 @@ begin
|
|
122
123
|
if app_config[:chunk_limit] && app_config[:chunk_limit] > 10_000
|
123
124
|
raise OptionParser::InvalidOption, '--chunk_limit is too large.'
|
124
125
|
end
|
125
|
-
|
126
|
-
|
126
|
+
|
127
|
+
# Validate freeform tags and defined tags
|
128
|
+
begin
|
129
|
+
if !app_config[:oci_tags].nil? && !app_config[:oci_tags].empty?
|
130
|
+
app_config[:oci_tags_str] = Base64.decode64(app_config[:oci_tags])
|
131
|
+
app_config[:oci_tags_json] = parse_tags_to_hash(app_config[:oci_tags_str])
|
132
|
+
|
133
|
+
freeform_tags = app_config[:oci_tags_json]['freeformTags']
|
134
|
+
defined_tags = app_config[:oci_tags_json]['definedTags']
|
135
|
+
|
136
|
+
if !freeform_tags.nil?
|
137
|
+
raise StandardError, 'Freeform tags should be string key-value pairs' if !json_key_value_pair?(freeform_tags)
|
138
|
+
end
|
139
|
+
|
140
|
+
if !defined_tags.nil?
|
141
|
+
raise StandardError, 'Defined tags should be string key-value pairs' if !json_key_value_pair?(defined_tags)
|
142
|
+
app_config[:oci_tags_json]['definedTags'] = parse_defined_tags(defined_tags)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
rescue StandardError => e
|
146
|
+
logger.error("Error: #{e.message}")
|
147
|
+
raise OptionParser::InvalidArgument, 'Invalid format for --oci_tags. Ensure it follows the correct structure.'
|
148
|
+
end
|
149
|
+
|
150
|
+
# Tenancy OCID is compulsory if probe_all_compartments flag is set
|
151
|
+
if app_config[:probe_all_compartments] && app_config[:tenancy_ocid].nil?
|
152
|
+
logger.error('Tenancy OCID is compulsory if --probe_all_compartments is provided')
|
153
|
+
raise OptionParser::MissingArgument, '--tenancy_ocid'
|
154
|
+
end
|
155
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument, OptionParser::InvalidArgument => e
|
156
|
+
logger.error(e.to_s.capitalize)
|
127
157
|
logger.info(optparse)
|
128
158
|
exit(1)
|
129
159
|
end
|
130
160
|
|
131
161
|
# Set defaults for skipped inputs
|
132
|
-
|
133
162
|
cluster_config[:kubernetes_cluster_id] = cluster_config[:kubernetes_cluster_id] ||= nil
|
134
163
|
cluster_config[:oci_la_cluster_entity_id] = cluster_config[:oci_la_cluster_entity_id] ||= nil
|
135
164
|
cluster_config[:kubernetes_resourcename_prefix] = cluster_config[:kubernetes_resourcename_prefix] ||= 'oci-onm'
|
@@ -164,21 +193,46 @@ kube_config[:bearer_token_file] = kube_config[:bearer_token_file] ||= nil
|
|
164
193
|
kube_config[:secret_dir] = kube_config[:secret_dir] ||= '/var/run/secrets/kubernetes.io/serviceaccount'
|
165
194
|
|
166
195
|
# Discovery
|
167
|
-
app_config[:mode] = app_config[:mode] ||= 'object'
|
168
196
|
app_config[:skip_upload] = app_config[:skip_upload] ||= false
|
169
197
|
app_config[:collect_warning_events_only] = app_config[:collect_warning_events_only] ||= false
|
170
198
|
app_config[:chunk_limit] = app_config[:chunk_limit] ||= CHUNK_LIMIT_DEFAULT
|
199
|
+
app_config[:tenancy_ocid] = app_config[:tenancy_ocid] ||= nil
|
200
|
+
app_config[:stack_operation_timeout] = app_config[:stack_operation_timeout] ||= STACK_OPERATION_TIMEOUT_DEFAULT
|
201
|
+
|
202
|
+
# Stack operations
|
203
|
+
app_config[:oci_tags_str] = app_config[:oci_tags_str].nil? || app_config[:oci_tags_str].empty? ? '{ "freeformTags" = {}, "definedTags" = {} }' : app_config[:oci_tags_str]
|
204
|
+
app_config[:oci_tags_json] = app_config[:oci_tags_json].nil? || app_config[:oci_tags_json].empty? ? { freeformTags: {}, definedTags: {} } : app_config[:oci_tags_json]
|
205
|
+
app_config[:probe_all_compartments] = app_config[:probe_all_compartments] ||= false
|
171
206
|
|
172
207
|
# Threading
|
173
208
|
app_config[:enable_threading] = app_config[:enable_threading] ||= false
|
174
209
|
app_config[:thread_count] = app_config[:thread_count] ||= 1
|
175
210
|
app_config[:work_queue_size] = app_config[:work_queue_size] ||= (app_config[:thread_count] * 5)
|
176
211
|
|
177
|
-
# Log level and format provided in
|
212
|
+
# Log level and format provided in argument
|
178
213
|
app_config[:log_format] = app_config[:log_format] ||= LOG_FMT_OPTIONS.first
|
179
214
|
app_config[:log_level] = !app_config[:log_level].nil? ? Util::Logging::SEV_LABEL.key(app_config[:log_level].upcase) : Logger::INFO
|
180
215
|
app_config[:enable_raw_request] = app_config[:enable_raw_request] ||= false
|
181
216
|
|
217
|
+
# Decide on Service and Infra discovery based on input
|
218
|
+
if cluster_config[:kubernetes_cluster_id].nil?
|
219
|
+
if app_config[:enable_service_log]
|
220
|
+
logger.warn('Service Discovery is only supported for OKE. OCI service logs collection will be skipped.')
|
221
|
+
cluster_config[:enable_infra_discovery] = false
|
222
|
+
end
|
223
|
+
logger.warn('Kubernetes cluster ID is missing. Infrastructure discovery will be skipped.')
|
224
|
+
app_config[:enable_service_log] = false
|
225
|
+
elsif !cluster_config[:kubernetes_cluster_id].match?("ocid1\.cluster")
|
226
|
+
if app_config[:enable_service_log]
|
227
|
+
logger.warn('Service Discovery is only supported for OKE. OCI service logs collection will be skipped.')
|
228
|
+
cluster_config[:enable_infra_discovery] = false
|
229
|
+
end
|
230
|
+
logger.warn('Infra Discovery is only supported for OKE. Infrastructure discovery will be skipped.')
|
231
|
+
app_config[:enable_service_log] = false
|
232
|
+
else
|
233
|
+
cluster_config[:enable_infra_discovery] = true
|
234
|
+
end
|
235
|
+
|
182
236
|
Util::Logging::LogConfigs.new(app_config[:log_format], app_config[:log_level])
|
183
237
|
|
184
238
|
logger.info('Initiating Kubernetes Discovery.')
|
@@ -192,14 +246,7 @@ begin
|
|
192
246
|
app_config_hash: app_config
|
193
247
|
)
|
194
248
|
|
195
|
-
|
196
|
-
when 'infra'
|
197
|
-
# Initiating Kubernetes infrastructure discovery
|
198
|
-
OciLogAnalyticsResourcesDiscovery.initiate_infra_discovery
|
199
|
-
when 'object'
|
200
|
-
# Initiating Kubernetes objects discovery
|
201
|
-
OciLogAnalyticsResourcesDiscovery.initiate_object_discovery
|
202
|
-
end
|
249
|
+
OciLogAnalyticsResourcesDiscovery.initiate_discovery
|
203
250
|
rescue StandardError => e
|
204
251
|
unless e.backtrace.empty?
|
205
252
|
stack_trace = "\n"
|
@@ -9,13 +9,15 @@ module Config
|
|
9
9
|
|
10
10
|
module_function
|
11
11
|
|
12
|
-
|
12
|
+
def oci_default_retry_config
|
13
|
+
OCI::Retry.default_retry_config
|
14
|
+
end
|
13
15
|
|
14
|
-
def
|
16
|
+
def custom_retry_policy
|
15
17
|
OCI::Retry::RetryConfig.new(
|
16
18
|
base_sleep_time_millis: 1000,
|
17
19
|
exponential_growth_factor: 2,
|
18
|
-
should_retry_exception_proc:
|
20
|
+
should_retry_exception_proc: retry_on_4xx_and_5xx,
|
19
21
|
sleep_calc_millis_proc: OCI::Retry::Functions::Sleep.exponential_backoff_with_full_jitter,
|
20
22
|
max_attempts: 5,
|
21
23
|
max_elapsed_time_millis: 300_000, # 5 minutes
|
@@ -23,12 +25,13 @@ module Config
|
|
23
25
|
)
|
24
26
|
end
|
25
27
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
28
|
+
def retry_on_4xx_and_5xx
|
29
|
+
lambda do |retry_state|
|
30
|
+
return true if retry_state.last_exception.is_a?(OCI::Errors::NetworkError)
|
31
|
+
return false unless retry_state.last_exception.is_a?(OCI::Errors::ServiceError)
|
29
32
|
|
30
|
-
|
31
|
-
|
33
|
+
retry_state.last_exception.status_code >= 400
|
34
|
+
end
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
@@ -1,9 +1,11 @@
|
|
1
1
|
## Copyright (c) 2024 Oracle and/or its affiliates.
|
2
2
|
## The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
3
3
|
|
4
|
-
|
4
|
+
require 'oci'
|
5
|
+
require 'json'
|
5
6
|
|
6
7
|
# Util
|
8
|
+
require_relative '../util/logging'
|
7
9
|
require_relative '../util/oci_clients'
|
8
10
|
|
9
11
|
module Discover
|
@@ -13,7 +15,7 @@ module Discover
|
|
13
15
|
|
14
16
|
module_function
|
15
17
|
|
16
|
-
def fetch_cluster_details(
|
18
|
+
def fetch_cluster_details(cluster_id)
|
17
19
|
client = nil
|
18
20
|
begin
|
19
21
|
client = Util::OCIClients.get_clients[:ce_client]
|
@@ -23,63 +25,93 @@ module Discover
|
|
23
25
|
rescue StandardError => e
|
24
26
|
logger.error("Error while discovering cluster details: #{e}")
|
25
27
|
raise StandardError, 'Error while discovering cluster details.'
|
26
|
-
exit
|
27
28
|
end
|
28
29
|
@cluster_details
|
29
30
|
end
|
30
31
|
|
31
|
-
def fetch_node_pool_lists(
|
32
|
-
opts = { cluster_id: cluster_id }
|
32
|
+
def fetch_node_pool_lists(compartment_id, cluster_id)
|
33
|
+
opts = { cluster_id: cluster_id, limit: 1000 }
|
33
34
|
begin
|
34
35
|
client = Util::OCIClients.get_clients[:ce_client]
|
36
|
+
|
37
|
+
# NOTE: The below call retrieves only the first page of the node pool list. Pagination support is
|
38
|
+
# not implemented because the first page already contains up to 1000 records (Check limit above)
|
39
|
+
# which is sufficient for our current use case. Subsequent pages will not be fetched.
|
35
40
|
response = client.list_node_pools(compartment_id, opts)
|
36
41
|
|
37
42
|
@node_pool_list = response.data
|
38
43
|
rescue StandardError => e
|
39
44
|
logger.error("Error while discovering node pool list: #{e}")
|
40
45
|
raise StandardError, 'Error while discovering node pool list.'
|
41
|
-
exit
|
42
46
|
end
|
43
47
|
@node_pool_list
|
44
48
|
end
|
45
49
|
|
46
|
-
def
|
50
|
+
def fetch_node_pool(node_pool_id)
|
51
|
+
begin
|
52
|
+
client = Util::OCIClients.get_clients[:ce_client]
|
53
|
+
response = client.get_node_pool(node_pool_id)
|
54
|
+
|
55
|
+
@node_pool_details = response.data
|
56
|
+
rescue StandardError => e
|
57
|
+
logger.error("Error while fetching node pool details: #{e}")
|
58
|
+
raise StandardError, 'Error while fetching node pool details.'
|
59
|
+
end
|
60
|
+
@node_pool_details
|
61
|
+
end
|
62
|
+
|
63
|
+
def fetch_compartment_list(compartment_id, scoped_at_tenancy)
|
47
64
|
client = nil
|
48
|
-
|
65
|
+
all_records = []
|
66
|
+
|
49
67
|
begin
|
50
68
|
client = Util::OCIClients.get_clients[:id_client]
|
69
|
+
|
70
|
+
opts = if scoped_at_tenancy
|
71
|
+
{ compartment_id_in_subtree: true, access_level: 'ACCESSIBLE' }
|
72
|
+
else
|
73
|
+
{ access_level: 'ACCESSIBLE' }
|
74
|
+
end
|
75
|
+
|
51
76
|
response = client.list_compartments(compartment_id, opts)
|
77
|
+
all_records.concat(response.data)
|
52
78
|
|
53
|
-
|
79
|
+
while !response.next_page.nil?
|
80
|
+
opts[:page] = response.next_page
|
81
|
+
response = client.list_compartments(compartment_id, opts)
|
82
|
+
all_records.concat(response.data)
|
83
|
+
end
|
54
84
|
rescue StandardError => e
|
55
|
-
logger.error("Error while fetching
|
56
|
-
raise StandardError, 'Error while fetching
|
85
|
+
logger.error("Error while fetching compartment list: #{e}")
|
86
|
+
raise StandardError, 'Error while fetching compartment list.'
|
57
87
|
end
|
58
|
-
|
88
|
+
return { data: all_records, status: response.status }
|
59
89
|
end
|
60
90
|
|
61
|
-
def fetch_load_balancer_details(
|
91
|
+
def fetch_load_balancer_details(load_balancer_id)
|
62
92
|
client = nil
|
63
93
|
begin
|
64
94
|
client = Util::OCIClients.get_clients[:lb_client]
|
65
95
|
response = client.get_load_balancer(load_balancer_id)
|
66
|
-
@lb_response = response
|
96
|
+
@lb_response = response
|
67
97
|
rescue StandardError => e
|
68
98
|
logger.error("Error while fetching load balancer details: #{e}")
|
99
|
+
return { data: nil, status: e.status_code } unless e.status_code.nil?
|
100
|
+
|
69
101
|
raise StandardError, 'Error while fetching load balancer details.'
|
70
102
|
end
|
71
|
-
@lb_response
|
103
|
+
{ data: @lb_response.data, status: @lb_response.status }
|
72
104
|
end
|
73
105
|
|
74
|
-
def
|
106
|
+
def search_with_free_text(free_text)
|
75
107
|
client = nil
|
76
108
|
begin
|
77
|
-
client = Util::OCIClients.get_clients[:
|
109
|
+
client = Util::OCIClients.get_clients[:rqs_client]
|
78
110
|
response = client.search_resources(
|
79
111
|
OCI::ResourceSearch::Models::FreeTextSearchDetails.new(
|
80
112
|
type: 'FreeText',
|
81
|
-
text:
|
82
|
-
|
113
|
+
text: free_text,
|
114
|
+
matching_context_type: OCI::ResourceSearch::Models::SearchDetails::MATCHING_CONTEXT_TYPE_HIGHLIGHTS
|
83
115
|
)
|
84
116
|
)
|
85
117
|
@free_text_response = response.data
|
@@ -90,7 +122,26 @@ module Discover
|
|
90
122
|
@free_text_response
|
91
123
|
end
|
92
124
|
|
93
|
-
def
|
125
|
+
def search_with_structured_query(query)
|
126
|
+
client = nil
|
127
|
+
begin
|
128
|
+
client = Util::OCIClients.get_clients[:rqs_client]
|
129
|
+
response = client.search_resources(
|
130
|
+
OCI::ResourceSearch::Models::StructuredSearchDetails.new(
|
131
|
+
type: 'Structured',
|
132
|
+
query: query,
|
133
|
+
matching_context_type: OCI::ResourceSearch::Models::SearchDetails::MATCHING_CONTEXT_TYPE_HIGHLIGHTS
|
134
|
+
)
|
135
|
+
)
|
136
|
+
@structured_query_response = response.data
|
137
|
+
rescue StandardError => e
|
138
|
+
logger.error("Error while fetching structured query: #{e}")
|
139
|
+
raise StandardError, 'Error while fetching structured query.'
|
140
|
+
end
|
141
|
+
@structured_query_response
|
142
|
+
end
|
143
|
+
|
144
|
+
def fetch_vcn_response(vcn_id)
|
94
145
|
client = nil
|
95
146
|
begin
|
96
147
|
client = Util::OCIClients.get_clients[:vcn_client]
|
@@ -98,25 +149,26 @@ module Discover
|
|
98
149
|
|
99
150
|
@vnc_response = response.data
|
100
151
|
rescue StandardError => e
|
101
|
-
logger.error("Error while discovering
|
102
|
-
raise StandardError, 'Error while discovering
|
152
|
+
logger.error("Error while discovering VCN details: #{e}")
|
153
|
+
raise StandardError, 'Error while discovering VCN details.'
|
103
154
|
end
|
104
155
|
@vnc_response
|
105
156
|
end
|
106
157
|
|
107
|
-
def
|
158
|
+
def fetch_subnet_details(subnet_id)
|
108
159
|
client = nil
|
109
160
|
begin
|
110
|
-
opts = { vcn_id: vcn_id }
|
111
161
|
client = Util::OCIClients.get_clients[:vcn_client]
|
112
|
-
response = client.
|
162
|
+
response = client.get_subnet(subnet_id)
|
113
163
|
|
114
|
-
@subnet_response = response
|
164
|
+
@subnet_response = response
|
115
165
|
rescue StandardError => e
|
116
166
|
logger.error("Error while discovering subnet details: #{e}")
|
167
|
+
return { data: nil, status: e.status_code } unless e.status_code.nil?
|
168
|
+
|
117
169
|
raise StandardError, 'Error while discovering subnet details.'
|
118
170
|
end
|
119
|
-
@subnet_response
|
171
|
+
{ data: @subnet_response.data, status: @subnet_response.status }
|
120
172
|
end
|
121
173
|
end
|
122
174
|
end
|
data/lib/discover/object.rb
CHANGED
@@ -21,9 +21,9 @@ module Discover
|
|
21
21
|
End_point_slice = Struct.new(:name, :namespace, :uid, :endpoints, :ports)
|
22
22
|
Job = Struct.new(:name, :namespace, :uid, :controller)
|
23
23
|
Node = Struct.new(:name, :displayName, :uid, :internalIP, :externalIP)
|
24
|
-
Pod = Struct.new(:name, :namespace, :uid, :podIP, :hostIP, :nodeIP, :controller)
|
24
|
+
Pod = Struct.new(:name, :namespace, :uid, :podIP, :hostIP, :nodeIP, :controller, :phase, :startTime, :finishTime)
|
25
25
|
Replica_set = Struct.new(:name, :namespace, :uid, :controller)
|
26
|
-
Service = Struct.new(:name, :namespace, :uid, :clusterIP, :externalIP, :loadBalancerIP, :ports)
|
26
|
+
Service = Struct.new(:name, :namespace, :uid, :clusterIP, :externalIP, :loadBalancerIP, :serviceType, :ports)
|
27
27
|
Namespace = Struct.new(:name, :uid)
|
28
28
|
|
29
29
|
def get_generic_object_details(item, object_type)
|
@@ -200,6 +200,8 @@ module Discover
|
|
200
200
|
podIP = item[:status][:podIP]
|
201
201
|
hostIP = item[:status][:hostIP]
|
202
202
|
nodeIP = item[:status][:nodeIP]
|
203
|
+
phase = item[:status][:phase]
|
204
|
+
startTime = item[:status][:startTime]
|
203
205
|
controller = nil
|
204
206
|
if !item[:metadata][:ownerReferences].nil? && !item[:metadata][:ownerReferences].empty?
|
205
207
|
item[:metadata][:ownerReferences].each do |owner_reference|
|
@@ -210,7 +212,18 @@ module Discover
|
|
210
212
|
end
|
211
213
|
end
|
212
214
|
end
|
213
|
-
|
215
|
+
finishTime = nil
|
216
|
+
if !item[:status][:containerStatuses].nil? && !item[:status][:containerStatuses].empty?
|
217
|
+
item[:status][:containerStatuses].each do |container_status|
|
218
|
+
next if container_status.nil?
|
219
|
+
|
220
|
+
if !container_status[:state][:terminated].nil?
|
221
|
+
finishTime = container_status[:state][:terminated][:finishedAt]
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
processed_data.push(Pod.new(generic_object[:name], generic_object[:namespace], generic_object[:uid],
|
226
|
+
podIP, hostIP, nodeIP, controller.to_h, phase, startTime, finishTime))
|
214
227
|
end
|
215
228
|
rescue StandardError => e
|
216
229
|
logger.error("Unable to fetch '#{resource_name}'")
|
@@ -259,6 +272,8 @@ module Discover
|
|
259
272
|
clusterIP = item[:spec][:clusterIP]
|
260
273
|
externalIP = item[:spec][:externalIP]
|
261
274
|
loadBalancerIP = item[:status][:loadBalancer][:ingress].nil? ? nil : item[:status][:loadBalancer][:ingress][0][:ip]
|
275
|
+
service_type = item[:spec][:type]
|
276
|
+
|
262
277
|
ports = item[:spec][:ports]
|
263
278
|
ports_arr = []
|
264
279
|
if !ports.nil? && !ports.empty?
|
@@ -268,7 +283,7 @@ module Discover
|
|
268
283
|
ports_arr.push(port_item.to_h)
|
269
284
|
end
|
270
285
|
end
|
271
|
-
processed_data.push(Service.new(generic_object[:name], generic_object[:namespace], generic_object[:uid], clusterIP, externalIP, loadBalancerIP, ports_arr))
|
286
|
+
processed_data.push(Service.new(generic_object[:name], generic_object[:namespace], generic_object[:uid], clusterIP, externalIP, loadBalancerIP, service_type, ports_arr))
|
272
287
|
end
|
273
288
|
rescue StandardError => e
|
274
289
|
logger.error("Unable to fetch '#{resource_name}'")
|
@@ -0,0 +1,32 @@
|
|
1
|
+
## Copyright (c) 2024 Oracle and/or its affiliates.
|
2
|
+
## The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
3
|
+
|
4
|
+
module Dto
|
5
|
+
module Infra
|
6
|
+
class LoadBalancerPayload
|
7
|
+
attr_accessor :name, :ocid, :compartment_id, :is_private, :ip_addresses, :lifecycle_state, :subnet_ids
|
8
|
+
|
9
|
+
def initialize(name, ocid, compartment_id, is_private, ip_addresses, lifecycle_state, subnet_ids)
|
10
|
+
@name = name
|
11
|
+
@ocid = ocid
|
12
|
+
@compartment_id = compartment_id
|
13
|
+
@is_private = is_private
|
14
|
+
@ip_addresses = ip_addresses
|
15
|
+
@lifecycle_state = lifecycle_state
|
16
|
+
@subnet_ids = subnet_ids
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_hash
|
20
|
+
{
|
21
|
+
name: @name,
|
22
|
+
ocid: @ocid,
|
23
|
+
compartmentId: @compartment_id,
|
24
|
+
isPrivate: @is_private,
|
25
|
+
ipAddresses: @ip_addresses.map(&:to_h),
|
26
|
+
lifecycleState: @lifecycle_state,
|
27
|
+
subnetIds: @subnet_ids
|
28
|
+
}.compact
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
## Copyright (c) 2024 Oracle and/or its affiliates.
|
2
|
+
## The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
3
|
+
|
4
|
+
module Dto
|
5
|
+
module Infra
|
6
|
+
class NodePoolPayload
|
7
|
+
attr_accessor :name, :ocid, :compartment_id, :subnet_ids, :nodes
|
8
|
+
|
9
|
+
def initialize(name, ocid, compartment_id, subnet_ids, nodes)
|
10
|
+
@name = name
|
11
|
+
@ocid = ocid
|
12
|
+
@compartment_id = compartment_id
|
13
|
+
@subnet_ids = subnet_ids
|
14
|
+
@nodes = nodes
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_hash
|
18
|
+
{
|
19
|
+
name: @name,
|
20
|
+
ocid: @ocid,
|
21
|
+
compartmentId: @compartment_id,
|
22
|
+
subnetIds: @subnet_ids,
|
23
|
+
nodes: @nodes.map(&:to_h)
|
24
|
+
}.compact
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -3,20 +3,20 @@
|
|
3
3
|
|
4
4
|
module Dto
|
5
5
|
module Infra
|
6
|
-
class
|
7
|
-
attr_accessor :name, :
|
6
|
+
class ResourcePayload
|
7
|
+
attr_accessor :name, :ocid, :compartment_id
|
8
8
|
|
9
|
-
def initialize(name,
|
9
|
+
def initialize(name, ocid, compartment_id)
|
10
10
|
@name = name
|
11
|
-
@
|
11
|
+
@ocid = ocid
|
12
12
|
@compartment_id = compartment_id
|
13
13
|
end
|
14
14
|
|
15
15
|
def to_hash
|
16
16
|
{
|
17
17
|
name: @name,
|
18
|
-
|
19
|
-
|
18
|
+
ocid: @ocid,
|
19
|
+
compartmentId: @compartment_id
|
20
20
|
}.compact
|
21
21
|
end
|
22
22
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
## Copyright (c) 2024 Oracle and/or its affiliates.
|
2
|
+
## The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
3
|
+
|
4
|
+
module Dto
|
5
|
+
module Infra
|
6
|
+
class SubnetPayload
|
7
|
+
attr_accessor :name, :ocid, :compartment_id, :prohibit_internet_ingress, :prohibit_public_ip_on_vnic,
|
8
|
+
:cidr_block, :lifecycle_state
|
9
|
+
|
10
|
+
def initialize(name, ocid, compartment_id, prohibit_internet_ingress, prohibit_public_ip_on_vnic,
|
11
|
+
cidr_block, lifecycle_state)
|
12
|
+
@name = name
|
13
|
+
@ocid = ocid
|
14
|
+
@compartment_id = compartment_id
|
15
|
+
@prohibit_internet_ingress = prohibit_internet_ingress
|
16
|
+
@prohibit_public_ip_on_vnic = prohibit_public_ip_on_vnic
|
17
|
+
@cidr_block = cidr_block
|
18
|
+
@lifecycle_state = lifecycle_state
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_hash
|
22
|
+
{
|
23
|
+
name: @name,
|
24
|
+
ocid: @ocid,
|
25
|
+
compartmentId: @compartment_id,
|
26
|
+
prohibitInternetIngress: @prohibit_internet_ingress,
|
27
|
+
prohibitPublicIpOnVnic: @prohibit_public_ip_on_vnic,
|
28
|
+
cidrBlock: @cidr_block,
|
29
|
+
lifecycleState: @lifecycle_state
|
30
|
+
}.compact
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -31,9 +31,9 @@ module Dto
|
|
31
31
|
{
|
32
32
|
cluster: @cluster.to_hash,
|
33
33
|
vcn: @vcn.to_hash,
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
subnets: get_hash(@subnet, SUBNET.to_s),
|
35
|
+
loadbalancers: get_hash(@load_balancer, LOAD_BALANCER.to_s),
|
36
|
+
nodepools: get_hash(@node_pools, NODE_POOLS.to_s)
|
37
37
|
}.compact
|
38
38
|
end
|
39
39
|
end
|