@@ -9,7 +9,7 @@ class Deployment(Resource):
99 api_prefix = 'apis'
1010 api_version = 'apps/v1'
1111
12- def get (self , namespace , name = None , ** kwargs ):
12+ def get (self , namespace , name = None , ignore_exception = False , ** kwargs ):
1313 """
1414 Fetch a single Deployment or a list
1515 """
@@ -24,7 +24,7 @@ def get(self, namespace, name=None, **kwargs):
2424
2525 url = self .api (url , * args )
2626 response = self .http_get (url , params = self .query_params (** kwargs ))
27- if self .unhealthy (response .status_code ):
27+ if self .unhealthy (response .status_code ) and not ignore_exception :
2828 args .reverse () # error msg is in reverse order
2929 raise KubeHTTPException (response , message , * args )
3030
@@ -115,40 +115,43 @@ def manifest(self, namespace, name, image, command, args, spec_annotations, **kw
115115
116116 return manifest
117117
118- def create (self , namespace , name , image , command , args , spec_annotations , ** kwargs ):
118+ def create (self , namespace , name , image , command , args ,
119+ spec_annotations , ignore_exception = False , ** kwargs ):
119120 manifest = self .manifest (namespace , name , image ,
120121 command , args , spec_annotations , ** kwargs )
121122
122123 url = self .api ("/namespaces/{}/deployments" , namespace )
123124 response = self .http_post (url , json = manifest )
124125 if self .unhealthy (response .status_code ):
125126 self .log (namespace , 'template: {}' .format (json .dumps (manifest , indent = 4 )), 'DEBUG' )
126- raise KubeHTTPException (
127- response ,
128- 'create Deployment "{}" in Namespace "{}"' , name , namespace
129- )
130-
131- self . wait_until_updated ( namespace , name )
132- self .wait_until_ready (namespace , name , ** kwargs )
133-
127+ if not ignore_exception :
128+ raise KubeHTTPException (
129+ response ,
130+ 'create Deployment "{}" in Namespace "{}"' , name , namespace
131+ )
132+ else :
133+ self .wait_until_updated (namespace , name )
134+ self . wait_until_ready ( namespace , name , ** kwargs )
134135 return response
135136
136- def update (self , namespace , name , image , command , args , spec_annotations , ** kwargs ):
137+ def update (self , namespace , name , image , command , args ,
138+ spec_annotations , ignore_exception = False , ** kwargs ):
137139 manifest = self .manifest (namespace , name , image ,
138140 command , args , spec_annotations , ** kwargs )
139141
140142 url = self .api ("/namespaces/{}/deployments/{}" , namespace , name )
141143 response = self .http_put (url , json = manifest )
142144 if self .unhealthy (response .status_code ):
143145 self .log (namespace , 'template: {}' .format (json .dumps (manifest , indent = 4 )), 'DEBUG' )
144- raise KubeHTTPException ( response , 'update Deployment "{}"' , name )
145-
146- self . wait_until_updated ( namespace , name )
147- self .wait_until_ready (namespace , name , ** kwargs )
148-
146+ if not ignore_exception :
147+ raise KubeHTTPException ( response , 'update Deployment "{}"' , name )
148+ else :
149+ self .wait_until_updated (namespace , name )
150+ self . wait_until_ready ( namespace , name , ** kwargs )
149151 return response
150152
151- def patch (self , namespace , name , image , command , args , spec_annotations , ** kwargs ):
153+ def patch (self , namespace , name , image , command , args ,
154+ spec_annotations , ignore_exception = False , ** kwargs ):
152155 manifest = self .manifest (namespace , name , image ,
153156 command , args , spec_annotations , ** kwargs )
154157
@@ -161,11 +164,11 @@ def patch(self, namespace, name, image, command, args, spec_annotations, **kwarg
161164
162165 if self .unhealthy (response .status_code ):
163166 self .log (namespace , 'template: {}' .format (json .dumps (manifest , indent = 4 )), 'DEBUG' )
164- raise KubeHTTPException ( response , 'patch Deployment "{}"' , name )
165-
166- self . wait_until_updated ( namespace , name )
167- self .wait_until_ready (namespace , name , ** kwargs )
168-
167+ if not ignore_exception :
168+ raise KubeHTTPException ( response , 'patch Deployment "{}"' , name )
169+ else :
170+ self .wait_until_updated (namespace , name )
171+ self . wait_until_ready ( namespace , name , ** kwargs )
169172 return response
170173
171174 def delete (self , namespace , name , ignore_exception = False ):
@@ -200,7 +203,7 @@ def scale(self, namespace, name, **kwargs):
200203 kwargs ['previous_replicas' ] = current
201204 self .wait_until_ready (namespace , name , ** kwargs )
202205
203- def restart (self , namespace , name ):
206+ def restart (self , namespace , name , ignore_exception = False ):
204207 url = self .api (
205208 "/namespaces/{}/deployments/{}?fieldManager=kubectl-rollout&pretty=true" ,
206209 namespace , name
@@ -221,7 +224,7 @@ def restart(self, namespace, name):
221224 }),
222225 headers = {"Content-Type" : "application/merge-patch+json" },
223226 )
224- if self .unhealthy (response .status_code ):
227+ if self .unhealthy (response .status_code ) and not ignore_exception :
225228 raise KubeHTTPException (
226229 response ,
227230 'restart Deployment "{}" in Namespace "{}"' , name , namespace
0 commit comments