Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/kubeclient/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ def define_entity_methods
patch_entity(entity.resource_name, name, patch, 'strategic-merge-patch', namespace)
end

define_singleton_method("patch_#{entity.method_names[0]}_status") \
do |name, patch, namespace = nil|
patch_entity_status(entity.resource_name, name, patch, 'strategic-merge-patch', namespace)
end

define_singleton_method("json_patch_#{entity.method_names[0]}") \
do |name, patch, namespace = nil|
patch_entity(entity.resource_name, name, patch, 'json-patch', namespace)
Expand Down Expand Up @@ -395,6 +400,18 @@ def update_entity(resource_name, entity_config)
format_response(@as, response.body)
end

def patch_entity_status(resource_name, name, patch, strategy, namespace)
ns_prefix = build_namespace_prefix(namespace)
response = handle_exception do
rest_client[ns_prefix + resource_name + "/#{name}/status"]
.patch(
patch.to_json,
{ 'Content-Type' => "application/#{strategy}+json" }.merge(@headers)
)
end
format_response(@as, response.body)
end

def patch_entity(resource_name, name, patch, strategy, namespace)
ns_prefix = build_namespace_prefix(namespace)
response = handle_exception do
Expand Down
34 changes: 34 additions & 0 deletions test/test_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,40 @@ def test_patch_service
end
end

def test_patch_service_status
service = Kubeclient::Resource.new
name = 'my_service'

service.metadata = {}
service.metadata.name = name
service.metadata.namespace = 'development'

stub_core_api_list
expected_url = "http://localhost:8080/api/v1/namespaces/development/services/#{name}/status"
stub_request(:patch, expected_url)
.to_return(body: open_test_file('service_patch.json'), status: 200)

patch = {
status: {
conditions: [
{
type: 'StatusType',
status: 'True',
}
]
}
}

client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
service = client.patch_service_status(name, patch, 'development')
assert_kind_of(RecursiveOpenStruct, service)

assert_requested(:patch, expected_url, times: 1) do |req|
data = JSON.parse(req.body)
data['status']['conditions'].find { |c| c['type'] == 'StatusType' }['status'] == 'True'
end
end

def test_json_patch_service
service = Kubeclient::Resource.new
name = 'my-service'
Expand Down