From 9d7355cbaaacc430d541d3bc7101a595ccd0bd8a Mon Sep 17 00:00:00 2001 From: Ta-Ching Chen Date: Wed, 15 Aug 2018 19:56:30 +0800 Subject: [PATCH] Fix newdeploy fail to update HPA, deployment of a function after function update (#862) --- executor/newdeploy/newdeploy.go | 4 ++-- executor/newdeploy/newdeploymgr.go | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/executor/newdeploy/newdeploy.go b/executor/newdeploy/newdeploy.go index 56192c8b..221b356d 100644 --- a/executor/newdeploy/newdeploy.go +++ b/executor/newdeploy/newdeploy.go @@ -425,9 +425,9 @@ func (deploy *NewDeploy) createOrGetHpa(hpaName string, execStrategy *fission.Ex } -func (deploy *NewDeploy) getHpa(fn *crd.Function) (*asv1.HorizontalPodAutoscaler, error) { +func (deploy *NewDeploy) getHpa(ns string, fn *crd.Function) (*asv1.HorizontalPodAutoscaler, error) { hpaName := deploy.getObjName(fn) - return deploy.kubernetesClient.AutoscalingV1().HorizontalPodAutoscalers(fn.Metadata.Namespace).Get(hpaName, metav1.GetOptions{}) + return deploy.kubernetesClient.AutoscalingV1().HorizontalPodAutoscalers(ns).Get(hpaName, metav1.GetOptions{}) } func (deploy *NewDeploy) updateHpa(hpa *asv1.HorizontalPodAutoscaler) error { diff --git a/executor/newdeploy/newdeploymgr.go b/executor/newdeploy/newdeploymgr.go index 110f2f2a..da29d9f1 100644 --- a/executor/newdeploy/newdeploymgr.go +++ b/executor/newdeploy/newdeploymgr.go @@ -397,7 +397,14 @@ func (deploy *NewDeploy) fnUpdate(oldFn *crd.Function, newFn *crd.Function) { return } - hpa, err := deploy.getHpa(newFn) + // to support backward compatibility, if the function was created in default ns, we fall back to creating the + // deployment of the function in fission-function ns, so cleaning up resources there + ns := deploy.namespace + if newFn.Metadata.Namespace != metav1.NamespaceDefault { + ns = newFn.Metadata.Namespace + } + + hpa, err := deploy.getHpa(ns, newFn) if err != nil { updateStatus(oldFn, err, "error getting HPA while updating function") return @@ -469,7 +476,7 @@ func (deploy *NewDeploy) fnUpdate(oldFn *crd.Function, newFn *crd.Function) { } deployName := deploy.getObjName(oldFn) deployLabels := deploy.getDeployLabels(oldFn, env) - log.Printf("updating deployment due to function update") + log.Printf("updating %v deployment due to function %v update", deployName, newFn.Metadata.Name) newDeployment, err := deploy.getDeploymentSpec(newFn, env, deployName, deployLabels) if err != nil { updateStatus(oldFn, err, "failed to get new deployment spec while updating function") @@ -580,7 +587,7 @@ func (deploy *NewDeploy) updateKubeObjRefRV(fsvc *fscache.FuncSvc, objKind strin // updateStatus is a function which updates status of update. // Current implementation only logs messages, in future it will update function status func updateStatus(fn *crd.Function, err error, message string) { - log.Printf(message, err) + log.Println(message, fn, err) } // IsValidService does a get on the service address to ensure it's a valid service. returns true if it is, else false.