Skip to content

Commit

Permalink
Merge pull request #929 from Shopify/tmp
Browse files Browse the repository at this point in the history
Fix CI
  • Loading branch information
RRethy committed Aug 4, 2023
2 parents 1c15c3e + 6f6ee9e commit 8ea5c92
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 32 deletions.
8 changes: 4 additions & 4 deletions krane.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
spec.add_dependency("ejson", "~> 1.0")
spec.add_dependency("colorize", "~> 0.8")
spec.add_dependency("statsd-instrument", ['>= 2.8', "< 4"])
spec.add_dependency("oj", "~> 3.0")
spec.add_dependency("multi_json")
spec.add_dependency("concurrent-ruby", "~> 1.1")
spec.add_dependency("jsonpath", "~> 1.0")
spec.add_dependency("thor", ">= 1.0", "< 2.0")
Expand All @@ -43,11 +43,11 @@ Gem::Specification.new do |spec|
spec.add_development_dependency("yard")

# Test framework
spec.add_development_dependency("minitest", "~> 5.12")
spec.add_development_dependency("minitest", "~> 5.19")
spec.add_development_dependency("minitest-stub-const", "~> 0.6")
spec.add_development_dependency("minitest-reporters")
spec.add_development_dependency("mocha", "~> 1.5")
spec.add_development_dependency("webmock", "~> 3.0")
spec.add_development_dependency("mocha", "~> 2.1")
spec.add_development_dependency("webmock", "~> 3.18")
spec.add_development_dependency("timecop")

# Debugging and analysis
Expand Down
4 changes: 2 additions & 2 deletions lib/krane/bindings_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ def parse_file(string)
end

def parse_json(string)
bindings = JSON.parse(string)
bindings = MultiJson.load(string)

unless bindings.is_a?(Hash)
raise ArgumentError, "Expected JSON data to be a hash."
end

bindings
rescue JSON::ParserError
rescue MultiJson::ParseError
nil
end

Expand Down
12 changes: 6 additions & 6 deletions lib/krane/cli/krane.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# frozen_string_literal: true
require 'krane'
require 'krane/oj'
require 'thor'
require 'krane/cli/version_command'
require 'krane/cli/restart_command'
require 'krane/cli/run_command'
require 'krane/cli/render_command'
require 'krane/cli/deploy_command'
require 'krane/cli/global_deploy_command'
require 'krane/cli/render_command'
require 'krane/cli/restart_command'
require 'krane/cli/run_command'
require 'krane/cli/version_command'
require 'multi_json'
require 'thor'

module Krane
module CLI
Expand Down
6 changes: 3 additions & 3 deletions lib/krane/cluster_resource_discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def api_paths
@api_path_cache["/"] ||= begin
raw_json, err, st = kubectl.run("get", "--raw", base_api_path, attempts: 5, use_namespace: false)
paths = if st.success?
JSON.parse(raw_json)["paths"]
MultiJson.load(raw_json)["paths"]
else
raise FatalKubeAPIError, "Error retrieving raw path /: #{err}"
end
Expand All @@ -66,7 +66,7 @@ def fetch_api_path(path)
@api_path_cache[path] ||= begin
raw_json, err, st = kubectl.run("get", "--raw", path, attempts: 2, use_namespace: false)
if st.success?
JSON.parse(raw_json)
MultiJson.load(raw_json)
else
logger.warn("Error retrieving api path: #{err}")
{}
Expand All @@ -92,7 +92,7 @@ def fetch_crds
raw_json, err, st = kubectl.run("get", "CustomResourceDefinition", output: "json", attempts: 5,
use_namespace: false)
if st.success?
JSON.parse(raw_json)["items"]
MultiJson.load(raw_json)["items"]
else
raise FatalKubeAPIError, "Error retrieving CustomResourceDefinition: #{err}"
end
Expand Down
4 changes: 2 additions & 2 deletions lib/krane/deploy_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def namespace_definition
@namespace_definition ||= begin
definition, _err, st = kubectl.run("get", "namespace", @namespace, use_namespace: false,
log_failure: true, raise_if_not_found: true, attempts: 3, output: 'json')
st.success? ? JSON.parse(definition, symbolize_names: true) : nil
st.success? ? MultiJson.load(definition, symbolize_names: true) : nil
end
rescue Kubectl::ResourceNotFoundError
nil
Expand Down Expand Up @@ -362,7 +362,7 @@ def ejson_keys_secret
unless st.success?
raise EjsonSecretError, "Error retrieving Secret/#{EjsonSecretProvisioner::EJSON_KEYS_SECRET}: #{err}"
end
JSON.parse(out)
MultiJson.load(out)
end
end

Expand Down
8 changes: 4 additions & 4 deletions lib/krane/ejson_secret_provisioner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def generate_secret_resource(secret_name, secret_type, data)

def load_ejson_from_file
return {} unless File.exist?(@ejson_file)
JSON.parse(File.read(@ejson_file))
rescue JSON::ParserError => e
MultiJson.load(File.read(@ejson_file))
rescue MultiJson::ParseError => e
raise EjsonSecretError, "Failed to parse encrypted ejson:\n #{e}"
end

Expand All @@ -139,8 +139,8 @@ def decrypt_ejson(key_dir)
msg = err.presence || out
raise EjsonSecretError, msg
end
JSON.parse(out)
rescue JSON::ParserError
MultiJson.load(out)
rescue MultiJson::ParseError
raise EjsonSecretError, "Failed to parse decrypted ejson"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/krane/kubectl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def version_info
response, _, status = run("version", output: "json", use_namespace: false, log_failure: true, attempts: 2)
raise KubectlError, "Could not retrieve kubectl version info" unless status.success?

version_data = JSON.parse(response)
version_data = MultiJson.load(response)
client_version = platform_agnostic_version(version_data.dig("clientVersion", "gitVersion").to_s)
server_version = platform_agnostic_version(version_data.dig("serverVersion", "gitVersion").to_s)
unless client_version && server_version
Expand Down
4 changes: 0 additions & 4 deletions lib/krane/oj.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/krane/resource_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def fetch_by_kind(kind)
raise KubectlError unless st.success?

instances = {}
JSON.parse(raw_json)["items"].each do |resource|
MultiJson.load(raw_json)["items"].each do |resource|
resource_name = resource.dig("metadata", "name")
instances[resource_name] = resource
end
Expand Down
2 changes: 1 addition & 1 deletion lib/krane/resource_deployer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def create_resource(resource)
# For resources that rely on a generateName attribute, we get the `name` from the result of the call to `create`
# We must explicitly set this name value so that the `apply` step for pruning can run successfully
if status.success? && resource.uses_generate_name?
resource.use_generated_name(JSON.parse(out))
resource.use_generated_name(MultiJson.load(out))
end

[err, status]
Expand Down
4 changes: 2 additions & 2 deletions lib/krane/rollout_conditions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class << self
def from_annotation(conditions_string)
return new(default_conditions) if conditions_string.downcase.strip == "true"

conditions = JSON.parse(conditions_string).slice('success_conditions', 'failure_conditions')
conditions = MultiJson.load(conditions_string).slice('success_conditions', 'failure_conditions')
conditions.deep_symbolize_keys!

# Create JsonPath objects
Expand All @@ -26,7 +26,7 @@ def from_annotation(conditions_string)
end

new(conditions)
rescue JSON::ParserError => e
rescue MultiJson::ParseError => e
raise RolloutConditionsError, "Rollout conditions are not valid JSON: #{e}"
rescue StandardError => e
raise RolloutConditionsError,
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/cluster_resource_discovery_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def stub_raw_apis(success:)
Krane::Kubectl.any_instance.stubs(:run).with("get", "--raw", "/", attempts: 5, use_namespace: false)
.returns([api_raw_full_response, "", stub(success?: success)])

paths = JSON.parse(api_raw_full_response)['paths'].select { |p| %r{^\/api.*\/v.*$}.match(p) }
paths = MultiJson.load(api_raw_full_response)['paths'].select { |p| %r{^\/api.*\/v.*$}.match(p) }
paths.each do |path|
Krane::Kubectl.any_instance.stubs(:run).with("get", "--raw", path, attempts: 2, use_namespace: false)
.returns([apis_full_response(path), "", stub(success?: true)])
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/fixture_deploy_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def load_fixtures(set, subset)
fixtures = {}
if !subset || subset.include?("secrets.ejson")
ejson_file = File.join(fixture_path(set), EJSON_FILENAME)
fixtures[EJSON_FILENAME] = JSON.parse(File.read(ejson_file)) if File.exist?(ejson_file)
fixtures[EJSON_FILENAME] = MultiJson.load(File.read(ejson_file)) if File.exist?(ejson_file)
end

Dir.glob("#{fixture_path(set)}/*.{yml,yaml}*").each do |filename|
Expand Down

0 comments on commit 8ea5c92

Please sign in to comment.