Skip to content

Commit

Permalink
wrap jsonpath evalutations and raise on error
Browse files Browse the repository at this point in the history
  • Loading branch information
timothysmith0609 committed Nov 21, 2018
1 parent ec38f65 commit ffd511e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/kubernetes-deploy/kubernetes_resource/custom_resource.rb
Expand Up @@ -17,21 +17,21 @@ def deploy_succeeded?
return super unless rollout_params

rollout_params[:success_queries]&.all? do |query|
JsonPath.new(query[:path]).first(@instance_data) == query[:value]
jsonpath_query(path: query[:path]) == query[:value]
end
end

def deploy_failed?
return super unless rollout_params

rollout_params[:failure_queries].any? do |query|
JsonPath.new(query[:path]).first(@instance_data) == query[:value]
jsonpath_query(path: query[:path]) == query[:value]
end
end

def failure_message
messages = rollout_params[:failure_queries].map do |query|
JsonPath.new(query[:error_msg_path]).first(@instance_data) if query[:error_msg_path]
jsonpath_query(path: query[:error_msg_path]) if query[:error_msg_path]
end.compact
messages.present? ? messages.join("\n") : "error deploying #{id}"
end
Expand Down Expand Up @@ -59,5 +59,11 @@ def kind
def rollout_params
@rollout_params ||= @crd.rollout_params
end

def jsonpath_query(path:)
JsonPath.new(path).first(@instance_data)
rescue StandardError
raise FatalDeploymentError, "fatal error for #{id}. Failed to parse JsonPath for #{path}"
end
end
end

0 comments on commit ffd511e

Please sign in to comment.