|
|
@ -19,11 +19,12 @@ package main
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"github.com/fluxcd/pkg/apis/meta"
|
|
|
|
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/fluxcd/pkg/apis/meta"
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"k8s.io/apimachinery/pkg/types"
|
|
|
|
"k8s.io/apimachinery/pkg/types"
|
|
|
|
"k8s.io/apimachinery/pkg/util/wait"
|
|
|
|
"k8s.io/apimachinery/pkg/util/wait"
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
|
@ -94,7 +95,8 @@ func reconcileHrCmdRun(cmd *cobra.Command, args []string) error {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
logger.Actionf("annotating HelmRelease %s in %s namespace", name, namespace)
|
|
|
|
logger.Actionf("annotating HelmRelease %s in %s namespace", name, namespace)
|
|
|
|
if helmRelease.Annotations == nil {
|
|
|
|
if helmRelease.Annotations == nil {
|
|
|
|
helmRelease.Annotations = map[string]string{
|
|
|
|
helmRelease.Annotations = map[string]string{
|
|
|
@ -107,11 +109,11 @@ func reconcileHrCmdRun(cmd *cobra.Command, args []string) error {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logger.Successf("HelmRelease annotated")
|
|
|
|
logger.Successf("HelmRelease annotated")
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.Waitingf("waiting for HelmRelease reconciliation")
|
|
|
|
logger.Waitingf("waiting for HelmRelease reconciliation")
|
|
|
|
if err := wait.PollImmediate(pollInterval, timeout,
|
|
|
|
if err := wait.PollImmediate(pollInterval, timeout,
|
|
|
|
isHelmReleaseReady(ctx, kubeClient, name, namespace)); err != nil {
|
|
|
|
helmReleaseReconciliationHandled(ctx, kubeClient, name, namespace, helmRelease.Status.LastHandledReconcileAt),
|
|
|
|
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -121,16 +123,19 @@ func reconcileHrCmdRun(cmd *cobra.Command, args []string) error {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if c := meta.GetCondition(helmRelease.Status.Conditions, meta.ReadyCondition); c != nil {
|
|
|
|
if helmRelease.Status.LastAppliedRevision != "" {
|
|
|
|
switch c.Status {
|
|
|
|
logger.Successf("reconciled revision %s", helmRelease.Status.LastAppliedRevision)
|
|
|
|
case corev1.ConditionFalse:
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return fmt.Errorf("HelmRelease reconciliation failed")
|
|
|
|
return fmt.Errorf("HelmRelease reconciliation failed")
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
logger.Successf("reconciled revision %s", helmRelease.Status.LastAppliedRevision)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func isHelmReleaseReady(ctx context.Context, kubeClient client.Client, name, namespace string) wait.ConditionFunc {
|
|
|
|
func helmReleaseReconciliationHandled(ctx context.Context, kubeClient client.Client,
|
|
|
|
|
|
|
|
name, namespace, lastHandledReconcileAt string) wait.ConditionFunc {
|
|
|
|
return func() (bool, error) {
|
|
|
|
return func() (bool, error) {
|
|
|
|
var helmRelease helmv2.HelmRelease
|
|
|
|
var helmRelease helmv2.HelmRelease
|
|
|
|
namespacedName := types.NamespacedName{
|
|
|
|
namespacedName := types.NamespacedName{
|
|
|
@ -143,14 +148,6 @@ func isHelmReleaseReady(ctx context.Context, kubeClient client.Client, name, nam
|
|
|
|
return false, err
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if c := meta.GetCondition(helmRelease.Status.Conditions, meta.ReadyCondition); c != nil {
|
|
|
|
return helmRelease.Status.LastHandledReconcileAt != lastHandledReconcileAt, nil
|
|
|
|
switch c.Status {
|
|
|
|
|
|
|
|
case corev1.ConditionTrue:
|
|
|
|
|
|
|
|
return true, nil
|
|
|
|
|
|
|
|
case corev1.ConditionFalse:
|
|
|
|
|
|
|
|
return false, fmt.Errorf(c.Message)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|