oci-logging-analytics-kubernetes-discovery 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +40 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +7 -0
  5. data/LICENSE.txt +36 -0
  6. data/README.md +83 -0
  7. data/Rakefile +15 -0
  8. data/bin/console +17 -0
  9. data/bin/oci-loganalytics-kubernetes-discovery +184 -0
  10. data/bin/setup +12 -0
  11. data/lib/config/oci_client_retry_config.rb +34 -0
  12. data/lib/discover/infrastructure.rb +122 -0
  13. data/lib/discover/object.rb +347 -0
  14. data/lib/dto/infra/cluster_entity_payload.rb +22 -0
  15. data/lib/dto/infra/load_balancers_entity_payload.rb +22 -0
  16. data/lib/dto/infra/node_pool_entity_payload.rb +24 -0
  17. data/lib/dto/infra/subnet_entity_payload.rb +22 -0
  18. data/lib/dto/infra/vcn_entity_payload.rb +22 -0
  19. data/lib/dto/infra_objects_payload.rb +40 -0
  20. data/lib/dto/kubernetes_objects_payload.rb +58 -0
  21. data/lib/dto/payload/log_events.rb +26 -0
  22. data/lib/dto/payload/log_events_json.rb +22 -0
  23. data/lib/dto/state.rb +19 -0
  24. data/lib/enum/auth_type_enum.rb +9 -0
  25. data/lib/enum/infrastructure_resource_discovery.rb +9 -0
  26. data/lib/enum/kubernetes_objects_enum.rb +22 -0
  27. data/lib/enum/object_client_mapping_enum.rb +21 -0
  28. data/lib/infra_resources.rb +91 -0
  29. data/lib/objects_resources.rb +174 -0
  30. data/lib/oci_loganalytics_resources_discovery.rb +293 -0
  31. data/lib/util/kube_client.rb +141 -0
  32. data/lib/util/kubectl_ops.rb +229 -0
  33. data/lib/util/log_analytics.rb +154 -0
  34. data/lib/util/logging.rb +96 -0
  35. data/lib/util/oci_clients.rb +228 -0
  36. data/lib/util/state_manager.rb +61 -0
  37. data/lib/util/string_utils.rb +16 -0
  38. data/lib/version.rb +6 -0
  39. data/oci-logging-analytics-kubernetes-discovery.gemspec +45 -0
  40. metadata +324 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 91e5befbfc8bd2e885d9965cc8dcf9fcf52d8efb
4
+ data.tar.gz: f54c28695b070ad4566cfe0320f713fd71a1ed30
5
+ SHA512:
6
+ metadata.gz: 7122da1196e19892247ed00fe61a14490b9cc43c1a4a810c76275ec808978fc7db40281b2b5b0312af10bf616f11a8abb60fdc20fa1e044973d784a46a44dd56
7
+ data.tar.gz: 353ad156e28982d160fb8b977b064de2768ef024409d893cfe79df6dbb8ca40c93db4d2a43d72143620b6d22227dcca2d72a6326c2aa18b09c55bfe8012d4852
data/.gitignore ADDED
@@ -0,0 +1,40 @@
1
+ ### Project Binaries ###
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ ### Ruby ###
12
+ .rspec_status
13
+
14
+ ### IntelliJ IDEA ###
15
+ .idea
16
+ *.iws
17
+ *.iml
18
+ *.ipr
19
+ out/
20
+ !**/src/main/**/out/
21
+ !**/src/test/**/out/
22
+
23
+ ### NetBeans ###
24
+ /nbproject/private/
25
+ /nbbuild/
26
+ /dist/
27
+ /nbdist/
28
+ /.nb-gradle/
29
+
30
+ ### VS Code ###
31
+ .vscode/
32
+
33
+ ### Development Test scripts ###
34
+ test-run*.sh
35
+
36
+ ### Gems ###
37
+ *.gem
38
+
39
+ ### Data files ###
40
+ *.dat
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,7 @@
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
+ source 'https://rubygems.org'
5
+
6
+ # Specify your gem's dependencies in oci-logging-analytics-kubernetes-discovery.gemspec
7
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,36 @@
1
+ Copyright (c) 2024 Oracle and/or its affiliates.
2
+
3
+ The Universal Permissive License (UPL), Version 1.0
4
+
5
+ Subject to the condition set forth below, permission is hereby granted to any
6
+ person obtaining a copy of this software, associated documentation and/or data
7
+ (collectively the "Software"), free of charge and under any and all copyright
8
+ rights in the Software, and any and all patent rights owned or freely
9
+ licensable by each licensor hereunder covering either (i) the unmodified
10
+ Software as contributed to or provided by such licensor, or (ii) the Larger
11
+ Works (as defined below), to deal in both
12
+
13
+ (a) the Software, and
14
+ (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15
+ one is included with the Software (each a "Larger Work" to which the Software
16
+ is contributed by such licensors),
17
+
18
+ without restriction, including without limitation the rights to copy, create
19
+ derivative works of, display, perform, and distribute the Software and make,
20
+ use, sell, offer for sale, import, export, have made, and have sold the
21
+ Software and the Larger Work(s), and to sublicense the foregoing rights on
22
+ either these or other terms.
23
+
24
+ This license is subject to the following condition:
25
+
26
+ The above copyright notice and either this complete permission notice or at
27
+ a minimum a reference to the UPL must be included in all copies or
28
+ substantial portions of the Software.
29
+
30
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # OCI Logging Analytics Kubernetes Discovery
2
+
3
+ ## Overview
4
+
5
+ A rubygem for discovering Kubernetes resources and send it to OCI Logging Analytics.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'oci-logging-analytics-kubernetes-discovery'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```shell
18
+ $ bundle install
19
+ ```
20
+
21
+ Or install it yourself as:
22
+
23
+ ```ruby
24
+ $ gem install oci-logging-analytics-kubernetes-discovery
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ```
30
+ Usage: oci-loganalytics-kubernetes-discovery [options]
31
+ --oci_la_namespace OCI_LA_NAMESPACE
32
+ OCI Tenancy Namespace to which the collected log data is to be uploaded
33
+ --oci_la_log_group_id OCI_LA_LOG_GROUP_ID
34
+ OCID of Logging Analytics Log Group to which the uploaded data is to be associated with
35
+ --oci_la_cluster_entity_id KUBERNETES_CLUSTER_ENTITY_ID
36
+ OCID of Logging Analytics Kubernetes Cluster entity
37
+ --kubernetes_cluster_name KUBERNETES_CLUSTER_NAME
38
+ A unique name for each kubernetes cluster must be provided
39
+ --kubernetes_cluster_namespace KUBERNETES_CLUSTER_NAMESPACE
40
+ Kubernetes namespace in which the discovery job is configured
41
+ --kubernetes_resourcename_prefix PREFIX
42
+ Kubernetes cluster resourcename prefix. Defaults to oci-onm
43
+ --kubernetes_cluster_id KUBERNETES_CLUSTER_ID
44
+ Unique identifier for Kubernetes cluster
45
+ --endpoint ENDPOINT Logging Analytics Ingestion API endpoint to ingest your application logs
46
+ --profile_name PROFILE_NAME OCI Config Profile Name to be used from the configuration file
47
+ --config_file_location CONFIG_FILE_LOCATION
48
+ The location of the configuration file containing OCI authentication details
49
+ --kube_config_location KUBE_CONFIG_LOCATION
50
+ Path to the kubernetes configuration (kubeconfig) file
51
+ --kubernetes_url KUBERNETES_URL
52
+ Kubernetes API server URL. Alternatively, environment variables KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT can be used
53
+ --client_cert CLIENT_CERT Path to certificate file for Kubernetes HTTPs/SSL server certificate validation
54
+ --client_key CLIENT_KEY Path to key for Kubernetes HTTPs/SSL server certificate validation
55
+ --ca_file CA_FILE Path to CA file for Kubernetes HTTPs/SSL server certificate validation
56
+ --verify_ssl Validate SSL certificates while creating kube clients
57
+ --bearer_token_file BEARER_TOKEN_FILE
58
+ Path to bearer token file if basic authentication is used
59
+ --secret_dir SECRET_DIR Path to Kubernetes service account token file to access Kubernetes API
60
+ --discovery DISCOVERY_MODE Discovery mode to be used: {infra|object}
61
+ --chunk_limit CHUNK_SIZE Max number of objects that can be fetched via K8s GET API call. Default: 1000
62
+ --skip_upload Flag to skip uploading data to OCI Logging Analytics [ONLY FOR INTERNAL TESTING]
63
+ --collect_warning_events_only
64
+ Flag to collect only warning event logs
65
+ --log_format LOG_FORMAT Log format to be used: {text|json}
66
+ --log_level LOG_LEVEL User defined log level: {trace|debug|info|warn|error|fatal}
67
+ --enable_threading Defaults to sequential execution when parameter is not provided
68
+ --thread_count THREAD_COUNT Number of parallel threads to be used while making requests to API server
69
+ --enable_raw_request If set, signs the raw request while uploading payloads to Discovery API. The default behavior is to use OCI Ruby SDK
70
+ --help Print complete help information and exit
71
+ ```
72
+
73
+ ## License
74
+
75
+ Copyright (c) 2024 Oracle and/or its affiliates.
76
+
77
+ The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/.
78
+
79
+ See [LICENSE](LICENSE.txt) for more details.
80
+
81
+ ## Re-distribution Note
82
+
83
+ If you need to re-distribute this as part of any other binary, you may need to ensure including all the necessary [runtime dependencies](oci-logging-analytics-kubernetes-discovery.gemspec) along with their transitive dependencies. Also, you may need to take care of the necessary attributions as required.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
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
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ # Adds the tests directory to the lists of directories in the #$LOADPATH
8
+ t.libs << 'tests'
9
+
10
+ # Creates a list of files that match 'test/*_test.rb'
11
+ t.test_files = FileList['test/*_test.rb']
12
+
13
+ # If you want your tests to output what they should do, then set this to true.
14
+ t.verbose = true
15
+ end
data/bin/console ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ## Copyright (c) 2024 Oracle and/or its affiliates.
4
+ ## The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
5
+
6
+ require 'bundler/setup'
7
+ require 'oci-logging-analytics-kubernetes-discovery'
8
+
9
+ # You can add fixtures and/or initialization code here to make experimenting
10
+ # with your gem easier. You can also use a different console, if you like.
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ require 'irb'
17
+ IRB.start(__FILE__)
@@ -0,0 +1,184 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ## Copyright (c) 2024 Oracle and/or its affiliates.
4
+ ## The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
5
+
6
+ require 'optparse'
7
+
8
+ require_relative '../lib/oci_loganalytics_resources_discovery'
9
+ require_relative '../lib/util/logging'
10
+ require_relative '../lib/util/string_utils'
11
+
12
+ extend Util::Logging
13
+ extend Util::StringUtils
14
+
15
+ cluster_config = {}
16
+ auth_config = {}
17
+ kube_config = {}
18
+ app_config = {}
19
+
20
+ DISCOVERY_OPTIONS = %w[infra object].freeze
21
+ LOG_FMT_OPTIONS = %w[text json].freeze
22
+ CHUNK_LIMIT_DEFAULT = 1000
23
+
24
+ optparse = OptionParser.new do |param|
25
+ # TODO: Naming of the gem and command.
26
+ param.banner = "\nUsage: oci-loganalytics-kubernetes-discovery [options]"
27
+
28
+ # Mandatory Fields
29
+ param.on('--oci_la_namespace OCI_LA_NAMESPACE', 'OCI Tenancy Namespace to which the collected log data is to be uploaded') { |o| cluster_config[:oci_la_namespace] = o }
30
+ param.on('--oci_la_log_group_id OCI_LA_LOG_GROUP_ID', 'OCID of Logging Analytics Log Group to which the uploaded data is to be associated with') { |o| cluster_config[:oci_la_log_group_id] = o }
31
+ param.on('--oci_la_cluster_entity_id KUBERNETES_CLUSTER_ENTITY_ID', 'OCID of Logging Analytics Kubernetes Cluster entity') { |o| cluster_config[:oci_la_cluster_entity_id] = o }
32
+ param.on('--kubernetes_cluster_name KUBERNETES_CLUSTER_NAME', 'A unique name for each kubernetes cluster must be provided') { |o| cluster_config[:kubernetes_cluster_name] = o }
33
+ param.on('--kubernetes_cluster_namespace KUBERNETES_CLUSTER_NAMESPACE', 'Kubernetes namespace in which the discovery job is configured') { |o| cluster_config[:kubernetes_cluster_namespace] = o }
34
+ param.on('--kubernetes_resourcename_prefix PREFIX', 'Kubernetes cluster resourcename prefix. Defaults to oci-onm') { |o| cluster_config[:kubernetes_resourcename_prefix] = o }
35
+ param.on('--kubernetes_cluster_id KUBERNETES_CLUSTER_ID', 'Unique identifier for Kubernetes cluster') { |o| cluster_config[:kubernetes_cluster_id] = o }
36
+
37
+ # 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
+ param.on('--profile_name PROFILE_NAME', 'OCI Config Profile Name to be used from the configuration file') { |o| auth_config[:profile_name] = o }
40
+ 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
+
42
+ # Kubernetes Cluster
43
+ # For AuthNAuth when the job is outside the cluster.
44
+ param.on('--kube_config_location KUBE_CONFIG_LOCATION', 'Path to the kubernetes configuration (kubeconfig) file') { |o| kube_config[:kube_config_location] = o }
45
+ param.on('--kubernetes_url KUBERNETES_URL', 'Kubernetes API server URL. Alternatively, environment variables KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT can be used') { |o| kube_config[:kubernetes_url] = o }
46
+ # For AuthNAuth when the job is within the same cluster.
47
+ param.on('--client_cert CLIENT_CERT', 'Path to certificate file for Kubernetes HTTPs/SSL server certificate validation') { |o| kube_config[:client_cert] = o }
48
+ param.on('--client_key CLIENT_KEY', 'Path to key for Kubernetes HTTPs/SSL server certificate validation') { |o| kube_config[:client_key] = o }
49
+ param.on('--ca_file CA_FILE', 'Path to CA file for Kubernetes HTTPs/SSL server certificate validation') { |o| kube_config[:ca_file] = o }
50
+ param.on('--verify_ssl', 'Validate SSL certificates while creating kube clients') { |_o| kube_config[:verify_ssl] = true }
51
+ # For AuthNAuth using bearer token.
52
+ param.on('--bearer_token_file BEARER_TOKEN_FILE', 'Path to bearer token file if basic authentication is used') { |o| kube_config[:bearer_token_file] = o }
53
+ param.on('--secret_dir SECRET_DIR', 'Path to Kubernetes service account token file to access Kubernetes API') { |o| kube_config[:secret_dir] = o }
54
+
55
+ # Discovery
56
+ param.on('--discovery DISCOVERY_MODE', "Discovery mode to be used: #{format_option_selections(DISCOVERY_OPTIONS)}") { |o| app_config[:mode] = o.downcase }
57
+ 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
+ param.on('--skip_upload', 'Flag to skip uploading data to OCI Logging Analytics [ONLY FOR INTERNAL TESTING]') { |_o| app_config[:skip_upload] = true }
59
+ param.on('--collect_warning_events_only', 'Flag to collect only warning event logs') { |_o| app_config[:collect_warning_events_only] = true }
60
+
61
+ # Logging and threading
62
+ param.on('--log_format LOG_FORMAT', "Log format to be used: #{format_option_selections(LOG_FMT_OPTIONS)}") { |o| app_config[:log_format] = o }
63
+ param.on('--log_level LOG_LEVEL', "User defined log level: #{format_option_selections(Util::Logging::SEV_LABEL.values)}") { |o| app_config[:log_level] = o }
64
+ param.on('--enable_threading', 'Defaults to sequential execution when parameter is not provided') { |o| app_config[:enable_threading] = o }
65
+ param.on('--thread_count THREAD_COUNT', Integer, 'Number of parallel threads to be used while making requests to API server') { |o| app_config[:thread_count] = o }
66
+ param.on('--enable_raw_request', 'If set, signs the raw request while uploading payloads to Discovery API. The default behavior is to use OCI Ruby SDK') { |o| app_config[:enable_raw_request] = o }
67
+
68
+ param.on('--help', 'Print complete help information and exit') do
69
+ puts param
70
+ exit
71
+ end
72
+ end
73
+
74
+ # Initial logging configs (format is 'text', level is 'info').
75
+ Util::Logging::LogConfigs.new(LOG_FMT_OPTIONS.first, Logger::INFO)
76
+
77
+ # Argument Validations
78
+ begin
79
+ optparse.parse!
80
+
81
+ # Check if mandatory arguments are missing.
82
+ mandatory = %i[oci_la_namespace oci_la_log_group_id kubernetes_cluster_id kubernetes_cluster_name kubernetes_cluster_namespace]
83
+ missing = mandatory.select { |param| cluster_config[param].nil? || cluster_config[param].empty? } # .empty gates 'key=' edge case
84
+ raise OptionParser::MissingArgument, missing.join(', ') unless missing.empty?
85
+
86
+ # Valid discovery mode check.
87
+ unless app_config[:mode].nil?
88
+ unless DISCOVERY_OPTIONS.include? app_config[:mode]
89
+ raise OptionParser::InvalidOption, "--discovery=#{app_config[:mode]}"
90
+ end
91
+
92
+ # Threads valid only for object discovery (not for infrastrucutre discovery).
93
+ if app_config[:mode] == DISCOVERY_OPTIONS.first && app_config[:enable_threading]
94
+ logger.info("Multi-threading is only supported for mode: #{DISCOVERY_OPTIONS.second}")
95
+ raise OptionParser::InvalidOption, '--enable_threading'
96
+ end
97
+ end
98
+
99
+ # If threads are enabled, thread count and queue size should be provided as arguments.
100
+ if app_config[:enable_threading] && app_config[:thread_count].nil?
101
+ raise OptionParser::MissingArgument, '--thread_count'
102
+ end
103
+
104
+ if app_config[:chunk_limit] && app_config[:chunk_limit] > 10_000
105
+ raise OptionParser::InvalidOption, '--chunk_limit is too large.'
106
+ end
107
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
108
+ logger.info(e.to_s.capitalize)
109
+ logger.info(optparse)
110
+ exit(1)
111
+ end
112
+
113
+ # Set defaults for skipped inputs
114
+
115
+ cluster_config[:kubernetes_cluster_id] = cluster_config[:kubernetes_cluster_id] ||= nil
116
+ cluster_config[:oci_la_cluster_entity_id] = cluster_config[:oci_la_cluster_entity_id] ||= nil
117
+ cluster_config[:kubernetes_resourcename_prefix] = cluster_config[:kubernetes_resourcename_prefix] ||= 'oci-onm'
118
+
119
+ # Config based auth
120
+ auth_config[:endpoint] = auth_config[:endpoint] ||= nil
121
+ auth_config[:profile_name] = auth_config[:profile_name] ||= 'DEFAULT'
122
+ auth_config[:config_file_location] = auth_config[:config_file_location] ||= nil
123
+
124
+ # Kubernetes cluster related
125
+ kube_config[:kube_config_location] = kube_config[:kube_config_location] ||= nil
126
+ kube_config[:kubernetes_url] = kube_config[:kubernetes_url] ||= nil
127
+ kube_config[:api_endpoint] = kube_config[:api_endpoint] ||= 'api'
128
+ kube_config[:api_version] = kube_config[:api_version] ||= 'v1'
129
+ kube_config[:client_cert] = kube_config[:client_cert] ||= nil
130
+ kube_config[:client_key] = kube_config[:client_key] ||= nil
131
+ kube_config[:ca_file] = kube_config[:ca_file] ||= nil
132
+ kube_config[:verify_ssl] = kube_config[:verify_ssl] ||= false
133
+ kube_config[:bearer_token_file] = kube_config[:bearer_token_file] ||= nil
134
+ kube_config[:secret_dir] = kube_config[:secret_dir] ||= '/var/run/secrets/kubernetes.io/serviceaccount'
135
+
136
+ # Discovery
137
+ app_config[:mode] = app_config[:mode] ||= 'object'
138
+ app_config[:skip_upload] = app_config[:skip_upload] ||= false
139
+ app_config[:collect_warning_events_only] = app_config[:collect_warning_events_only] ||= false
140
+ app_config[:chunk_limit] = app_config[:chunk_limit] ||= CHUNK_LIMIT_DEFAULT
141
+
142
+ # Threading
143
+ app_config[:enable_threading] = app_config[:enable_threading] ||= false
144
+ app_config[:thread_count] = app_config[:thread_count] ||= 1
145
+ app_config[:work_queue_size] = app_config[:work_queue_size] ||= (app_config[:thread_count] * 5)
146
+
147
+ # Log level and format provided in arguement
148
+ app_config[:log_format] = app_config[:log_format] ||= LOG_FMT_OPTIONS.first
149
+ app_config[:log_level] = !app_config[:log_level].nil? ? Util::Logging::SEV_LABEL.key(app_config[:log_level].upcase) : Logger::INFO
150
+ app_config[:enable_raw_request] = app_config[:enable_raw_request] ||= false
151
+
152
+ Util::Logging::LogConfigs.new(app_config[:log_format], app_config[:log_level])
153
+
154
+ logger.info('Initiating Kubernetes Discovery.')
155
+
156
+ begin
157
+ # Initializing required clients.
158
+ OciLogAnalyticsResourcesDiscovery.initialize(
159
+ cluster_config_hash: cluster_config,
160
+ auth_config_hash: auth_config,
161
+ kube_config_hash: kube_config,
162
+ app_config_hash: app_config
163
+ )
164
+
165
+ case app_config[:mode]
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
173
+ rescue StandardError => e
174
+ unless e.backtrace.empty?
175
+ stack_trace = "\n"
176
+ e.backtrace.each { |line| stack_trace += "#{line}\n" }
177
+ logger.error("Stack trace - #{stack_trace.rstrip}")
178
+ end
179
+ logger.error('Kubernetes discovery failed.')
180
+ exit(1)
181
+ end
182
+
183
+ logger.info('Kubernetes discovery is successfully completed.')
184
+ exit(0)
data/bin/setup ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env bash
2
+
3
+ ## Copyright (c) 2024 Oracle and/or its affiliates.
4
+ ## The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
5
+
6
+ set -euo pipefail
7
+ IFS=$'\n\t'
8
+ set -vx
9
+
10
+ bundle install
11
+
12
+ # Do any other automated setup that you need to do here
@@ -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
+ require_relative '../util/logging'
5
+
6
+ module Config
7
+ module OCIClientRetryConfig
8
+ extend Util::Logging
9
+
10
+ module_function
11
+
12
+ attr_accessor :retry_config
13
+
14
+ def set_default_retry_config
15
+ OCI::Retry::RetryConfig.new(
16
+ base_sleep_time_millis: 1000,
17
+ exponential_growth_factor: 2,
18
+ should_retry_exception_proc: OCI::Retry::Functions::ShouldRetryOnError.retry_on_network_error_throttle_and_internal_server_errors,
19
+ sleep_calc_millis_proc: OCI::Retry::Functions::Sleep.exponential_backoff_with_full_jitter,
20
+ max_attempts: 5,
21
+ max_elapsed_time_millis: 300_000, # 5 minutes
22
+ max_sleep_between_attempts_millis: 10_000
23
+ )
24
+ end
25
+
26
+ def set_custom_retry_config(custom_retry_config)
27
+ @retry_config = custom_retry_config
28
+ end
29
+
30
+ def get_retry_config
31
+ @retry_config.nil? ? set_default_retry_config : @retry_config
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,122 @@
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
+ require_relative '../util/logging'
5
+
6
+ # Util
7
+ require_relative '../util/oci_clients'
8
+
9
+ module Discover
10
+ module Infrastructure
11
+ extend Util::Logging
12
+ extend Util::OCIClients
13
+
14
+ module_function
15
+
16
+ def fetch_cluster_details(_auth_object, cluster_id)
17
+ client = nil
18
+ begin
19
+ client = Util::OCIClients.get_clients[:ce_client]
20
+ response = client.get_cluster(cluster_id)
21
+
22
+ @cluster_details = response.data
23
+ rescue StandardError => e
24
+ logger.error("Error while discovering cluster details: #{e}")
25
+ raise StandardError, 'Error while discovering cluster details.'
26
+ exit
27
+ end
28
+ @cluster_details
29
+ end
30
+
31
+ def fetch_node_pool_lists(_auth_object, compartment_id, cluster_id)
32
+ opts = { cluster_id: cluster_id }
33
+ begin
34
+ client = Util::OCIClients.get_clients[:ce_client]
35
+ response = client.list_node_pools(compartment_id, opts)
36
+
37
+ @node_pool_list = response.data
38
+ rescue StandardError => e
39
+ logger.error("Error while discovering node pool list: #{e}")
40
+ raise StandardError, 'Error while discovering node pool list.'
41
+ exit
42
+ end
43
+ @node_pool_list
44
+ end
45
+
46
+ def fetch_compartment_list(_auth_object, compartment_id)
47
+ client = nil
48
+ opts = { compartment_id_in_subtree: true, access_level: 'ANY' }
49
+ begin
50
+ client = Util::OCIClients.get_clients[:id_client]
51
+ response = client.list_compartments(compartment_id, opts)
52
+
53
+ @id_response = response.data
54
+ rescue StandardError => e
55
+ logger.error("Error while fetching load balancer details: #{e}")
56
+ raise StandardError, 'Error while fetching load balancer details.'
57
+ end
58
+ @id_response
59
+ end
60
+
61
+ def fetch_load_balancer_details(_auth_object, load_balancer_id)
62
+ client = nil
63
+ begin
64
+ client = Util::OCIClients.get_clients[:lb_client]
65
+ response = client.get_load_balancer(load_balancer_id)
66
+ @lb_response = response.data
67
+ rescue StandardError => e
68
+ logger.error("Error while fetching load balancer details: #{e}")
69
+ raise StandardError, 'Error while fetching load balancer details.'
70
+ end
71
+ @lb_response
72
+ end
73
+
74
+ def fetch_free_text_details(_auth_object, cluster_id)
75
+ client = nil
76
+ begin
77
+ client = Util::OCIClients.get_clients[:rs_client]
78
+ response = client.search_resources(
79
+ OCI::ResourceSearch::Models::FreeTextSearchDetails.new(
80
+ type: 'FreeText',
81
+ text: cluster_id,
82
+ matchingContextType: 'HIGHLIGHTS'
83
+ )
84
+ )
85
+ @free_text_response = response.data
86
+ rescue StandardError => e
87
+ logger.error("Error while fetching free text details: #{e}")
88
+ raise StandardError, 'Error while fetching free text details.'
89
+ end
90
+ @free_text_response
91
+ end
92
+
93
+ def fetch_vcn_response(_auth_object, vcn_id)
94
+ client = nil
95
+ begin
96
+ client = Util::OCIClients.get_clients[:vnc_client]
97
+ response = client.get_vcn(vcn_id)
98
+
99
+ @vnc_response = response.data
100
+ rescue StandardError => e
101
+ logger.error("Error while discovering VNC details: #{e}")
102
+ raise StandardError, 'Error while discovering VNC details.'
103
+ end
104
+ @vnc_response
105
+ end
106
+
107
+ def fetch_subnet_list_response(_auth_object, compartment_id, vcn_id)
108
+ client = nil
109
+ begin
110
+ opts = { vcn_id: vcn_id }
111
+ client = Util::OCIClients.get_clients[:vnc_client]
112
+ response = client.list_subnets(compartment_id, opts)
113
+
114
+ @subnet_response = response.data
115
+ rescue StandardError => e
116
+ logger.error("Error while discovering subnet details: #{e}")
117
+ raise StandardError, 'Error while discovering subnet details.'
118
+ end
119
+ @subnet_response
120
+ end
121
+ end
122
+ end