Skip to content

Commit

Permalink
crd /status update check (pomerium#439)
Browse files Browse the repository at this point in the history
* check observed generation when updating status

* update on state transition
  • Loading branch information
wasaga authored Nov 22, 2022
1 parent 7d86072 commit cdc389c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/all_in_one.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (s *allCmdParam) runBootstrapConfigController(ctx context.Context, reconcil
}
name := "bootstrap"
if host, err := os.Hostname(); err == nil {
name = fmt.Sprintf("%s-%s", name, host)
name = fmt.Sprintf("%s pod/%s", name, host)
}
if err := settings.NewSettingsController(mgr, reconciler, s.settings, name, false); err != nil {
return fmt.Errorf("settings controller: %w", err)
Expand Down
6 changes: 2 additions & 4 deletions controllers/ingress/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,13 @@ func (r *ingressController) deleteIngress(ctx context.Context, name types.Namesp
}

func (r *ingressController) upsertIngress(ctx context.Context, ic *model.IngressConfig) (ctrl.Result, error) {
changed, err := r.IngressReconciler.Upsert(ctx, ic)
_, err := r.IngressReconciler.Upsert(ctx, ic)
if err != nil {
r.IngressNotReconciled(ctx, ic.Ingress, err)
return ctrl.Result{Requeue: true}, fmt.Errorf("upsert: %w", err)
}

if changed {
r.IngressReconciled(ctx, ic.Ingress)
}
r.IngressReconciled(ctx, ic.Ingress)

if err = r.updateIngressStatus(ctx, ic.Ingress); err != nil {
return ctrl.Result{Requeue: true}, fmt.Errorf("update ingress status: %w", err)
Expand Down
16 changes: 14 additions & 2 deletions controllers/settings/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,24 @@ func (c *settingsController) Reconcile(ctx context.Context, req ctrl.Request) (c

changed, err := c.SetConfig(ctx, cfg)
if err != nil {
c.SettingsRejected(ctx, &cfg.Pomerium, err)
if statusUpToDate(&cfg.Pomerium, false) {
c.SettingsRejected(ctx, &cfg.Pomerium, err)
}
return ctrl.Result{Requeue: true}, fmt.Errorf("set config: %w", err)
}
if changed {
if changed || !statusUpToDate(&cfg.Pomerium, true) {
c.SettingsUpdated(ctx, &cfg.Pomerium)
}

return ctrl.Result{}, nil
}

func statusUpToDate(pom *icsv1.Pomerium, reconciled bool) bool {
if pom.Status.SettingsStatus == nil {
return false
}
if pom.Status.SettingsStatus.Reconciled != reconciled {
return false
}
return pom.Generation == pom.Status.SettingsStatus.ObservedGeneration
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/iancoleman/strcase v0.2.0
github.com/martinlindhe/base36 v1.1.1
github.com/open-policy-agent/opa v0.46.1
github.com/pomerium/csrf v1.7.0
github.com/pomerium/pomerium v0.20.0
github.com/sergi/go-diff v1.2.0
github.com/spf13/cobra v1.6.1
Expand Down Expand Up @@ -229,7 +230,6 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polyfloyd/go-errorlint v1.0.5 // indirect
github.com/pomerium/csrf v1.7.0 // indirect
github.com/pomerium/datasource v0.18.2-0.20221108160055-c6134b5ed524 // indirect
github.com/pomerium/webauthn v0.0.0-20211014213840-422c7ce1077f // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
Expand Down

0 comments on commit cdc389c

Please sign in to comment.