Reuse isReady from create_image commands
I implemented the isReady procedure for adapters for resume -- use it in create too. Signed-off-by: Michael Bridgen <michael@weave.works>
This commit is contained in:
@@ -22,7 +22,6 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
apimeta "k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
@@ -31,7 +30,6 @@ import (
|
||||
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
autov1 "github.com/fluxcd/image-automation-controller/api/v1alpha1"
|
||||
"github.com/fluxcd/pkg/apis/meta"
|
||||
)
|
||||
|
||||
var createImageUpdateCmd = &cobra.Command{
|
||||
@@ -130,7 +128,7 @@ func createImageUpdateRun(cmd *cobra.Command, args []string) error {
|
||||
|
||||
logger.Waitingf("waiting for ImageUpdateAutomation reconciliation")
|
||||
if err := wait.PollImmediate(pollInterval, timeout,
|
||||
isImageUpdateAutomationReady(ctx, kubeClient, namespacedName, &update)); err != nil {
|
||||
isReady(ctx, kubeClient, namespacedName, imageUpdateAutomationAdapter{&update})); err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Successf("ImageUpdateAutomation reconciliation completed")
|
||||
@@ -164,28 +162,3 @@ func upsertImageUpdateAutomation(ctx context.Context, kubeClient client.Client,
|
||||
}
|
||||
return nsname, nil
|
||||
}
|
||||
|
||||
func isImageUpdateAutomationReady(ctx context.Context, kubeClient client.Client,
|
||||
namespacedName types.NamespacedName, update *autov1.ImageUpdateAutomation) wait.ConditionFunc {
|
||||
return func() (bool, error) {
|
||||
err := kubeClient.Get(ctx, namespacedName, update)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// Confirm the state we are observing is for the current generation
|
||||
if update.Generation != update.Status.ObservedGeneration {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if c := apimeta.FindStatusCondition(update.Status.Conditions, meta.ReadyCondition); c != nil {
|
||||
switch c.Status {
|
||||
case metav1.ConditionTrue:
|
||||
return true, nil
|
||||
case metav1.ConditionFalse:
|
||||
return false, fmt.Errorf(c.Message)
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user