savegame
This commit is contained in:
@@ -130,3 +130,4 @@ Create resources w/o prompting
|
|||||||
4. Run `make generate`
|
4. Run `make generate`
|
||||||
5. Run `make manifests`
|
5. Run `make manifests`
|
||||||
|
|
||||||
|
6. Adapt reconciler in `internal/controller` -> `tdset_controller.go`
|
||||||
@@ -18,6 +18,7 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
@@ -27,6 +28,10 @@ import (
|
|||||||
schedulev1 "github.com/baschno/tdset-operator/api/v1"
|
schedulev1 "github.com/baschno/tdset-operator/api/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DefaultReconciliationInterval = 5
|
||||||
|
)
|
||||||
|
|
||||||
// TDSetReconciler reconciles a TDSet object
|
// TDSetReconciler reconciles a TDSet object
|
||||||
type TDSetReconciler struct {
|
type TDSetReconciler struct {
|
||||||
client.Client
|
client.Client
|
||||||
@@ -47,11 +52,65 @@ type TDSetReconciler struct {
|
|||||||
// For more details, check Reconcile and its Result here:
|
// For more details, check Reconcile and its Result here:
|
||||||
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.0/pkg/reconcile
|
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.0/pkg/reconcile
|
||||||
func (r *TDSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
func (r *TDSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
||||||
_ = log.FromContext(ctx)
|
|
||||||
|
|
||||||
// TODO(user): your logic here
|
// TODO(user): your logic here
|
||||||
|
log := log.FromContext(ctx)
|
||||||
|
|
||||||
return ctrl.Result{}, nil
|
log.Info("starting reconciliation")
|
||||||
|
|
||||||
|
tdSet := &schedulev1.TDSet{}
|
||||||
|
|
||||||
|
// Get the TDSet
|
||||||
|
err := r.GetTDSet(ctx, req, tdSet)
|
||||||
|
if err != nil {
|
||||||
|
if apierrors.IsNotFound(err) {
|
||||||
|
log.Info("TDSet resource not found. Ignoring since object must be deleted")
|
||||||
|
|
||||||
|
return ctrl.Result{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Error(err, "Failed to get TDSet")
|
||||||
|
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to set initial condition status
|
||||||
|
err = r.SetInitialCondition(ctx, req, tdSet)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err, "failed to set initial condition")
|
||||||
|
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Delete finalizer
|
||||||
|
|
||||||
|
// Deployment if not exist
|
||||||
|
ok, err := r.DeploymentIfNotExist(ctx, req, tdSet)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err, "failed to deploy deployment for TDSet")
|
||||||
|
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok {
|
||||||
|
return ctrl.Result{RequeueAfter: time.Minute}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update deployment replica if mis matched.
|
||||||
|
err = r.UpdateDeploymentReplica(ctx, req, tdSet)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err, "failed to update deployment for TDSet")
|
||||||
|
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
interval := DefaultReconciliationInterval
|
||||||
|
if tdSet.Spec.IntervalMint != 0 {
|
||||||
|
interval = int(tdSet.Spec.IntervalMint)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info("ending reconciliation")
|
||||||
|
|
||||||
|
return ctrl.Result{RequeueAfter: time.Duration(time.Minute * time.Duration(interval))}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupWithManager sets up the controller with the Manager.
|
// SetupWithManager sets up the controller with the Manager.
|
||||||
|
|||||||
Reference in New Issue
Block a user