|
| 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 | +} |
0 commit comments