Skip to content

Commit dd6f84d

Browse files
FunctionConfig CRD and Reconciler (#475)
* functionconfig crd poc Co-authored-by: dgyorgy-nokia <daniel.gyorgy@nokia.com> * fix unit tests * retrigger CI * remove -config suffix from spec fields, combine abspath and relpath * aling binary executor config with dockerfile * readd function pod metrics endpoint * fixes after rebase, add finalizers, improve reload-component logic, add dockerhub mirror support to postgres image, retry db connection inline in repository controller too, fix lint * fix binaryexecutor, review comment fixes * remove image name from regex * fix lint after merge * add finalizer unit tests --------- Co-authored-by: dgyorgy-nokia <daniel.gyorgy@nokia.com>
1 parent 9efe1bd commit dd6f84d

40 files changed

Lines changed: 3987 additions & 1172 deletions

api/porchconfig/v1alpha1/config.porch.kpt.dev_functionconfigs.yaml

Lines changed: 929 additions & 0 deletions
Large diffs are not rendered by default.

api/porchconfig/v1alpha1/config.porch.kpt.dev_servicetemplates.yaml

Lines changed: 404 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Copyright 2026 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+
package v1alpha1
16+
17+
import (
18+
corev1 "k8s.io/api/core/v1"
19+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20+
)
21+
22+
// +kubebuilder:object:root=true
23+
// +kubebuilder:subresource:status
24+
// +kubebuilder:resource:path=functionconfigs,singular=functionconfig
25+
// +kubebuilder:printcolumn:name="Server Applied",type=integer,JSONPath=`.status.apiServerObservedGeneration`
26+
// +kubebuilder:printcolumn:name="FnRunner Applied",type=integer,JSONPath=`.status.functionRunnerObservedGeneration`
27+
type FunctionConfig struct {
28+
metav1.TypeMeta `json:",inline"`
29+
metav1.ObjectMeta `json:"metadata,omitempty"`
30+
31+
Spec FunctionConfigSpec `json:"spec,omitempty"`
32+
Status FunctionConfigStatus `json:"status,omitempty"`
33+
}
34+
35+
// +kubebuilder:object:root=true
36+
type FunctionConfigList struct {
37+
metav1.TypeMeta `json:",inline"`
38+
metav1.ListMeta `json:"metadata,omitempty"`
39+
40+
Items []FunctionConfig `json:"items"`
41+
}
42+
43+
// +kubebuilder:validation:XValidation:message="At least one configuration must be specified",rule="has(self.podExecutor) || has(self.binaryExecutor) || has(self.goExecutor)"
44+
type FunctionConfigSpec struct {
45+
// +kubebuilder:validation:MinLength=1
46+
Image string `json:"image"`
47+
Prefixes []string `json:"prefixes,omitempty"`
48+
PodExecutor *PodExecutorConfig `json:"podExecutor,omitempty"`
49+
BinaryExecutor *BinaryExecutorConfig `json:"binaryExecutor,omitempty"`
50+
GoExecutor *GoExecutorConfig `json:"goExecutor,omitempty"`
51+
}
52+
53+
type FunctionConfigStatus struct {
54+
// ObservedGeneration indicates which resource version of the function configuration has been read by Porch
55+
// ObservedGeneration int64 `json:"observedGeneration"`
56+
57+
// ApiServerObservedGeneration indicates which generation of the config the porch server has applied to the build-in runtime
58+
ApiServerObservedGeneration int64 `json:"apiServerObservedGeneration,omitempty"`
59+
// FunctionRunnerObservedGeneration indicates which generation of the config the function-runner has applied to the executable and pod evaluator
60+
FunctionRunnerObservedGeneration int64 `json:"functionRunnerObservedGeneration,omitempty"`
61+
// Contains an error message if one occurred whilst trying to apply the FunctionConfig
62+
Error string `json:"error,omitempty"`
63+
}
64+
65+
type PodExecutorConfig struct {
66+
// Image tags which the pod executor configuration will be applied to.
67+
// If tags is empty, the configuration will apply to all pods created for the image. TODO: this is not implemented
68+
Tags []string `json:"tags,omitempty"`
69+
// +kubebuilder:default="30m"
70+
// +kubebuilder:validation:Format=duration
71+
TimeToLive metav1.Duration `json:"timeToLive,omitempty"`
72+
MaxParallelExecutions int `json:"maxParallelExecutions,omitempty"`
73+
PreferredMaxQueueLength int `json:"preferredMaxQueueLength,omitempty"`
74+
75+
TemplateOverrides *TemplateOverrides `json:"templateOverrides,omitempty"`
76+
// TODO: add warmup section
77+
}
78+
79+
type TemplateOverrides struct {
80+
ServiceAccountName string `json:"serviceAccountName,omitempty"`
81+
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
82+
InitContainer *ContainerOverrides `json:"initContainer,omitempty"`
83+
Container *ContainerOverrides `json:"container,omitempty"`
84+
}
85+
86+
type ContainerOverrides struct {
87+
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
88+
EnvFrom []corev1.EnvFromSource `json:"envFrom,omitempty"`
89+
Env []corev1.EnvVar `json:"env,omitempty"`
90+
}
91+
92+
type BinaryExecutorConfig struct {
93+
// Image tags which can be substituted with the specified KRM function binary.
94+
// +kubebuilder:validation:MinItems=1
95+
Tags []string `json:"tags"`
96+
// Path defines the absolute file path of the binary or the relative file path to the default `functions` directory
97+
// +kubebuilder:validation:MinLength=1
98+
Path string `json:"path"`
99+
}
100+
101+
type GoExecutorConfig struct {
102+
// Image tags which can be substituted with a go function call.
103+
// +kubebuilder:validation:MinItems=1
104+
Tags []string `json:"tags"`
105+
// ID defines how the function is registered in the internal go executor of Porch.
106+
// If empty, `.spec.image` will be used instead.
107+
ID *string `json:"id,omitempty"`
108+
}

api/porchconfig/v1alpha1/groupversion_info.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,19 @@ var (
3737
objects: []runtime.Object{&Repository{}, &RepositoryList{}},
3838
}
3939

40-
AllKinds = []TypeInfo{TypeRepository}
40+
TypeFunctionConfig = TypeInfo{
41+
Kind: "FunctionConfig",
42+
Resource: GroupVersion.WithResource("functionconfigs"),
43+
objects: []runtime.Object{&FunctionConfig{}, &FunctionConfigList{}},
44+
}
45+
46+
TypeServiceTemplate = TypeInfo{
47+
Kind: "ServiceTemplate",
48+
Resource: GroupVersion.WithResource("servicetemplates"),
49+
objects: []runtime.Object{&ServiceTemplate{}, &ServiceTemplateList{}},
50+
}
51+
52+
AllKinds = []TypeInfo{TypeRepository, TypeFunctionConfig, TypeServiceTemplate}
4153
)
4254

4355
//+kubebuilder:object:generate=false
File renamed without changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2026 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+
package v1alpha1
16+
17+
import (
18+
corev1 "k8s.io/api/core/v1"
19+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20+
)
21+
22+
// +kubebuilder:object:root=true
23+
// +kubebuilder:subresource:status
24+
// +kubebuilder:resource:path=servicetemplates,singular=servicetemplate
25+
type ServiceTemplate struct {
26+
metav1.TypeMeta `json:",inline"`
27+
metav1.ObjectMeta `json:"metadata,omitempty"`
28+
29+
Template ServiceTemplateSpec `json:"template"`
30+
}
31+
32+
// +kubebuilder:object:root=true
33+
type ServiceTemplateList struct {
34+
metav1.TypeMeta `json:",inline"`
35+
metav1.ListMeta `json:"metadata,omitempty"`
36+
37+
Items []ServiceTemplate `json:"items"`
38+
}
39+
40+
type ServiceTemplateSpec struct {
41+
metav1.ObjectMeta `json:"metadata,omitempty"`
42+
43+
Spec corev1.ServiceSpec `json:"spec,omitempty"`
44+
}

0 commit comments

Comments
 (0)