Skip to content

Implement Admin-operator for auth-admin team - #265

Merged
Vadz-Danil merged 2 commits into
mainfrom
216-implement-admin-operator-for-admin-auth-api
Jun 22, 2026
Merged

Implement Admin-operator for auth-admin team#265
Vadz-Danil merged 2 commits into
mainfrom
216-implement-admin-operator-for-admin-auth-api

Conversation

@Vadz-Danil

@Vadz-Danil Vadz-Danil commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced Admin Operator for Kubernetes, enabling automated management of admin service scaling and deployment configuration through custom resources.
  • Documentation

    • Added comprehensive Admin Operator documentation including architecture, reconciliation workflow, RBAC configuration, and security hardening details.
  • Tests

    • Added controller tests for Admin Operator reconciliation scenarios covering enabled/disabled states, missing deployments, and scaling operations.

@Vadz-Danil Vadz-Danil linked an issue Jun 20, 2026 that may be closed by this pull request
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Vadz-Danil, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 40 minutes and 15 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 092ba31e-f028-4c5c-8222-0cb56c9a4a52

📥 Commits

Reviewing files that changed from the base of the PR and between bb76e49 and 6dcbcd7.

📒 Files selected for processing (6)
  • build/Dockerfile.admin-operator
  • deploy/k8s/operators/admin-auth/operator-deployment.yaml
  • deploy/k8s/operators/admin-auth/rbac.yaml
  • docs/k8s/admin-operator.md
  • operators/admin-operator/controller/controller.go
  • operators/admin-operator/controller/controller_test.go
📝 Walkthrough

Walkthrough

Introduces a complete Kubernetes operator (admin-operator) that manages AdminAppProfile custom resources in the admin.sharebite.dev/v1alpha1 API group. The operator reconciles deployment replica counts for admin-auth-api based on CRD spec fields. Adds Go API types, controller logic with tests, CRD/RBAC/Deployment manifests, a multi-stage Dockerfile, Makefile automation targets, and expanded operator documentation.

Changes

Admin Operator

Layer / File(s) Summary
AdminAppProfile API types and scheme registration
operators/admin-operator/api/v1alpha1/adminappprofile_types.go, operators/admin-operator/api/v1alpha1/deep_copy.go, operators/admin-operator/api/v1alpha1/groupversion_info.go, deploy/k8s/operators/admin-auth/crd.yaml
Defines AdminAppProfileSpec (replicas, enabled, deploymentName), AdminAppProfileStatus (conditions), and list types with kubebuilder markers; implements DeepCopy methods; registers the admin.sharebite.dev/v1alpha1 GroupVersion. The CRD YAML mirrors these with OpenAPI v3 schema validation and a status subresource.
Reconciler controller and unit tests
operators/admin-operator/controller/controller.go, operators/admin-operator/controller/controller_test.go
AdminAppProfileReconciler.Reconcile derives desired replica counts, patches Deployment replicas on drift, and updates status conditions (DeploymentNotFound, Scaling, Scaled) with requeue delays. Three unit tests cover Enabled=false, missing Deployment requeue, and happy-path scaling via a fake client.
Operator entrypoint, scheme wiring, and Dockerfile
cmd/admin-operator/main.go, build/Dockerfile.admin-operator
main.go registers schemes, parses flags for metrics/leader election, creates the controller-runtime manager, wires AdminAppProfileReconciler, and starts with signal handling. Multi-stage Dockerfile compiles the manager binary for linux/arm64 and packages it into Alpine as a non-root container.
RBAC, operator Deployment, and example CR manifests
deploy/k8s/operators/admin-auth/rbac.yaml, deploy/k8s/operators/admin-auth/operator-deployment.yaml, deploy/k8s/operators/admin-auth/example-cr.yaml
ServiceAccount, ClusterRole (deployments/adminappprofiles/leases/events permissions), and ClusterRoleBinding for the operator. Operator Deployment applies security hardening (non-root, read-only rootfs, seccomp RuntimeDefault, dropped capabilities). Example CR sets replicas: 2, enabled: true.
Makefile targets, .gitignore, and docs
Makefile, .gitignore, docs/k8s/admin-operator.md
Adds run-admin-service, stop-admin-service, run-admin-operator, stop-admin-operator, apply-cr Makefile targets; ignores pkg/gateway. Rewrites operator docs with CRD field reference, reconciliation loop diagram, RBAC table, security hardening, and developer workflow.

Sequence Diagram(s)

sequenceDiagram
  participant Developer
  participant Makefile
  participant Docker
  participant Kubernetes
  participant AdminAppProfileReconciler

  Developer->>Makefile: make run-admin-operator
  Makefile->>Docker: docker build admin-operator:latest
  Makefile->>Kubernetes: kubectl apply crd.yaml, rbac.yaml, operator-deployment.yaml
  Kubernetes->>AdminAppProfileReconciler: Start manager / watch AdminAppProfile

  Developer->>Makefile: make apply-cr
  Makefile->>Kubernetes: kubectl apply example-cr.yaml
  Kubernetes->>AdminAppProfileReconciler: Reconcile(AdminAppProfile)
  AdminAppProfileReconciler->>Kubernetes: Get Deployment (admin-auth-api)
  AdminAppProfileReconciler->>Kubernetes: Patch spec.replicas
  AdminAppProfileReconciler->>Kubernetes: Update AdminAppProfile status conditions
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

core, enhancement

Suggested reviewers

  • viktorzhabskyi
  • mblinovv
  • DmyMi

🐰 A profile appears, the operator wakes,
It counts the replicas, adjusts what it takes.
Enabled or not, the deployment obeys,
RBAC stands guard through the cluster's maze.
🥕 Hop hop, the manager starts with a sign —
the admin-auth scales right down the line!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly reflects the main changeset: implementing a new admin operator for the auth-admin team with supporting CRDs, controllers, deployments, and documentation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 216-implement-admin-operator-for-admin-auth-api

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

🧹 Nitpick comments (1)
Makefile (1)

14-14: ⚡ Quick win

Unused OPERATOR_IMAGE variable.

The OPERATOR_IMAGE variable is defined on line 14 but not used in the run-admin-operator target; instead, the target hardcodes admin-operator:latest. This suggests either the variable was intended but not connected, or it's a remnant from earlier design.

If the intention is to build locally for development, clarify this assumption. If the operator should eventually use a registry-qualified image, align the variable usage across all operator-related targets.

Also applies to: 223-223

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Makefile` at line 14, The OPERATOR_IMAGE variable is defined but not used in
the run-admin-operator target, which hardcodes the image reference as
admin-operator:latest instead. Update the run-admin-operator target to use the
OPERATOR_IMAGE variable reference. Also check line 223 and any other
operator-related targets to ensure consistency in using the OPERATOR_IMAGE
variable throughout the Makefile rather than hardcoding image references. If
OPERATOR_IMAGE is not needed elsewhere, document the purpose of this variable or
consider removing it.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@build/Dockerfile.admin-operator`:
- Line 10: The RUN command in the Dockerfile is hardcoding GOARCH=arm64, which
restricts the binary to only run on arm64 architecture nodes and breaks
deployments on other architectures like amd64. Remove the hardcoded GOARCH=arm64
parameter from the go build command in the RUN instruction that builds the
manager binary, and instead allow the build system to use the appropriate target
architecture automatically. This will enable the Dockerfile to support
multi-platform builds and work correctly on different node architectures.

In `@deploy/k8s/operators/admin-auth/operator-deployment.yaml`:
- Line 24: Replace the image reference in the admin-auth operator deployment
from the `:latest` tag to use an immutable image reference. Either update the
image field to use a commit-based tag (e.g., `admin-operator:sha-abc1234`) that
aligns with the project's CI pipeline tagging strategy, or alternatively update
the imagePullPolicy field to `IfNotPresent` to rely on locally built images
without requiring a specific tag. If using the commit hash approach, ensure the
Makefile target that builds and pushes this operator image is updated to
generate and apply the appropriate commit-based tag during the build process.

In `@deploy/k8s/operators/admin-auth/rbac.yaml`:
- Around line 15-17: The RBAC rule for adminappprofiles resource is granting
excessive permissions that the reconciler does not actually use. The reconciler
only performs r.Get() on adminappprofiles and r.Status().Update() on the status
sub-resource. Remove the unnecessary verbs "create", "delete", "update", and
"patch" from the verbs array in the rule with apiGroups ["admin.sharebite.dev"]
and resources ["adminappprofiles", "adminappprofiles/status"], keeping only
"watch", "get", and "list" to follow the principle of least privilege.

In `@docs/k8s/admin-operator.md`:
- Line 151: The documentation at line 151 in the developer guide references an
incorrect Makefile target name `make run-auth-service`. Replace this with the
correct target name `make run-admin-service` to match the actual Makefile
definition and ensure the documented instructions will execute successfully.
- Line 170: The documentation in step 4 of the developer guide references an
incorrect Makefile target name. Replace `make stop-auth-service` with `make
stop-admin-service` on line 170 of the admin-operator.md file to match the
actual Makefile target that is defined in the Makefile.
- Line 110: The RBAC permissions table contains an incorrect resource name in
the row under the admin.sharebite.dev API group. Replace the resource reference
from `businessappprofiles/status` to `adminappprofiles/status` to align with the
actual custom resource definition and RBAC rules documented elsewhere. This
ensures consistency and prevents user confusion about the correct API resource
to reference.
- Line 3: The overview statement on line 3 incorrectly identifies the Deployment
being scaled as "business-api" when it should be "admin-auth-api" according to
the CRD manifest and controller implementation. Replace the incorrect Deployment
name "business-api" with the correct name "admin-auth-api" in the description
that states what Deployment the operator scales from the AdminAppProfile
resource.

In `@operators/admin-operator/controller/controller_test.go`:
- Around line 42-43: The cl.Get() calls in the test are ignoring errors by using
the blank identifier, which allows failures to go undetected and cause
misleading test failures. Replace the `_ = cl.Get(...)` statements with proper
error handling that captures the error and immediately fails the test if the Get
operation fails, such as using t.Fatalf or requiring that the error is nil.
Apply this fix to all occurrences of ignored cl.Get() errors in the test file,
including the calls around line 42-43 and 98-99.

In `@operators/admin-operator/controller/controller.go`:
- Around line 102-105: The SetupWithManager method in the
AdminAppProfileReconciler currently only watches for AdminAppProfile changes,
but does not track changes to the Deployment resource it manages. This allows
manual scaling of the Deployment to persist without reconciliation until the
next AdminAppProfile event. Add `.Owns(&appsv1.Deployment{})` to the controller
setup chain between the `.For(&adminv1alpha1.AdminAppProfile{})` call and the
`.Complete(r)` call to ensure the controller reconciles whenever the managed
Deployment is modified, maintaining the desired replica count promptly.

---

Nitpick comments:
In `@Makefile`:
- Line 14: The OPERATOR_IMAGE variable is defined but not used in the
run-admin-operator target, which hardcodes the image reference as
admin-operator:latest instead. Update the run-admin-operator target to use the
OPERATOR_IMAGE variable reference. Also check line 223 and any other
operator-related targets to ensure consistency in using the OPERATOR_IMAGE
variable throughout the Makefile rather than hardcoding image references. If
OPERATOR_IMAGE is not needed elsewhere, document the purpose of this variable or
consider removing it.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5ae4566e-23dc-44bf-a4dd-e79cc46a8921

📥 Commits

Reviewing files that changed from the base of the PR and between e5b4328 and bb76e49.

📒 Files selected for processing (14)
  • .gitignore
  • Makefile
  • build/Dockerfile.admin-operator
  • cmd/admin-operator/main.go
  • deploy/k8s/operators/admin-auth/crd.yaml
  • deploy/k8s/operators/admin-auth/example-cr.yaml
  • deploy/k8s/operators/admin-auth/operator-deployment.yaml
  • deploy/k8s/operators/admin-auth/rbac.yaml
  • docs/k8s/admin-operator.md
  • operators/admin-operator/api/v1alpha1/adminappprofile_types.go
  • operators/admin-operator/api/v1alpha1/deep_copy.go
  • operators/admin-operator/api/v1alpha1/groupversion_info.go
  • operators/admin-operator/controller/controller.go
  • operators/admin-operator/controller/controller_test.go

Comment thread build/Dockerfile.admin-operator Outdated
Comment thread deploy/k8s/operators/admin-auth/operator-deployment.yaml
Comment thread deploy/k8s/operators/admin-auth/rbac.yaml Outdated
Comment thread docs/k8s/admin-operator.md Outdated
Comment thread docs/k8s/admin-operator.md Outdated
Comment thread docs/k8s/admin-operator.md Outdated
Comment thread docs/k8s/admin-operator.md Outdated
Comment thread operators/admin-operator/controller/controller_test.go Outdated
Comment thread operators/admin-operator/controller/controller.go
@Vadz-Danil
Vadz-Danil merged commit 6df0ae8 into main Jun 22, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement admin-operator for admin-auth-api

2 participants