Skip to content

Commit ede0900

Browse files
gkumar78efiacor
andauthored
Updated porch e2e tests to use service manifest from function pod template configmap (#285)
* Updated porch e2e tests to use service manifest from function pod template configmap * Updated function pod template changes as per review comments * Applying suggestions from code review comments Co-authored-by: Fiachra Corcoran <fiachra.corcoran@est.tech> * Update deployment.yaml to correct copyright line year --------- Co-authored-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
1 parent 5967bdf commit ede0900

3 files changed

Lines changed: 130 additions & 4 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
### Function Pod Template
2+
3+
In order to leverage custom manifests for Pod and frontend Service of Function Pods created by Function Runner, the following additional Kubernetes Resource Manifests (KRM) need to be provisioned in the Porch environment
4+
5+
* A ConfigMap containing 2 data elements: a) a KRM of type Pod under the `template` key and b) a KRM of type Service under `serviceTemplate` key
6+
* A Kubernetes Role providing read access to resource type ConfigMap in the porch-system namespace
7+
* A Kubernetes RoleBinding, binding to the above listed Role to the ServiceAccount (porch-fn-runner) used by Function Runner Pod
8+
9+
All of the above KRMs are predefined in `deployment.yaml` file present in this folder.
10+
11+
### How to enable Function Pod Template use by Function Runner
12+
13+
* Apply the [deployment.yaml manifest](deployment.yaml) from this directory
14+
15+
```
16+
kubectl apply -f deployment.yaml
17+
```
18+
19+
* Add an additional argument `--function-pod-template` in command section of function-runner deployment instructing it to use the Function Pod Template ConfigMap, as shown below
20+
21+
```
22+
kubectl edit deployment -n porch-system function-runner
23+
```
24+
25+
```
26+
command:
27+
- /server
28+
- --config=/config.yaml
29+
- --functions=/functions
30+
- --pod-namespace=porch-fn-system
31+
- --function-pod-template=kpt-function-eval-pod-template
32+
- --max-request-body-size=6291456 # Keep this in sync with porch-server's corresponding argument
33+
```
34+
35+
After the function-runner Pods restart, they will start using the Pod and Service templates from ConfigMap.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Copyright 2025 The kpt and Nephio Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
---
15+
apiVersion: v1
16+
kind: ConfigMap
17+
metadata:
18+
name: kpt-function-eval-pod-template
19+
namespace: porch-system
20+
data:
21+
template: |
22+
apiVersion: v1
23+
kind: Pod
24+
annotations:
25+
cluster-autoscaler.kubernetes.io/safe-to-evict: true
26+
spec:
27+
initContainers:
28+
- name: copy-wrapper-server
29+
image: docker.io/nephio/porch-wrapper-server:latest
30+
command:
31+
- cp
32+
- -a
33+
- /wrapper-server/.
34+
- /wrapper-server-tools
35+
volumeMounts:
36+
- name: wrapper-server-tools
37+
mountPath: /wrapper-server-tools
38+
containers:
39+
- name: function
40+
image: image-replaced-by-kpt-func-image
41+
command:
42+
- /wrapper-server-tools/wrapper-server
43+
volumeMounts:
44+
- name: wrapper-server-tools
45+
mountPath: /wrapper-server-tools
46+
volumes:
47+
- name: wrapper-server-tools
48+
emptyDir: {}
49+
serviceTemplate: |
50+
apiVersion: v1
51+
kind: Service
52+
spec:
53+
ports:
54+
- port: 9446
55+
protocol: TCP
56+
targetPort: 9446
57+
selector:
58+
fn.kpt.dev/image: to-be-replaced
59+
type: ClusterIP
60+
---
61+
# Need to lookup and access Configmap containing Function Pod Template
62+
kind: Role
63+
apiVersion: rbac.authorization.k8s.io/v1
64+
metadata:
65+
name: porch-fn-runner
66+
namespace: porch-system
67+
rules:
68+
- apiGroups: [""]
69+
resources: ["configmaps"]
70+
verbs: ["get", "list"]
71+
---
72+
apiVersion: rbac.authorization.k8s.io/v1
73+
kind: RoleBinding
74+
metadata:
75+
name: porch-fn-runner
76+
namespace: porch-system
77+
roleRef:
78+
apiGroup: rbac.authorization.k8s.io
79+
kind: Role
80+
name: porch-fn-runner
81+
subjects:
82+
- kind: ServiceAccount
83+
name: porch-fn-runner

func/internal/podevaluator.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -938,12 +938,16 @@ func (pm *podManager) getBasePodTemplate(ctx context.Context) (*corev1.Pod, stri
938938
return nil, "", err
939939
}
940940

941-
decoder := yamlutil.NewYAMLOrJSONDecoder(strings.NewReader(podTemplateCm.Data["template"]), 100)
941+
podTemplate, ok := podTemplateCm.Data["template"]
942+
if !ok {
943+
return nil, "", fmt.Errorf("function pod template with key template does not exist in Configmap %s", pm.functionPodTemplateName)
944+
}
945+
946+
decoder := yamlutil.NewYAMLOrJSONDecoder(strings.NewReader(podTemplate), 100)
942947
var basePodTemplate corev1.Pod
943948
err = decoder.Decode(&basePodTemplate)
944949

945950
if err != nil {
946-
klog.Errorf("Could not decode function pod template: %s", pm.functionPodTemplateName)
947951
return nil, "", fmt.Errorf("unable to decode function pod template: %w", err)
948952
}
949953

@@ -1087,12 +1091,16 @@ func (pm *podManager) getBaseServiceTemplate(ctx context.Context) (*corev1.Servi
10871091
return nil, err
10881092
}
10891093

1090-
decoder := yamlutil.NewYAMLOrJSONDecoder(strings.NewReader(serviceTemplateCm.Data["serviceTemplate"]), 100)
1094+
serviceTemplate, ok := serviceTemplateCm.Data["serviceTemplate"]
1095+
if !ok {
1096+
return nil, fmt.Errorf("function pod service template with key serviceTemplate does not exist in Configmap %s", pm.functionPodTemplateName)
1097+
}
1098+
1099+
decoder := yamlutil.NewYAMLOrJSONDecoder(strings.NewReader(serviceTemplate), 100)
10911100
var baseServiceTemplate corev1.Service
10921101
err = decoder.Decode(&baseServiceTemplate)
10931102

10941103
if err != nil {
1095-
klog.Errorf("Could not decode function service template: %s", pm.functionPodTemplateName)
10961104
return nil, fmt.Errorf("unable to decode function service template: %w", err)
10971105
}
10981106

0 commit comments

Comments
 (0)