Skip to content

Commit

Permalink
write upsert error to status obj
Browse files Browse the repository at this point in the history
Signed-off-by: Avinash Patnala <avinashpatnala@google.com>
  • Loading branch information
Avinash Patnala committed Sep 21, 2024
1 parent 7bf092d commit 4bf9617
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
6 changes: 3 additions & 3 deletions apis/status/v1beta1/configpodstatus_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
)

func TestNewConfigStatusForPod(t *testing.T) {
podName := "some-gk-pod"
podNS := "a-gk-namespace"
configName := "a-config"
const podName = "some-gk-pod"
const podNS = "a-gk-namespace"
const configName = "a-config"

testutils.Setenv(t, "POD_NAMESPACE", podNS)

Expand Down
17 changes: 14 additions & 3 deletions pkg/controller/config/config_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ func (r *ReconcileConfig) Reconcile(ctx context.Context, request reconcile.Reque
if err := r.cacheManager.UpsertSource(ctx, configSourceKey, gvksToSync); err != nil {
r.tracker.For(configGVK).TryCancelExpect(instance)

return reconcile.Result{Requeue: true}, fmt.Errorf("config-controller: error establishing watches for new syncOny: %w", err)
return reconcile.Result{Requeue: true}, r.updateOrCreatePodStatus(ctx, instance, err)
}

r.tracker.For(configGVK).Observe(instance)

if deleted {
return reconcile.Result{}, r.deleteStatus(ctx, request.NamespacedName.Name)
}
return reconcile.Result{}, r.updateOrCreatePodStatus(ctx, instance)
return reconcile.Result{}, r.updateOrCreatePodStatus(ctx, instance, err)
}

func (r *ReconcileConfig) deleteStatus(ctx context.Context, cfgName string) error {
Expand All @@ -244,7 +244,7 @@ func (r *ReconcileConfig) deleteStatus(ctx context.Context, cfgName string) erro
return nil
}

func (r *ReconcileConfig) updateOrCreatePodStatus(ctx context.Context, cfg *configv1alpha1.Config) error {
func (r *ReconcileConfig) updateOrCreatePodStatus(ctx context.Context, cfg *configv1alpha1.Config, upsertErr error) error {
pod, err := r.getPod(ctx)
if err != nil {
return fmt.Errorf("getting reconciler pod: %w", err)
Expand All @@ -271,6 +271,8 @@ func (r *ReconcileConfig) updateOrCreatePodStatus(ctx context.Context, cfg *conf
return fmt.Errorf("getting config status in name %s, namespace %s: %w", cfg.GetName(), cfg.GetNamespace(), err)
}

setStatusError(status, upsertErr)

status.Status.ObservedGeneration = cfg.GetGeneration()

if shouldCreate {
Expand All @@ -288,3 +290,12 @@ func (r *ReconcileConfig) newConfigStatus(pod *corev1.Pod, cfg *configv1alpha1.C

return status, nil
}

func setStatusError(status *statusv1beta1.ConfigPodStatus, etErr error) {
if etErr == nil {
status.Status.Errors = nil
return
}
e := &statusv1beta1.ConfigError{Message: etErr.Error()}
status.Status.Errors = []*statusv1beta1.ConfigError{e}
}

0 comments on commit 4bf9617

Please sign in to comment.