From 79cf12f39444a169a5d24a9881ae9795e5374b84 Mon Sep 17 00:00:00 2001 From: Jason Frey Date: Wed, 15 Apr 2020 09:52:13 -0400 Subject: [PATCH] Merge pull request #20070 from carbonin/orchestrator_add_owner_reference Add an owner reference to the orchestrator pod for all created objects (cherry picked from commit 1f070023fdaf08abf1f4dd8c0dc2ae9556f30477) --- .../object_definition.rb | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/container_orchestrator/object_definition.rb b/lib/container_orchestrator/object_definition.rb index fdc04d1580e..5dec1b19774 100644 --- a/lib/container_orchestrator/object_definition.rb +++ b/lib/container_orchestrator/object_definition.rb @@ -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}}, @@ -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, @@ -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 } @@ -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