oci-logging-analytics-kubernetes-discovery 1.0.2 → 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/.gitignore +2 -1
- data/bin/oci-loganalytics-kubernetes-discovery +102 -25
- data/lib/config/oci_client_retry_config.rb +11 -8
- data/lib/discover/infrastructure.rb +81 -29
- 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/auth_type_enum.rb +1 -0
- 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 +104 -77
- data/lib/util/helper.rb +15 -0
- 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 +222 -103
- 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
- data/oci-logging-analytics-kubernetes-discovery.gemspec +1 -1
- metadata +13 -10
- 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
|
data/.gitignore
CHANGED
@@ -4,10 +4,12 @@
|
|
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'
|
10
11
|
require_relative '../lib/util/string_utils'
|
12
|
+
require_relative '../lib/util/helper'
|
11
13
|
|
12
14
|
extend Util::Logging
|
13
15
|
extend Util::StringUtils
|
@@ -20,9 +22,9 @@ app_config = {}
|
|
20
22
|
DISCOVERY_OPTIONS = %w[infra object].freeze
|
21
23
|
LOG_FMT_OPTIONS = %w[text json].freeze
|
22
24
|
CHUNK_LIMIT_DEFAULT = 1000
|
25
|
+
STACK_OPERATION_TIMEOUT_DEFAULT = 300 # Timeout unit is in seconds
|
23
26
|
|
24
27
|
optparse = OptionParser.new do |param|
|
25
|
-
# TODO: Naming of the gem and command.
|
26
28
|
param.banner = "\nUsage: oci-loganalytics-kubernetes-discovery [options]"
|
27
29
|
|
28
30
|
# Mandatory Fields
|
@@ -34,11 +36,17 @@ optparse = OptionParser.new do |param|
|
|
34
36
|
param.on('--kubernetes_resourcename_prefix PREFIX', 'Kubernetes cluster resourcename prefix. Defaults to oci-onm') { |o| cluster_config[:kubernetes_resourcename_prefix] = o }
|
35
37
|
param.on('--kubernetes_cluster_id KUBERNETES_CLUSTER_ID', 'Unique identifier for Kubernetes cluster') { |o| cluster_config[:kubernetes_cluster_id] = o }
|
36
38
|
|
39
|
+
# OCI Auth Type
|
40
|
+
param.on('--auth_type AUTH_TYPE', "OCI Authentication type - #{Util::Helper.enum_values(Enum::AuthTypeEnum)}") { |o| auth_config[:auth_type] = o }
|
41
|
+
param.on('--oci_domain DOMAIN', 'OCI domain, ex - us-ashburn-1.oci.oraclecloud.com') { |o| auth_config[:oci_domain] = o }
|
42
|
+
|
37
43
|
# OCI Config-based Auth
|
38
|
-
param.on('--endpoint ENDPOINT', 'Logging Analytics Ingestion API endpoint to ingest your application logs') { |o| auth_config[:endpoint] = o }
|
39
44
|
param.on('--profile_name PROFILE_NAME', 'OCI Config Profile Name to be used from the configuration file') { |o| auth_config[:profile_name] = o }
|
40
45
|
param.on('--config_file_location CONFIG_FILE_LOCATION', 'The location of the configuration file containing OCI authentication details') { |o| auth_config[:config_file_location] = o }
|
41
46
|
|
47
|
+
# OCI Logging Analytics custom endpoints
|
48
|
+
param.on('--endpoint ENDPOINT', 'Logging Analytics Ingestion API endpoint to ingest your application logs') { |o| auth_config[:endpoint] = o }
|
49
|
+
|
42
50
|
# Kubernetes Cluster
|
43
51
|
# For AuthNAuth when the job is outside the cluster.
|
44
52
|
param.on('--kube_config_location KUBE_CONFIG_LOCATION', 'Path to the kubernetes configuration (kubeconfig) file') { |o| kube_config[:kube_config_location] = o }
|
@@ -53,10 +61,18 @@ optparse = OptionParser.new do |param|
|
|
53
61
|
param.on('--secret_dir SECRET_DIR', 'Path to Kubernetes service account token file to access Kubernetes API') { |o| kube_config[:secret_dir] = o }
|
54
62
|
|
55
63
|
# Discovery
|
56
|
-
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 }
|
57
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 }
|
58
66
|
param.on('--skip_upload', 'Flag to skip uploading data to OCI Logging Analytics [ONLY FOR INTERNAL TESTING]') { |_o| app_config[:skip_upload] = true }
|
59
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 }
|
60
76
|
|
61
77
|
# Logging and threading
|
62
78
|
param.on('--log_format LOG_FORMAT', "Log format to be used: #{format_option_selections(LOG_FMT_OPTIONS)}") { |o| app_config[:log_format] = o }
|
@@ -83,16 +99,19 @@ begin
|
|
83
99
|
missing = mandatory.select { |param| cluster_config[param].nil? || cluster_config[param].empty? } # .empty gates 'key=' edge case
|
84
100
|
raise OptionParser::MissingArgument, missing.join(', ') unless missing.empty?
|
85
101
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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'
|
105
|
+
end
|
106
|
+
|
107
|
+
# Valid auth input check.
|
108
|
+
unless auth_config[:auth_type].nil?
|
109
|
+
unless Util::Helper.enum_value_defined?(Enum::AuthTypeEnum, auth_config[:auth_type])
|
110
|
+
raise OptionParser::InvalidOption, "--auth_type #{auth_config[:auth_type]} | valid inputs - #{Util::Helper.enum_values(Enum::AuthTypeEnum)}"
|
90
111
|
end
|
91
112
|
|
92
|
-
|
93
|
-
|
94
|
-
logger.info("Multi-threading is only supported for mode: #{DISCOVERY_OPTIONS.second}")
|
95
|
-
raise OptionParser::InvalidOption, '--enable_threading'
|
113
|
+
if auth_config[:auth_type] == Enum::AuthTypeEnum::CONFIG
|
114
|
+
raise OptionParser::MissingArgument, '--config_file_location' if auth_config[:config_file_location].nil?
|
96
115
|
end
|
97
116
|
end
|
98
117
|
|
@@ -104,23 +123,63 @@ begin
|
|
104
123
|
if app_config[:chunk_limit] && app_config[:chunk_limit] > 10_000
|
105
124
|
raise OptionParser::InvalidOption, '--chunk_limit is too large.'
|
106
125
|
end
|
107
|
-
|
108
|
-
|
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)
|
109
157
|
logger.info(optparse)
|
110
158
|
exit(1)
|
111
159
|
end
|
112
160
|
|
113
161
|
# Set defaults for skipped inputs
|
114
|
-
|
115
162
|
cluster_config[:kubernetes_cluster_id] = cluster_config[:kubernetes_cluster_id] ||= nil
|
116
163
|
cluster_config[:oci_la_cluster_entity_id] = cluster_config[:oci_la_cluster_entity_id] ||= nil
|
117
164
|
cluster_config[:kubernetes_resourcename_prefix] = cluster_config[:kubernetes_resourcename_prefix] ||= 'oci-onm'
|
118
165
|
|
166
|
+
# OCI Auth Type
|
167
|
+
if !auth_config[:config_file_location].nil?
|
168
|
+
auth_config[:auth_type] = auth_config[:auth_type] ||= Enum::AuthTypeEnum::CONFIG
|
169
|
+
else
|
170
|
+
auth_config[:auth_type] = auth_config[:auth_type] ||= Enum::AuthTypeEnum::INSTANCE_PRINCIPAL
|
171
|
+
end
|
172
|
+
|
173
|
+
# OCI Domain
|
174
|
+
auth_config[:oci_domain] = auth_config[:oci_domain] ||= nil
|
175
|
+
|
119
176
|
# Config based auth
|
120
|
-
auth_config[:endpoint] = auth_config[:endpoint] ||= nil
|
121
177
|
auth_config[:profile_name] = auth_config[:profile_name] ||= 'DEFAULT'
|
122
178
|
auth_config[:config_file_location] = auth_config[:config_file_location] ||= nil
|
123
179
|
|
180
|
+
# OCI Logging Analytics custom endpoints
|
181
|
+
auth_config[:endpoint] = auth_config[:endpoint] ||= nil
|
182
|
+
|
124
183
|
# Kubernetes cluster related
|
125
184
|
kube_config[:kube_config_location] = kube_config[:kube_config_location] ||= nil
|
126
185
|
kube_config[:kubernetes_url] = kube_config[:kubernetes_url] ||= nil
|
@@ -134,21 +193,46 @@ kube_config[:bearer_token_file] = kube_config[:bearer_token_file] ||= nil
|
|
134
193
|
kube_config[:secret_dir] = kube_config[:secret_dir] ||= '/var/run/secrets/kubernetes.io/serviceaccount'
|
135
194
|
|
136
195
|
# Discovery
|
137
|
-
app_config[:mode] = app_config[:mode] ||= 'object'
|
138
196
|
app_config[:skip_upload] = app_config[:skip_upload] ||= false
|
139
197
|
app_config[:collect_warning_events_only] = app_config[:collect_warning_events_only] ||= false
|
140
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
|
141
206
|
|
142
207
|
# Threading
|
143
208
|
app_config[:enable_threading] = app_config[:enable_threading] ||= false
|
144
209
|
app_config[:thread_count] = app_config[:thread_count] ||= 1
|
145
210
|
app_config[:work_queue_size] = app_config[:work_queue_size] ||= (app_config[:thread_count] * 5)
|
146
211
|
|
147
|
-
# Log level and format provided in
|
212
|
+
# Log level and format provided in argument
|
148
213
|
app_config[:log_format] = app_config[:log_format] ||= LOG_FMT_OPTIONS.first
|
149
214
|
app_config[:log_level] = !app_config[:log_level].nil? ? Util::Logging::SEV_LABEL.key(app_config[:log_level].upcase) : Logger::INFO
|
150
215
|
app_config[:enable_raw_request] = app_config[:enable_raw_request] ||= false
|
151
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
|
+
|
152
236
|
Util::Logging::LogConfigs.new(app_config[:log_format], app_config[:log_level])
|
153
237
|
|
154
238
|
logger.info('Initiating Kubernetes Discovery.')
|
@@ -162,14 +246,7 @@ begin
|
|
162
246
|
app_config_hash: app_config
|
163
247
|
)
|
164
248
|
|
165
|
-
|
166
|
-
when 'infra'
|
167
|
-
# Initiating Kubernetes infrastructure discovery
|
168
|
-
OciLogAnalyticsResourcesDiscovery.initiate_infra_discovery
|
169
|
-
when 'object'
|
170
|
-
# Initiating Kubernetes objects discovery
|
171
|
-
OciLogAnalyticsResourcesDiscovery.initiate_object_discovery
|
172
|
-
end
|
249
|
+
OciLogAnalyticsResourcesDiscovery.initiate_discovery
|
173
250
|
rescue StandardError => e
|
174
251
|
unless e.backtrace.empty?
|
175
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,33 +122,53 @@ module Discover
|
|
90
122
|
@free_text_response
|
91
123
|
end
|
92
124
|
|
93
|
-
def
|
125
|
+
def search_with_structured_query(query)
|
94
126
|
client = nil
|
95
127
|
begin
|
96
|
-
client = Util::OCIClients.get_clients[:
|
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)
|
145
|
+
client = nil
|
146
|
+
begin
|
147
|
+
client = Util::OCIClients.get_clients[:vcn_client]
|
97
148
|
response = client.get_vcn(vcn_id)
|
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
|
-
|
111
|
-
|
112
|
-
response = client.list_subnets(compartment_id, opts)
|
161
|
+
client = Util::OCIClients.get_clients[:vcn_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
|