feat: sless_service CRD + ServiceReconciler, RBAC fix, split postgres/functions.tf, operator v0.1.41

This commit is contained in:
Naeel
2026-03-20 13:03:12 +03:00
parent dc65f7ab8f
commit 680beb675b
19 changed files with 2448 additions and 693 deletions
+110
View File
@@ -0,0 +1,110 @@
// Создано: 2026-03-20
// service_types.go — CRD Service (sless_service): долгоживущий HTTP-сервис с постоянным URL.
// В отличие от Function (oneshot через Job), Service запускается как Deployment
// и всегда доступен по URL: https://sless.kube5s.ru/fn/{namespace}/{name}
// HTTP-триггер отдельно создавать не нужно — URL выдаётся оператором автоматически.
package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// ServiceSpec — желаемое состояние сервиса.
// Поля идентичны FunctionSpec, но нет семантики "одноразового вызова".
type ServiceSpec struct {
// Runtime — язык и версия выполнения (go1.23, python3.11, nodejs20)
// +kubebuilder:validation:Enum=go1.23;python3.11;nodejs20
// +kubebuilder:validation:Required
Runtime string `json:"runtime"`
// Entrypoint — точка входа в код сервиса (например: handler.handle)
// +kubebuilder:validation:Required
Entrypoint string `json:"entrypoint"`
// S3Bucket — бакет S3 где хранится zip архив с кодом
S3Bucket string `json:"s3Bucket"`
// S3Key — ключ объекта в S3 (путь до zip архива)
S3Key string `json:"s3Key"`
// MemoryMB — лимит памяти в мегабайтах (default: 128)
// +kubebuilder:default=128
MemoryMB int32 `json:"memoryMB,omitempty"`
// TimeoutSec — таймаут HTTP-прокси в секундах (default: 30).
// Ограничивает время ожидания ответа от пода в invoke.go.
// Для длительных вызовов (batch, pgstorm) увеличить до нужного значения.
// +kubebuilder:default=30
TimeoutSec int32 `json:"timeoutSec,omitempty"`
// Env — переменные окружения, передаются в контейнер сервиса
Env map[string]string `json:"env,omitempty"`
}
// ServicePhase — текущая фаза жизненного цикла сервиса.
type ServicePhase string
const (
// ServicePhasePending — сервис создан, ожидает сборки образа
ServicePhasePending ServicePhase = "Pending"
// ServicePhaseBuilding — идёт сборка Docker образа
ServicePhaseBuilding ServicePhase = "Building"
// ServicePhaseReady — образ собран, Deployment поднят, URL доступен
ServicePhaseReady ServicePhase = "Ready"
// ServicePhaseFailed — ошибка при сборке или деплое
ServicePhaseFailed ServicePhase = "Failed"
)
// ServiceStatus — наблюдаемое состояние сервиса (заполняет контроллер).
type ServiceStatus struct {
// Phase — текущая фаза: Pending, Building, Ready, Failed
Phase ServicePhase `json:"phase,omitempty"`
// ImageRef — полный путь к собранному Docker образу в registry
ImageRef string `json:"imageRef,omitempty"`
// URL — публичный URL сервиса, заполняется оператором после создания Ingress.
// Формат: {ExternalURL}/fn/{namespace}/{name}
URL string `json:"url,omitempty"`
// Message — человекочитаемое сообщение об ошибке или статусе
Message string `json:"message,omitempty"`
// Conditions — стандартные k8s conditions для интеграции с инструментами
Conditions []metav1.Condition `json:"conditions,omitempty"`
// LastBuiltAt — время последней успешной сборки образа
LastBuiltAt *metav1.Time `json:"lastBuiltAt,omitempty"`
}
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Runtime",type=string,JSONPath=`.spec.runtime`
//+kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`
//+kubebuilder:printcolumn:name="URL",type=string,JSONPath=`.status.url`
//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
// Service — ресурс для долгоживущего HTTP-сервиса.
// Оператор создаёт Deployment + k8s Service + Ingress автоматически.
// URL доступен сразу после фазы Ready, без создания sless_trigger.
type Service struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ServiceSpec `json:"spec,omitempty"`
Status ServiceStatus `json:"status,omitempty"`
}
//+kubebuilder:object:root=true
// ServiceList contains a list of Service
type ServiceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Service `json:"items"`
}
func init() {
SchemeBuilder.Register(&Service{}, &ServiceList{})
}
+108 -1
View File
@@ -21,7 +21,7 @@ limitations under the License.
package v1alpha1
import (
"k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
)
@@ -288,6 +288,113 @@ func (in *TriggerList) DeepCopyObject() runtime.Object {
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Service) DeepCopyInto(out *Service) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
in.Status.DeepCopyInto(&out.Status)
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Service.
func (in *Service) DeepCopy() *Service {
if in == nil {
return nil
}
out := new(Service)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *Service) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ServiceList) DeepCopyInto(out *ServiceList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]Service, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceList.
func (in *ServiceList) DeepCopy() *ServiceList {
if in == nil {
return nil
}
out := new(ServiceList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *ServiceList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ServiceSpec) DeepCopyInto(out *ServiceSpec) {
*out = *in
if in.Env != nil {
in, out := &in.Env, &out.Env
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceSpec.
func (in *ServiceSpec) DeepCopy() *ServiceSpec {
if in == nil {
return nil
}
out := new(ServiceSpec)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ServiceStatus) DeepCopyInto(out *ServiceStatus) {
*out = *in
if in.Conditions != nil {
in, out := &in.Conditions, &out.Conditions
*out = make([]v1.Condition, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.LastBuiltAt != nil {
in, out := &in.LastBuiltAt, &out.LastBuiltAt
*out = (*in).DeepCopy()
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceStatus.
func (in *ServiceStatus) DeepCopy() *ServiceStatus {
if in == nil {
return nil
}
out := new(ServiceStatus)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *TriggerSpec) DeepCopyInto(out *TriggerSpec) {
*out = *in