-
Notifications
You must be signed in to change notification settings - Fork 4
[controller] [doc] [low priority] Astef prototype controller style guide #343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: astef-prototype
Are you sure you want to change the base?
[controller] [doc] [low priority] Astef prototype controller style guide #343
Conversation
- Update handlers section: prioritize For() and EnqueueRequestForOwner - Add EnqueueRequestsFromMapFunc usage guidelines - Add Ginkgo/Gomega testing framework requirements - Update examples to reflect new best practices
|
@asergunov Fixed it few time for be close to wanned specs, if you have time, check pls |
|
|
||
| **Обоснование:** `.For()` и `EnqueueRequestForOwner` покрывают 99% случаев. `EnqueueRequestsFromMapFunc` используется только когда нет owner reference, но нужен маппинг событий. Остальные handlers добавляют сложность и используются только для оптимизации производительности. | ||
|
|
||
| **Пример:** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Плохой пример? Может хороший сделать?
| - Функции-конструкторы (`NewReconciler`) - создавайте напрямую в `controller.go` | ||
|
|
||
| **✅ Используйте по умолчанию:** | ||
| - Минимальная структура с только необходимыми полями: `Cl`, `Log`, `LogAlt` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LogAlt не нужен. И все с маленькой буквы должны быть
| - Рекомендуется, если констант несколько (2+) | ||
| - Не обязательно, если константа одна или две | ||
|
|
||
| 4. **`reconciler_test.go`** - unit тесты |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
У гинкго еще suit. Без него тесты не запустятся. Еще пакет у тестов должен кончаться на _test
|
|
||
| return fake.NewClientBuilder(). | ||
| WithScheme(scheme). | ||
| WithStatusSubresource(&v1alpha3.SomeResource{}). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Больше одного через запятую
|
|
||
| BeforeEach(func() { | ||
| cl = newFakeClient() | ||
| rec = &mycontroller.Reconciler{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NewReconciler. Потому что поля приватные у него
| } | ||
| }) | ||
|
|
||
| It("returns no error when resource does not exist", func(ctx context.Context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Еще добавь With с общей инициализацией в JustBeforeEach. И несколькими It внутри
|
|
||
| --- | ||
|
|
||
| ## Чеклист при создании контроллера |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нафиг это повторение
| - Операции действительно независимы | ||
| - Обсуждено с командой | ||
|
|
||
| **Пример безопасной параллельной обработки (обсуждаемо):** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это спорно прям. Проще канал завести в контроллер по типу Watch
| } | ||
| ``` | ||
|
|
||
| **Важно:** При использовании goroutines убедитесь, что: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Спорно надо ли их вообще
| - Используется правильная обработка ошибок и контекста | ||
| - Это обсуждено с командой перед реализацией | ||
|
|
||
| ### Тестирование |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это было?
Description
Adds
CONTROLLER_STYLE_GUIDE.md- style guide for writing controllers based on review feedback and controller-runtime best practices.Changes:
docs/dev/controllers/CONTROLLER_STYLE_GUIDE.mdNo code changes: Documentation only.
Why do we need it, and what problem does it solve?
Establishes consistent standards for controller development to ensure code quality and reduce review back-and-forth. Documents when to use standard reconciler,
.For()method, structured logging, and parallel processing patterns.Based on review feedback: Guidelines derived from actual code review comments.
What is the expected result?
Developers have a reference document for controller development standards. New controllers will follow consistent patterns.
How to use:
MUST NOT change:
Checklist