- 7 CRDs (Agent, AgentConfig, AgentGroup, Channel, Provider, WorkflowTemplate, CompliancePolicy) - 3 controllers (Agent, WorkflowTemplate, CompliancePolicy) - Generated deepcopy methods (controller-gen v0.16.5) - Dockerfile (multi-stage Go build) - Nix build-image.nix (dockerTools.streamLayeredImage) - Helm chart with RBAC, deployment, service account - Deploy manifests (RBAC + controller deployment) - Sample manifests for all 7 CRDs - Quickstart script - Successfully deployed to k3s on n97-mini: - Controller running and reconciling - All 7 CRDs registered - Agent CR creates Pod (ErrImagePull expected — no agent image yet) - Controller logs show reconciliation working
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
/*
|
|
Copyright 2025 Scott Scoble. Licensed under the MIT License.
|
|
*/
|
|
|
|
package controller
|
|
|
|
import (
|
|
"context"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
ctrl "sigs.k8s.io/controller-runtime"
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
"sigs.k8s.io/controller-runtime/pkg/log"
|
|
|
|
kubeclawv1alpha1 "github.com/sscoble/kubeclaw/api/v1alpha1"
|
|
)
|
|
|
|
// CompliancePolicyReconciler reconciles CompliancePolicy objects.
|
|
type CompliancePolicyReconciler struct {
|
|
client.Client
|
|
Scheme *runtime.Scheme
|
|
}
|
|
|
|
func (r *CompliancePolicyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
|
logger := log.FromContext(ctx)
|
|
|
|
cp := &kubeclawv1alpha1.CompliancePolicy{}
|
|
if err := r.Get(ctx, req.NamespacedName, cp); err != nil {
|
|
return ctrl.Result{}, client.IgnoreNotFound(err)
|
|
}
|
|
|
|
logger.Info("validating compliance policy", "name", cp.Name)
|
|
|
|
valid := true
|
|
if len(cp.Spec.Rules) == 0 {
|
|
valid = false
|
|
}
|
|
|
|
cp.Status.Ready = valid
|
|
|
|
if err := r.Status().Update(ctx, cp); err != nil {
|
|
return ctrl.Result{}, err
|
|
}
|
|
|
|
return ctrl.Result{}, nil
|
|
}
|
|
|
|
func (r *CompliancePolicyReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
|
return ctrl.NewControllerManagedBy(mgr).
|
|
For(&kubeclawv1alpha1.CompliancePolicy{}).
|
|
Complete(r)
|
|
}
|