-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from 3scale-ops/feat/show-resource-diff
feat/show-resource-diff
- Loading branch information
Showing
16 changed files
with
186 additions
and
509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package property | ||
|
||
import ( | ||
"github.com/go-logr/logr" | ||
"github.com/google/go-cmp/cmp" | ||
"k8s.io/apimachinery/pkg/api/equality" | ||
) | ||
|
||
type ChangeSet[T any] struct { | ||
path string | ||
current *T | ||
desired *T | ||
} | ||
|
||
func NewChangeSet[T any](path string, current *T, desired *T) *ChangeSet[T] { | ||
return &ChangeSet[T]{path: path, current: current, desired: desired} | ||
} | ||
|
||
// EnsureDesired checks if two structs are equal. If they are not, current is overwriten | ||
// with the value of desired. Bool flag is returned to indicate if the value of current was changed. | ||
func (set *ChangeSet[T]) EnsureDesired(logger logr.Logger) bool { | ||
|
||
if equality.Semantic.DeepEqual(set.current, set.desired) { | ||
return false | ||
} | ||
|
||
logger.V(1).Info("differences detected", "path", set.path, "diff", cmp.Diff(set.current, set.desired)) | ||
*set.current = *set.desired | ||
return true | ||
} | ||
|
||
type ReconcilableProperty interface { | ||
EnsureDesired(logger logr.Logger) bool | ||
} | ||
|
||
func EnsureDesired(logger logr.Logger, changeSets ...ReconcilableProperty) bool { | ||
changed := false | ||
|
||
for _, set := range changeSets { | ||
|
||
if set.EnsureDesired(logger) { | ||
changed = true | ||
} | ||
} | ||
|
||
return changed | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.