Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions pkg/controller/generic_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,12 @@ func (c *realGenericControlInterface) CreateOrUpdate(controller, obj client.Obje
}
}

// 1. try to create and see if there is any conflicts
err := c.client.Create(context.TODO(), desired)
if errors.IsAlreadyExists(err) {
// 1. check whether object exists
exist, err := c.Exist(client.ObjectKeyFromObject(desired), obj)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also change the comment

if err != nil {
return nil, err
}
if exist {

// 2. object has already existed, merge our desired changes to it
existing, err := EmptyClone(obj)
Expand Down Expand Up @@ -497,7 +500,8 @@ func (c *realGenericControlInterface) CreateOrUpdate(controller, obj client.Obje
return mutated, nil
}

// object do not exist, return the creation result
// object do not exist, do create and return the creation result
err = c.client.Create(context.TODO(), desired)
if err == nil {
c.RecordControllerEvent("create", controller, desired, err)
}
Expand Down