-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Infoblox, heavy load fixed #312
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,17 @@ | ||
package utils | ||
|
||
// MergeAnnotations adds or updates annotations from source to target and returns merge | ||
func MergeAnnotations(target map[string]string, source map[string]string) map[string]string { | ||
if target == nil { | ||
target = make(map[string]string) | ||
} | ||
if source == nil { | ||
source = make(map[string]string) | ||
} | ||
for k, v := range source { | ||
if target[k] != v { | ||
target[k] = v | ||
} | ||
} | ||
return target | ||
} |
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,73 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var a2 = map[string]string{"k8gb.io/primary-geotag": "eu", "k8gb.io/strategy": "failover"} | ||
var a1 = map[string]string{"field.cattle.io/publicEndpoints": "dummy"} | ||
|
||
func TestAddNewAnnotations(t *testing.T) { | ||
// arrange | ||
// act | ||
repaired := MergeAnnotations(a1, a2) | ||
// assert | ||
assert.Equal(t, 3, len(repaired)) | ||
assert.Equal(t, "eu", repaired["k8gb.io/primary-geotag"]) | ||
assert.Equal(t, "dummy", repaired["field.cattle.io/publicEndpoints"]) | ||
} | ||
|
||
func TestAddExistingAnnotations(t *testing.T) { | ||
// arrange | ||
for k, v := range a2 { | ||
a1[k] = v | ||
} | ||
// act | ||
repaired := MergeAnnotations(a1, a2) | ||
// assert | ||
assert.Equal(t, 3, len(repaired)) | ||
assert.Equal(t, "eu", repaired["k8gb.io/primary-geotag"]) | ||
assert.Equal(t, "dummy", repaired["field.cattle.io/publicEndpoints"]) | ||
assert.Equal(t, "failover", repaired["k8gb.io/strategy"]) | ||
} | ||
|
||
func TestUpdateExistingRecords(t *testing.T) { | ||
// arrange | ||
for k, v := range a2 { | ||
a1[k] = v | ||
} | ||
a1["k8gb.io/primary-geotag"] = "us" | ||
// act | ||
repaired := MergeAnnotations(a1, a2) | ||
// assert | ||
assert.Equal(t, 3, len(repaired)) | ||
assert.Equal(t, "eu", repaired["k8gb.io/primary-geotag"]) | ||
assert.Equal(t, "dummy", repaired["field.cattle.io/publicEndpoints"]) | ||
assert.Equal(t, "failover", repaired["k8gb.io/strategy"]) | ||
} | ||
|
||
func TestEqualAnnotationsWithNilA1(t *testing.T) { | ||
// arrange | ||
// act | ||
repaired := MergeAnnotations(nil, a2) | ||
// assert | ||
assert.True(t, assert.ObjectsAreEqual(a2, repaired)) | ||
} | ||
|
||
func TestEqualAnnotationsWithNilA2(t *testing.T) { | ||
// arrange | ||
// act | ||
repaired := MergeAnnotations(a1, nil) | ||
// assert | ||
assert.True(t, assert.ObjectsAreEqual(a1, repaired)) | ||
} | ||
|
||
func TestEqualAnnotationsWithNilInput(t *testing.T) { | ||
// arrange | ||
// act | ||
repaired := MergeAnnotations(nil, nil) | ||
// assert | ||
assert.Equal(t, 0, len(repaired)) | ||
} |
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,45 @@ | ||
package utils | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/go-logr/logr" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
) | ||
|
||
type ReconcileResultHandler struct { | ||
log logr.Logger | ||
delayedResult ctrl.Result | ||
} | ||
|
||
func NewReconcileResultHandler(reconcileAfter int, log logr.Logger) *ReconcileResultHandler { | ||
return &ReconcileResultHandler{ | ||
delayedResult: ctrl.Result{RequeueAfter: time.Second * time.Duration(reconcileAfter)}, | ||
log: log, | ||
} | ||
} | ||
|
||
// Stop stops reconciliation loop | ||
func (r *ReconcileResultHandler) Stop() (ctrl.Result, error) { | ||
r.log.Info("reconciler exit") | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
// RequeueError requeue loop immediately | ||
// see default controller limiter: https://danielmangum.com/posts/controller-runtime-client-go-rate-limiting/ | ||
func (r *ReconcileResultHandler) RequeueError(err error) (ctrl.Result, error) { | ||
// logging error is handled in caller function | ||
return ctrl.Result{}, err | ||
} | ||
|
||
// Requeue requeue loop after config.ReconcileRequeueSeconds | ||
// this apply in case you didn't modify request resources. | ||
// If so, reconciliation starts immediately | ||
// see: https://github.com/operator-framework/operator-sdk/issues/1164 | ||
func (r *ReconcileResultHandler) Requeue() (ctrl.Result, error) { | ||
return r.delayedResult, nil | ||
} | ||
|
||
func (r *ReconcileResultHandler) RequeueNow() (ctrl.Result, error) { | ||
return ctrl.Result{Requeue: true}, nil | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just in case the
ensureIngress
naming was inherited from official operator-sdk quickstart tutorial. Obviously no strong opinion here :)