Conversation
Comprehensive analysis document for migrating nixos-operator from KOPF (Python) to kubebuilder (Go), covering: - CRD definitions with kstatus compliance - Reconciler design patterns - Long-running operations via Kubernetes Jobs - Secret watches with field indexes - Testing strategy with unit test examples - Owner references and garbage collection - State machines and lifecycle diagrams Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: ZverGuy <maximbel2003@gmail.com>
- Replace separate hostname/ipAddress fields with single host field - Add SecretKeyReference with explicit key field for additionalFiles - Add jobTemplate for pod customization (image, nodeSelector, tolerations, resources, serviceAccountName) - Remove Age from additionalPrinterColumns (built-in kubectl column) - Add complete Go type definitions for MachineSpec Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: ZverGuy <maximbel2003@gmail.com>
Initialize kubebuilder project with: - Domain: homystack.com - Repo: github.com/homystack/nixos-operator - Go 1.25.5, kubebuilder v4.10.1 Created API scaffolds: - Machine (nio.homystack.com/v1alpha1) - NixosConfiguration (nio.homystack.com/v1alpha1) Ref: Issue #2 Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: ZverGuy <maximbel2003@gmail.com>
…s compliance Machine type includes: - Spec: host, sshUser, sshKeySecretRef, sshPasswordSecretRef - Status: observedGeneration, discoverable, hasConfiguration, appliedConfiguration, appliedCommit, hardwareFacts, nixFacterResult - Conditions: Ready, Reconciling, Stalled, Discoverable, HardwareScanned - Printer columns for kubectl output NixosConfiguration type includes: - Spec: machineRef, gitRepo, ref, credentialsRef, flake, onRemoveFlake, configurationSubdir, fullInstall, additionalFiles, jobTemplate - Status: observedGeneration, fullDiskInstallCompleted, appliedCommit, configurationHash, additionalFilesHash, operationState - Conditions: Ready, Reconciling, Stalled, Applied, GitSynced - Support for JobTemplate customization Added condition constants and reasons for kstatus compliance. Ref: Issue #3 Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: ZverGuy <maximbel2003@gmail.com>
…hecks MachineReconciler implementation includes: - SSH Client interface with mock for testing - SSH connectivity checks using golang.org/x/crypto/ssh - Key-based and password-based authentication support - Condition management for kstatus compliance: - Ready, Reconciling, Stalled, Discoverable - Secret watching for SSH credentials updates - Field indexes for efficient secret-to-machine mapping - Finalizer handling for clean deletion - Event recording for status changes - Periodic requeue for connectivity monitoring Tests cover: - Successful SSH connection scenario - Failed SSH connection scenario - Missing SSH credentials scenario - Non-existent resource handling Ref: Issue #4 Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: ZverGuy <maximbel2003@gmail.com>
…ed apply NixosConfigurationReconciler implementation includes: - Machine reference resolution and discovery validation - Kubernetes Job creation for nixos-rebuild and nixos-anywhere - Job lifecycle monitoring (pending, running, succeeded, failed) - Per-machine concurrency protection via labels - Global concurrency limiting (max 5 concurrent jobs) - Configuration hash calculation for change detection - Machine status updates on successful apply - Finalizer handling for cleanup on deletion - onRemoveFlake placeholder for deletion cleanup - Secret mounting for SSH keys and git credentials - Pod security context with minimal privileges - JobTemplate customization (nodeSelector, tolerations, resources) RBAC updates for Job management and pods/logs access. Ref: Issue #5 Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: ZverGuy <maximbel2003@gmail.com>
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - pods | ||
| - pods/log | ||
| - secrets | ||
| verbs: | ||
| - get | ||
| - list | ||
| - watch |
Check failure
Code scanning / Trivy
Manage secrets Critical
| containers: | ||
| - command: | ||
| - /manager | ||
| args: | ||
| - --leader-elect | ||
| - --health-probe-bind-address=:8081 | ||
| image: controller:latest | ||
| name: manager | ||
| ports: [] | ||
| securityContext: | ||
| readOnlyRootFilesystem: true | ||
| allowPrivilegeEscalation: false | ||
| capabilities: | ||
| drop: | ||
| - "ALL" | ||
| livenessProbe: | ||
| httpGet: | ||
| path: /healthz | ||
| port: 8081 | ||
| initialDelaySeconds: 15 | ||
| periodSeconds: 20 | ||
| readinessProbe: | ||
| httpGet: | ||
| path: /readyz | ||
| port: 8081 | ||
| initialDelaySeconds: 5 | ||
| periodSeconds: 10 | ||
| # TODO(user): Configure the resources accordingly based on the project requirements. | ||
| # More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ | ||
| resources: | ||
| limits: | ||
| cpu: 500m | ||
| memory: 128Mi | ||
| requests: | ||
| cpu: 10m | ||
| memory: 64Mi |
Check warning
Code scanning / Trivy
Image tag ":latest" used Medium
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - configmaps | ||
| verbs: | ||
| - get | ||
| - list | ||
| - watch | ||
| - create | ||
| - update | ||
| - patch | ||
| - delete |
Check warning
Code scanning / Trivy
Manage configmaps Medium
| - apiGroups: | ||
| - batch | ||
| resources: | ||
| - jobs | ||
| verbs: | ||
| - create | ||
| - delete | ||
| - get | ||
| - list | ||
| - patch | ||
| - update | ||
| - watch |
Check warning
Code scanning / Trivy
Manage Kubernetes workloads and pods Medium
| @@ -0,0 +1,31 @@ | |||
| # Build the manager binary | |||
Check notice
Code scanning / Trivy
No HEALTHCHECK defined Low
| containers: | ||
| - command: | ||
| - /manager | ||
| args: | ||
| - --leader-elect | ||
| - --health-probe-bind-address=:8081 | ||
| image: controller:latest | ||
| name: manager | ||
| ports: [] | ||
| securityContext: | ||
| readOnlyRootFilesystem: true | ||
| allowPrivilegeEscalation: false | ||
| capabilities: | ||
| drop: | ||
| - "ALL" | ||
| livenessProbe: | ||
| httpGet: | ||
| path: /healthz | ||
| port: 8081 | ||
| initialDelaySeconds: 15 | ||
| periodSeconds: 20 | ||
| readinessProbe: | ||
| httpGet: | ||
| path: /readyz | ||
| port: 8081 | ||
| initialDelaySeconds: 5 | ||
| periodSeconds: 10 | ||
| # TODO(user): Configure the resources accordingly based on the project requirements. | ||
| # More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ | ||
| resources: | ||
| limits: | ||
| cpu: 500m | ||
| memory: 128Mi | ||
| requests: | ||
| cpu: 10m | ||
| memory: 64Mi |
Check notice
Code scanning / Trivy
Runs with UID <= 10000 Low
| containers: | ||
| - command: | ||
| - /manager | ||
| args: | ||
| - --leader-elect | ||
| - --health-probe-bind-address=:8081 | ||
| image: controller:latest | ||
| name: manager | ||
| ports: [] | ||
| securityContext: | ||
| readOnlyRootFilesystem: true | ||
| allowPrivilegeEscalation: false | ||
| capabilities: | ||
| drop: | ||
| - "ALL" | ||
| livenessProbe: | ||
| httpGet: | ||
| path: /healthz | ||
| port: 8081 | ||
| initialDelaySeconds: 15 | ||
| periodSeconds: 20 | ||
| readinessProbe: | ||
| httpGet: | ||
| path: /readyz | ||
| port: 8081 | ||
| initialDelaySeconds: 5 | ||
| periodSeconds: 10 | ||
| # TODO(user): Configure the resources accordingly based on the project requirements. | ||
| # More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ | ||
| resources: | ||
| limits: | ||
| cpu: 500m | ||
| memory: 128Mi | ||
| requests: | ||
| cpu: 10m | ||
| memory: 64Mi |
Check notice
Code scanning / Trivy
Runs with GID <= 10000 Low
- Add cmd/apply package for Job-based apply execution - Add internal/applyjob package with git clone and nixos-rebuild/anywhere runner - Add internal/metrics package with Prometheus metrics (gauges, counters, histograms) - Add SSH client unit tests - Add RBAC role for apply jobs - Update controllers with metrics integration - Fix Containerfile.ipxe PATH configuration Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: ZverGuy <maximbel2003@gmail.com>
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - secrets | ||
| verbs: | ||
| - get |
Check warning
Code scanning / Trivy
Manage namespace secrets Medium
Summary
Changes
API Types (
api/v1alpha1/):Controllers (
internal/controller/):Infrastructure:
Known Limitations (to address before stable release)
:latest- should be configurable via flag/envTest plan
go build ./...passesgo test ./...passes (MachineReconciler covered)golangci-lint run ./...- 0 issues