From a332ded88ad2b487be39a55e19f00899beafad47 Mon Sep 17 00:00:00 2001 From: Donnie Adams Date: Wed, 20 Nov 2024 11:50:05 -0500 Subject: [PATCH] fix: set aliases as unassigned on changes or deletes Signed-off-by: Donnie Adams --- pkg/controller/handlers/alias/alias.go | 13 +++++++------ pkg/storage/apis/otto.otto8.ai/v1/agent.go | 4 ++-- pkg/storage/apis/otto.otto8.ai/v1/alias.go | 2 +- pkg/storage/apis/otto.otto8.ai/v1/emailaddress.go | 4 ++-- pkg/storage/apis/otto.otto8.ai/v1/oauthapp.go | 2 +- pkg/storage/apis/otto.otto8.ai/v1/webhook.go | 4 ++-- pkg/storage/apis/otto.otto8.ai/v1/workflow.go | 4 ++-- 7 files changed, 17 insertions(+), 16 deletions(-) diff --git a/pkg/controller/handlers/alias/alias.go b/pkg/controller/handlers/alias/alias.go index 66687f31a..68a5f349e 100644 --- a/pkg/controller/handlers/alias/alias.go +++ b/pkg/controller/handlers/alias/alias.go @@ -27,6 +27,11 @@ func AssignAlias(req router.Request, _ router.Response) error { aliasable := req.Object.(v1.Aliasable) if aliasable.GetAliasName() == "" { + if aliasable.IsAssigned() { + aliasable.SetAssigned(false) + return req.Client.Status().Update(req.Ctx, req.Object) + } + return nil } @@ -56,12 +61,8 @@ func AssignAlias(req router.Request, _ router.Response) error { return err } - if !matches(alias, req.Object) { - return nil - } - - if !aliasable.IsAssigned() { - aliasable.SetAssigned() + if assigned := matches(alias, req.Object); assigned != aliasable.IsAssigned() { + aliasable.SetAssigned(assigned) return req.Client.Status().Update(req.Ctx, req.Object) } diff --git a/pkg/storage/apis/otto.otto8.ai/v1/agent.go b/pkg/storage/apis/otto.otto8.ai/v1/agent.go index db9ac3f74..91b57313d 100644 --- a/pkg/storage/apis/otto.otto8.ai/v1/agent.go +++ b/pkg/storage/apis/otto.otto8.ai/v1/agent.go @@ -32,8 +32,8 @@ func (a *Agent) GetAliasName() string { return a.Spec.Manifest.Alias } -func (a *Agent) SetAssigned() { - a.Status.AliasAssigned = true +func (a *Agent) SetAssigned(assigned bool) { + a.Status.AliasAssigned = assigned } func (a *Agent) Has(field string) bool { diff --git a/pkg/storage/apis/otto.otto8.ai/v1/alias.go b/pkg/storage/apis/otto.otto8.ai/v1/alias.go index 87a4723e1..438d87229 100644 --- a/pkg/storage/apis/otto.otto8.ai/v1/alias.go +++ b/pkg/storage/apis/otto.otto8.ai/v1/alias.go @@ -43,7 +43,7 @@ type AliasSpec struct { type Aliasable interface { GetAliasName() string - SetAssigned() + SetAssigned(bool) IsAssigned() bool } diff --git a/pkg/storage/apis/otto.otto8.ai/v1/emailaddress.go b/pkg/storage/apis/otto.otto8.ai/v1/emailaddress.go index 983902e5b..dc0dfa77f 100644 --- a/pkg/storage/apis/otto.otto8.ai/v1/emailaddress.go +++ b/pkg/storage/apis/otto.otto8.ai/v1/emailaddress.go @@ -24,8 +24,8 @@ func (in *EmailReceiver) GetAliasName() string { return in.Spec.EmailReceiverManifest.User } -func (in *EmailReceiver) SetAssigned() { - in.Status.AliasAssigned = true +func (in *EmailReceiver) SetAssigned(assigned bool) { + in.Status.AliasAssigned = assigned } func (in *EmailReceiver) IsAssigned() bool { diff --git a/pkg/storage/apis/otto.otto8.ai/v1/oauthapp.go b/pkg/storage/apis/otto.otto8.ai/v1/oauthapp.go index 21824a2a2..797857e5d 100644 --- a/pkg/storage/apis/otto.otto8.ai/v1/oauthapp.go +++ b/pkg/storage/apis/otto.otto8.ai/v1/oauthapp.go @@ -28,7 +28,7 @@ func (r *OAuthApp) GetAliasName() string { return r.Spec.Manifest.Integration } -func (r *OAuthApp) SetAssigned() { +func (r *OAuthApp) SetAssigned(bool) { } func (r *OAuthApp) IsAssigned() bool { diff --git a/pkg/storage/apis/otto.otto8.ai/v1/webhook.go b/pkg/storage/apis/otto.otto8.ai/v1/webhook.go index a7fa96166..c155fe632 100644 --- a/pkg/storage/apis/otto.otto8.ai/v1/webhook.go +++ b/pkg/storage/apis/otto.otto8.ai/v1/webhook.go @@ -24,8 +24,8 @@ func (w *Webhook) GetAliasName() string { return w.Spec.WebhookManifest.Alias } -func (w *Webhook) SetAssigned() { - w.Status.AliasAssigned = true +func (w *Webhook) SetAssigned(assigned bool) { + w.Status.AliasAssigned = assigned } func (w *Webhook) IsAssigned() bool { diff --git a/pkg/storage/apis/otto.otto8.ai/v1/workflow.go b/pkg/storage/apis/otto.otto8.ai/v1/workflow.go index 92c53f9f4..6420d0f2a 100644 --- a/pkg/storage/apis/otto.otto8.ai/v1/workflow.go +++ b/pkg/storage/apis/otto.otto8.ai/v1/workflow.go @@ -24,8 +24,8 @@ func (in *Workflow) GetAliasName() string { return in.Spec.Manifest.Alias } -func (in *Workflow) SetAssigned() { - in.Status.AliasAssigned = true +func (in *Workflow) SetAssigned(assigned bool) { + in.Status.AliasAssigned = assigned } func (in *Workflow) IsAssigned() bool {