Skip to content

Commit

Permalink
Add an owner reference to the orchestrator pod for all created objects
Browse files Browse the repository at this point in the history
This will allow anything we create to be automatically removed when
the orchestrator pod is removed for any reason. If the pod is cleanly
scaled down we will continue to tell the workers to exit cleanly, but
if the orchestrator is abruptly removed this will ensure everything
is cleaned up properly.

Fixes ManageIQ/manageiq-pods#428
  • Loading branch information
carbonin committed Apr 9, 2020
1 parent a59d08c commit 539a2cb
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions lib/container_orchestrator/object_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ module ObjectDefinition
def deployment_definition(name)
{
:metadata => {
:name => name,
:labels => {:app => app_name},
:namespace => my_namespace,
:name => name,
:labels => {:app => app_name},
:namespace => my_namespace,
:ownerReferences => owner_references
},
:spec => {
:selector => {:matchLabels => {:name => name}},
Expand All @@ -30,9 +31,10 @@ def deployment_definition(name)
def service_definition(name, selector, port)
{
:metadata => {
:name => name,
:labels => {:app => app_name},
:namespace => my_namespace
:name => name,
:labels => {:app => app_name},
:namespace => my_namespace,
:ownerReferences => owner_references
},
:spec => {
:selector => selector,
Expand All @@ -48,9 +50,10 @@ def service_definition(name, selector, port)
def secret_definition(name, string_data)
{
:metadata => {
:name => name,
:labels => {:app => app_name},
:namespace => my_namespace
:name => name,
:labels => {:app => app_name},
:namespace => my_namespace,
:ownerReferences => owner_references
},
:stringData => string_data
}
Expand Down Expand Up @@ -101,5 +104,16 @@ def my_namespace
def app_name
ENV["APP_NAME"]
end

def owner_references
[{
:apiVersion => "v1",
:blockOwnerDeletion => true,
:controller => true,
:kind => "Pod",
:name => ENV["POD_NAME"],
:uid => ENV["POD_UID"]
}]
end
end
end

0 comments on commit 539a2cb

Please sign in to comment.