From da50c3759d283b48a20d00d034d88b73199f3859 Mon Sep 17 00:00:00 2001 From: Ambor Date: Thu, 22 Sep 2022 16:51:27 +0800 Subject: [PATCH] feat: add the fn annotations to newdeploy function based deployment (#2554) * feat: add copy the fn annotations to the deploy annotations * feat: add copy the fn labels to the deploy labels --- pkg/executor/executortype/newdeploy/newdeploymgr.go | 8 ++++---- pkg/utils/maps/map.go | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/executor/executortype/newdeploy/newdeploymgr.go b/pkg/executor/executortype/newdeploy/newdeploymgr.go index fc15d7ed..df5504f7 100644 --- a/pkg/executor/executortype/newdeploy/newdeploymgr.go +++ b/pkg/executor/executortype/newdeploy/newdeploymgr.go @@ -455,7 +455,7 @@ func (deploy *NewDeploy) fnCreate(ctx context.Context, fn *fv1.Function) (*fscac kubeObjRefs := []apiv1.ObjectReference{ { - //obj.TypeMeta.Kind does not work hence this, needs investigation and a fix + // obj.TypeMeta.Kind does not work hence this, needs investigation and a fix Kind: "deployment", Name: depl.ObjectMeta.Name, APIVersion: depl.TypeMeta.APIVersion, @@ -747,14 +747,14 @@ func (deploy *NewDeploy) getDeployLabels(fnMeta metav1.ObjectMeta, envMeta metav fv1.FUNCTION_NAMESPACE: fnMeta.Namespace, fv1.FUNCTION_UID: string(fnMeta.UID), } - for k, v := range envMeta.Labels { - deployLabels[k] = v - } + maps.MergeStringMap(deployLabels, envMeta.Labels) + maps.MergeStringMap(deployLabels, fnMeta.Labels) return deployLabels } func (deploy *NewDeploy) getDeployAnnotations(fnMeta metav1.ObjectMeta, envMeta metav1.ObjectMeta) map[string]string { deployAnnotations := maps.CopyStringMap(envMeta.Annotations) + maps.MergeStringMap(deployAnnotations, fnMeta.Annotations) deployAnnotations[fv1.EXECUTOR_INSTANCEID_LABEL] = deploy.instanceID deployAnnotations[fv1.FUNCTION_RESOURCE_VERSION] = fnMeta.ResourceVersion return deployAnnotations diff --git a/pkg/utils/maps/map.go b/pkg/utils/maps/map.go index 7635d9d4..0cbf4d8f 100644 --- a/pkg/utils/maps/map.go +++ b/pkg/utils/maps/map.go @@ -22,3 +22,9 @@ func CopyStringMap(m map[string]string) map[string]string { } return n } + +func MergeStringMap(targetMap map[string]string, sourceMap map[string]string) { + for k, v := range sourceMap { + targetMap[k] = v + } +}