fix: imagePullSecrets, SLESS_ENTRYPOINT, registry secret propagation

- function_controller: добавить RegistrySecret + OperatorNamespace, копировать
  sless-registry-auth в sless-fn-<ns>, выставлять imagePullSecrets в Deployment,
  также обновлять imagePullSecrets при reconcile
- functionjob_controller: fnEnvVars включает SLESS_ENTRYPOINT, runner читает его
- server.js + server.py: читать SLESS_ENTRYPOINT вместо hardcoded handler.js/py
- rbac.yaml: добавить права на secrets
- operator.yaml: v0.1.8
- main.go: передать RegistrySecret + OperatorNamespace в FunctionReconciler
This commit is contained in:
“Naeel”
2026-03-08 11:15:48 +04:00
parent d67b9745a8
commit e6abc490cd
11 changed files with 289 additions and 36 deletions
+14 -12
View File
@@ -1,29 +1,31 @@
// Изменено: 2026-03-07
// Изменено: 2026-03-08
// HTTP-обёртка для serverless функций на Node.js 20.
// Загружает handler.js из /app/function/ и вызывает handle(event) на каждый запрос.
// Соглашение: handler.js должен экспортировать async функцию handle(event).
//
// Пример handler.js:
// exports.handle = async (event) => {
// return { message: `Hello, ${event.name || 'World'}!` };
// };
// Загружает модуль из SLESS_ENTRYPOINT или handler.js по умолчанию.
// Формат SLESS_ENTRYPOINT: "module-name.functionName" (например: handler-http.handle)
'use strict';
const http = require('http');
const path = require('path');
const HANDLER_PATH = '/app/function/handler.js';
const PORT = 8080;
// Разбираем SLESS_ENTRYPOINT="module.func" → файл и имя функции.
// Fallback: handler.js + handle — для обратной совместимости.
const entrypoint = process.env.SLESS_ENTRYPOINT || 'handler.handle';
const dotIdx = entrypoint.lastIndexOf('.');
const moduleName = dotIdx >= 0 ? entrypoint.slice(0, dotIdx) : entrypoint;
const funcName = dotIdx >= 0 ? entrypoint.slice(dotIdx + 1) : 'handle';
const HANDLER_PATH = path.join('/app/function', moduleName);
// Загружаем модуль пользователя один раз при старте — не на каждый запрос
let userHandle;
try {
const mod = require(HANDLER_PATH);
if (typeof mod.handle !== 'function') {
throw new Error('handler.js must export a handle(event) function');
if (typeof mod[funcName] !== 'function') {
throw new Error(`${moduleName} must export a ${funcName}(event) function`);
}
userHandle = mod.handle;
userHandle = mod[funcName];
} catch (err) {
console.error('Failed to load handler:', err.message);
process.exit(1);
+16 -7
View File
@@ -1,26 +1,35 @@
#!/usr/bin/env python3
# Изменено: 2026-03-07
# Изменено: 2026-03-08
# HTTP-обёртка для serverless функций на Python 3.11.
# Загружает handler.py из /app/function/ и вызывает handle(event) на каждый запрос.
# Загружает модуль из SLESS_ENTRYPOINT или handler.py по умолчанию.
# Формат SLESS_ENTRYPOINT: "module_name.func_name" (например: handler.handle)
# Почему importlib: нужно загружать модуль из фиксированного пути вне sys.path.
import sys
import os
import json
import importlib.util
from http.server import HTTPServer, BaseHTTPRequestHandler
HANDLER_PATH = "/app/function/handler.py"
PORT = 8080
# Разбираем SLESS_ENTRYPOINT="module.func" → файл и имя функции.
# Fallback: handler.py + handle — для обратной совместимости.
_entrypoint = os.environ.get("SLESS_ENTRYPOINT", "handler.handle")
_dot_idx = _entrypoint.rfind(".")
_module_name = _entrypoint[:_dot_idx] if _dot_idx >= 0 else _entrypoint
_func_name = _entrypoint[_dot_idx + 1:] if _dot_idx >= 0 else "handle"
HANDLER_PATH = f"/app/function/{_module_name}.py"
def load_handler():
# Загружаем модуль пользователя динамически — путь известен только в runtime.
spec = importlib.util.spec_from_file_location("handler", HANDLER_PATH)
spec = importlib.util.spec_from_file_location(_module_name, HANDLER_PATH)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
if not hasattr(module, "handle"):
raise AttributeError(f"handler.py must define a 'handle(event)' function")
return module.handle
if not hasattr(module, _func_name):
raise AttributeError(f"{HANDLER_PATH} must define a '{_func_name}(event)' function")
return getattr(module, _func_name)
_handle = load_handler()