Skip to content

Commit

Permalink
resource: add SetChanged() to LateInitializer so that it can be exten…
Browse files Browse the repository at this point in the history
…ded by providers as needed

Signed-off-by: Muvaffak Onus <me@muvaf.com>
  • Loading branch information
muvaf committed May 31, 2021
1 parent 0503711 commit 4a29beb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/resource/late_initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,18 @@ func (li *LateInitializer) IsChanged() bool {
return li.changed
}

// SetChanged marks the LateInitializer such that users can tell whether any
// of the late initialization calls returned the non-original argument.
func (li *LateInitializer) SetChanged() {
li.changed = true
}

// LateInitializeStringPtr implements late initialization for *string.
func (li *LateInitializer) LateInitializeStringPtr(org *string, from *string) *string {
if org != nil || from == nil {
return org
}
li.changed = true
li.SetChanged()
return from
}

Expand All @@ -55,7 +61,7 @@ func (li *LateInitializer) LateInitializeInt64Ptr(org *int64, from *int64) *int6
if org != nil || from == nil {
return org
}
li.changed = true
li.SetChanged()
return from
}

Expand All @@ -64,7 +70,7 @@ func (li *LateInitializer) LateInitializeBoolPtr(org *bool, from *bool) *bool {
if org != nil || from == nil {
return org
}
li.changed = true
li.SetChanged()
return from
}

Expand All @@ -74,7 +80,7 @@ func (li *LateInitializer) LateInitializeTimePtr(org *metav1.Time, from *time.Ti
if org != nil || from == nil {
return org
}
li.changed = true
li.SetChanged()
t := metav1.NewTime(*from)
return &t
}

0 comments on commit 4a29beb

Please sign in to comment.