refactor(sqs-operator): переделка через Operator SDK v1.37.0

- operator-sdk init + create api (QueueService kind, group sqs, v1alpha1)
- Стандартная kubebuilder структура: cmd/, internal/controller/, config/
- CRD types с kubebuilder маркерами (validation, defaults, printcolumns)
- Reconciler перенесён из ручного кода в internal/controller/
- controller-gen v0.17.0 (совместимость с Go 1.26.1)
- Автогенерация: deepcopy, CRD YAML, RBAC ClusterRole
- Удалены все ручные файлы (controllers/, main.go, deployments/)
This commit is contained in:
Naeel
2026-04-07 14:25:14 +03:00
parent cbe61d9f62
commit 66dcd99465
53 changed files with 2459 additions and 973 deletions
@@ -0,0 +1,125 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.17.0
name: queueservices.sqs.kube5s.ru
spec:
group: sqs.kube5s.ru
names:
kind: QueueService
listKind: QueueServiceList
plural: queueservices
singular: queueservice
scope: Namespaced
versions:
- additionalPrinterColumns:
- jsonPath: .spec.tenantId
name: Tenant
type: string
- jsonPath: .status.phase
name: Phase
type: string
- jsonPath: .status.endpoint
name: Endpoint
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha1
schema:
openAPIV3Schema:
description: |-
QueueService — управляет жизненным циклом ElasticMQ инстанса для тенанта.
Каждый QueueService CR = один ElasticMQ pod + Service + Ingress + PVC + Secret.
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
description: QueueServiceSpec — желаемое состояние QueueService (параметры
тенанта).
properties:
memoryMB:
default: 64
description: |-
MemoryMB — лимит памяти для ElasticMQ pod в мегабайтах.
ElasticMQ Native (GraalVM) в idle потребляет ~30MB.
format: int32
maximum: 1024
minimum: 32
type: integer
persistence:
default: true
description: |-
Persistence — включить H2 persistence для сохранения сообщений при рестарте pod.
Если false — сообщения in-memory only, теряются при перезапуске.
type: boolean
storageMB:
default: 512
description: |-
StorageMB — размер PVC для H2 persistence в мегабайтах.
H2 БД хранит очереди и сообщения между рестартами.
format: int32
maximum: 10240
minimum: 128
type: integer
tenantId:
description: |-
TenantID — уникальный идентификатор тенанта.
Используется в именах ресурсов (sqs-{tenantId}), namespace (sless-fn-{tenantId}),
и в Ingress path (/sqs/{tenantId}).
maxLength: 63
minLength: 1
pattern: ^[a-z0-9]([a-z0-9-]*[a-z0-9])?$
type: string
required:
- tenantId
type: object
status:
description: QueueServiceStatus — наблюдаемое состояние QueueService.
properties:
endpoint:
description: |-
Endpoint — публичный URL для SQS API тенанта (заполняется при Ready).
Формат: https://{SQS_EXTERNAL_HOST}/sqs/{tenantId}
type: string
message:
description: Message — описание ошибки или промежуточного статуса.
type: string
phase:
description: Phase — текущая фаза жизненного цикла.
enum:
- Pending
- Provisioning
- Ready
- Failed
type: string
readyAt:
description: ReadyAt — время когда инстанс перешёл в фазу Ready.
format: date-time
type: string
secretName:
description: SecretName — имя k8s Secret с credentials (accessKey/secretKey).
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
@@ -0,0 +1,22 @@
# This kustomization.yaml is not intended to be run by itself,
# since it depends on service name and namespace that are out of this kustomize package.
# It should be run by config/default
resources:
- bases/sqs.kube5s.ru_queueservices.yaml
#+kubebuilder:scaffold:crdkustomizeresource
patches:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#+kubebuilder:scaffold:crdkustomizewebhookpatch
# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- path: patches/cainjection_in_queueservices.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch
# [WEBHOOK] To enable webhook, uncomment the following section
# the following config is for teaching kustomize how to do kustomization for CRDs.
#configurations:
#- kustomizeconfig.yaml
@@ -0,0 +1,19 @@
# This file is for teaching kustomize how to substitute name and namespace reference in CRD
nameReference:
- kind: Service
version: v1
fieldSpecs:
- kind: CustomResourceDefinition
version: v1
group: apiextensions.k8s.io
path: spec/conversion/webhook/clientConfig/service/name
namespace:
- kind: CustomResourceDefinition
version: v1
group: apiextensions.k8s.io
path: spec/conversion/webhook/clientConfig/service/namespace
create: false
varReference:
- path: metadata/annotations