Skip to content

Commit

Permalink
fix: set aliases as unassigned on changes or deletes
Browse files Browse the repository at this point in the history
Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams committed Nov 20, 2024
1 parent e47684b commit a332ded
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
13 changes: 7 additions & 6 deletions pkg/controller/handlers/alias/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/apis/otto.otto8.ai/v1/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/apis/otto.otto8.ai/v1/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type AliasSpec struct {

type Aliasable interface {
GetAliasName() string
SetAssigned()
SetAssigned(bool)
IsAssigned() bool
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/apis/otto.otto8.ai/v1/emailaddress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/apis/otto.otto8.ai/v1/oauthapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/apis/otto.otto8.ai/v1/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/apis/otto.otto8.ai/v1/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a332ded

Please sign in to comment.