Drafting ctl controller

This commit is contained in:
2026-04-20 02:50:04 +08:00
parent c6b399ba22
commit 6ddff7c433
52 changed files with 3093 additions and 347 deletions

View File

@@ -41,26 +41,55 @@ func (r *UpgradeRunner) Run(fn func() error) error {
return fn()
}
func HandleOSUpgrade(ctx context.Context, clients *kube.Clients,
namespace string, nodeName string,
osu *monov1alpha1.OSUpgrade,
func HandleOSUpgradeProgress(
ctx context.Context,
clients *kube.Clients,
namespace string,
nodeName string,
osup *monov1alpha1.OSUpgradeProgress,
) error {
return r.Run(func() error {
return handleOSUpgradeLocked(ctx, clients, namespace, nodeName, osu)
return handleOSUpgradeProgressLocked(ctx, clients, namespace, nodeName, osup)
})
}
func handleOSUpgradeLocked(ctx context.Context, clients *kube.Clients,
namespace string, nodeName string,
osu *monov1alpha1.OSUpgrade,
func handleOSUpgradeProgressLocked(
ctx context.Context,
clients *kube.Clients,
namespace string,
nodeName string,
osup *monov1alpha1.OSUpgradeProgress,
) error {
osup, err := ensureProgressHeartbeat(ctx, clients, namespace, nodeName, osu)
if err != nil {
return err
if osup == nil {
return fmt.Errorf("osupgradeprogress is nil")
}
klog.InfoS("handling osupgrade",
"name", osu.Name,
if osup.Spec.NodeName != nodeName {
return nil
}
if osup.Status.Phase != "" &&
osup.Status.Phase != monov1alpha1.OSUpgradeProgressPhasePending &&
osup.Status.Phase != monov1alpha1.OSUpgradeProgressPhaseDownloading {
// tune this logic however you want
return nil
}
parentName := osup.Spec.SourceRef.Name
if parentName == "" {
return failProgress(ctx, clients, osup, "resolve parent osupgrade", fmt.Errorf("missing spec.osUpgradeName"))
}
osu, err := clients.MonoKS.Monok8sV1alpha1().
OSUpgrades(namespace).
Get(ctx, parentName, metav1.GetOptions{})
if err != nil {
return failProgress(ctx, clients, osup, "resolve parent osupgrade", err)
}
klog.InfoS("handling osupgradeprogress",
"name", osup.Name,
"osupgrade", osu.Name,
"node", nodeName,
"desiredVersion", osu.Spec.DesiredVersion,
)

View File

@@ -28,6 +28,33 @@ var (
}
)
func EnsureOSUpgradeProgressForNode(
ctx context.Context,
clients *kube.Clients,
namespace string,
nodeName string,
osu *monov1alpha1.OSUpgrade,
) error {
if osu == nil {
return fmt.Errorf("osupgrade is nil")
}
// Keep using your existing helper if it already encapsulates
// selector matching / parent linkage / create-or-update semantics.
osup, err := ensureProgressHeartbeat(ctx, clients, namespace, nodeName, osu)
if err != nil {
return err
}
klog.InfoS("ensured OSUpgradeProgress from admission",
"osupgrade", osu.Name,
"osupgradeProgress", osup.Name,
"node", nodeName,
)
return nil
}
func ensureProgressHeartbeat(ctx context.Context, clients *kube.Clients,
namespace string, nodeName string,
osu *monov1alpha1.OSUpgrade,