mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-25 17:12:50 +00:00
fix: change failed_when execute time (#2586)
* fix: change failed_when execute time Signed-off-by: joyceliu <joyceliu@yunify.com> * doc: move pkg/util to pkg/controllers/util Signed-off-by: joyceliu <joyceliu@yunify.com> --------- Signed-off-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
parent
4c9256cae4
commit
d979c92066
|
|
@ -38,7 +38,7 @@ import (
|
|||
|
||||
"github.com/kubesphere/kubekey/v4/cmd/controller-manager/app/options"
|
||||
_const "github.com/kubesphere/kubekey/v4/pkg/const"
|
||||
"github.com/kubesphere/kubekey/v4/pkg/util"
|
||||
"github.com/kubesphere/kubekey/v4/pkg/controllers/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import (
|
|||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
|
||||
_const "github.com/kubesphere/kubekey/v4/pkg/const"
|
||||
"github.com/kubesphere/kubekey/v4/pkg/util"
|
||||
"github.com/kubesphere/kubekey/v4/pkg/controllers/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import (
|
|||
|
||||
"github.com/kubesphere/kubekey/v4/cmd/controller-manager/app/options"
|
||||
_const "github.com/kubesphere/kubekey/v4/pkg/const"
|
||||
"github.com/kubesphere/kubekey/v4/pkg/util"
|
||||
"github.com/kubesphere/kubekey/v4/pkg/controllers/util"
|
||||
)
|
||||
|
||||
// InventoryReconciler reconciles a Inventory object
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ import (
|
|||
|
||||
"github.com/kubesphere/kubekey/v4/cmd/controller-manager/app/options"
|
||||
_const "github.com/kubesphere/kubekey/v4/pkg/const"
|
||||
"github.com/kubesphere/kubekey/v4/pkg/controllers/util"
|
||||
"github.com/kubesphere/kubekey/v4/pkg/converter"
|
||||
"github.com/kubesphere/kubekey/v4/pkg/util"
|
||||
)
|
||||
|
||||
// KKClusterReconciler reconciles a KKCluster object
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ import (
|
|||
|
||||
"github.com/kubesphere/kubekey/v4/cmd/controller-manager/app/options"
|
||||
_const "github.com/kubesphere/kubekey/v4/pkg/const"
|
||||
"github.com/kubesphere/kubekey/v4/pkg/util"
|
||||
"github.com/kubesphere/kubekey/v4/pkg/controllers/util"
|
||||
)
|
||||
|
||||
// KKMachineReconciler reconciles a KKMachine object.
|
||||
|
|
|
|||
|
|
@ -325,11 +325,6 @@ func (e *taskExecutor) executeModule(ctx context.Context, task *kkcorev1alpha1.T
|
|||
return
|
||||
}
|
||||
|
||||
// Check if task should fail based on failed_when conditions
|
||||
if skip := e.dealFailedWhen(had, stdout, stderr); skip {
|
||||
return
|
||||
}
|
||||
|
||||
// Execute the actual module with the prepared context
|
||||
*stdout, *stderr = modules.FindModule(task.Spec.Module.Name)(ctx, modules.ExecOptions{
|
||||
Args: e.task.Spec.Module.Args,
|
||||
|
|
@ -339,6 +334,8 @@ func (e *taskExecutor) executeModule(ctx context.Context, task *kkcorev1alpha1.T
|
|||
Playbook: *e.playbook,
|
||||
LogOutput: e.logOutput,
|
||||
})
|
||||
|
||||
e.dealFailedWhen(had, stderr)
|
||||
}
|
||||
|
||||
// dealLoop parses the loop specification into a slice of items to iterate over.
|
||||
|
|
@ -380,24 +377,17 @@ func (e *taskExecutor) dealWhen(had map[string]any, stdout, stderr *string) bool
|
|||
|
||||
// dealFailedWhen evaluates the "failed_when" conditions for a task to determine if it should fail.
|
||||
// Returns true if the task should be marked as failed, false if it should proceed.
|
||||
func (e *taskExecutor) dealFailedWhen(had map[string]any, stdout, stderr *string) bool {
|
||||
func (e *taskExecutor) dealFailedWhen(had map[string]any, stderr *string) {
|
||||
if len(e.task.Spec.FailedWhen) > 0 {
|
||||
ok, err := tmpl.ParseBool(had, e.task.Spec.FailedWhen...)
|
||||
if err != nil {
|
||||
klog.V(5).ErrorS(err, "validate failed_when condition error", "task", ctrlclient.ObjectKeyFromObject(e.task))
|
||||
*stderr = fmt.Sprintf("parse failed_when condition error: %v", err)
|
||||
|
||||
return true
|
||||
}
|
||||
if ok {
|
||||
*stdout = modules.StdoutFalse
|
||||
*stderr = "reach failed_when, failed"
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// dealRegister handles storing task output in a registered variable if specified.
|
||||
|
|
|
|||
Loading…
Reference in New Issue