Drafting ctl controller
This commit is contained in:
@@ -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,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user