zero: report resource bundle reconciliation status (#4618)

* zero: report resource bundle reconciliation status

* use latest zero-sdk
This commit is contained in:
Denis Mishin 2023-10-11 10:25:34 -04:00 committed by Kenneth Jenkins
parent e64e682853
commit 60ab9dafbe
4 changed files with 77 additions and 89 deletions

View file

@ -0,0 +1,44 @@
package reconciler
import (
"context"
"github.com/pomerium/pomerium/internal/log"
cluster_api "github.com/pomerium/zero-sdk/cluster"
)
const (
// BundleStatusFailureDatabrokerError indicates a failure due to a databroker error
BundleStatusFailureDatabrokerError = cluster_api.DatabrokerError
// BundleStatusFailureDownloadError indicates a failure due to a download error
BundleStatusFailureDownloadError = cluster_api.DownloadError
// BundleStatusFailureInvalidBundle indicates a failure due to an invalid bundle
BundleStatusFailureInvalidBundle = cluster_api.InvalidBundle
// BundleStatusFailureIO indicates a failure due to an IO error
BundleStatusFailureIO = cluster_api.IoError
// BundleStatusFailureUnknownError indicates a failure due to an unknown error
BundleStatusFailureUnknownError = cluster_api.UnknownError
)
func (c *service) ReportBundleAppliedSuccess(
ctx context.Context,
bundleID string,
metadata map[string]string,
) {
err := c.config.api.ReportBundleAppliedSuccess(ctx, bundleID, metadata)
if err != nil {
log.Ctx(ctx).Err(err).Msg("reconciler: error reporting bundle status")
}
}
func (c *service) ReportBundleAppliedFailure(
ctx context.Context,
bundleID string,
source cluster_api.BundleStatusFailureSource,
err error,
) {
err = c.config.api.ReportBundleAppliedFailure(ctx, bundleID, source, err)
if err != nil {
log.Ctx(ctx).Err(err).Msg("reconciler: error reporting bundle status")
}
}

View file

@ -135,6 +135,7 @@ func (c *service) syncBundle(ctx context.Context, key string) error {
result, err := c.config.api.DownloadClusterResourceBundle(ctx, fd, key, conditional)
if err != nil {
c.ReportBundleAppliedFailure(ctx, key, BundleStatusFailureDownloadError, err)
return fmt.Errorf("download bundle: %w", err)
}
@ -155,6 +156,7 @@ func (c *service) syncBundle(ctx context.Context, key string) error {
bundleRecordTypes, err := c.syncBundleToDatabroker(ctx, fd, cached.GetRecordTypes())
if err != nil {
c.ReportBundleAppliedFailure(ctx, key, BundleStatusFailureDatabrokerError, err)
return fmt.Errorf("apply bundle to databroker: %w", err)
}
current := BundleCacheEntry{
@ -171,9 +173,12 @@ func (c *service) syncBundle(ctx context.Context, key string) error {
err = c.SetBundleCacheEntry(ctx, key, current)
if err != nil {
return fmt.Errorf("set bundle cache entry: %w", err)
err = fmt.Errorf("set bundle cache entry: %w", err)
c.ReportBundleAppliedFailure(ctx, key, BundleStatusFailureDatabrokerError, err)
return err
}
c.ReportBundleAppliedSuccess(ctx, key, result.Metadata)
return nil
}