-
Notifications
You must be signed in to change notification settings - Fork 34
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
Update limitador to 0.9.0 #608
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
95546af
kuadrant_controller: bring latest limitador
eguzki 00498bc
update bundle
eguzki a1d2431
limitador tracing not exposed from the kuadrant API
eguzki dffb47c
tests added to kuadrant_controller
eguzki 281e301
fix nil pointer dereference
eguzki b6e489f
gateway kuadrant controller dedicated testsuite
eguzki 20735d0
kuadrant controller: fix limitador replica mutator
eguzki 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
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 was deleted.
Oops, something went wrong.
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,133 @@ | ||
package kuadranttools | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1" | ||
|
||
"github.com/kuadrant/kuadrant-operator/pkg/library/reconcilers" | ||
) | ||
|
||
// DeploymentMutateFn is a function which mutates the existing Deployment into it's desired state. | ||
type LimitadorMutateFn func(desired, existing *limitadorv1alpha1.Limitador) bool | ||
|
||
func LimitadorMutator(opts ...LimitadorMutateFn) reconcilers.MutateFn { | ||
return func(existingObj, desiredObj client.Object) (bool, error) { | ||
existing, ok := existingObj.(*limitadorv1alpha1.Limitador) | ||
if !ok { | ||
return false, fmt.Errorf("existingObj %T is not a *limitadorv1alpha1.Limitador", existingObj) | ||
} | ||
desired, ok := desiredObj.(*limitadorv1alpha1.Limitador) | ||
if !ok { | ||
return false, fmt.Errorf("desiredObj %T is not a *limitadorv1alpha1.Limitador", desiredObj) | ||
} | ||
|
||
update := false | ||
|
||
// Loop through each option | ||
for _, opt := range opts { | ||
tmpUpdate := opt(desired, existing) | ||
update = update || tmpUpdate | ||
} | ||
|
||
return update, nil | ||
} | ||
} | ||
|
||
func LimitadorAffinityMutator(desired, existing *limitadorv1alpha1.Limitador) bool { | ||
update := false | ||
if !reflect.DeepEqual(existing.Spec.Affinity, desired.Spec.Affinity) { | ||
existing.Spec.Affinity = desired.Spec.Affinity | ||
update = true | ||
} | ||
return update | ||
} | ||
|
||
func LimitadorReplicasMutator(desired, existing *limitadorv1alpha1.Limitador) bool { | ||
update := false | ||
|
||
var existingReplicas = 1 | ||
|
||
if existing.Spec.Replicas != nil { | ||
existingReplicas = *existing.Spec.Replicas | ||
} | ||
|
||
var desiredReplicas = 1 | ||
|
||
if desired.Spec.Replicas != nil { | ||
desiredReplicas = *desired.Spec.Replicas | ||
} | ||
|
||
if desiredReplicas != existingReplicas { | ||
existing.Spec.Replicas = &desiredReplicas | ||
update = true | ||
} | ||
|
||
return update | ||
} | ||
|
||
func LimitadorStorageMutator(desired, existing *limitadorv1alpha1.Limitador) bool { | ||
update := false | ||
if !reflect.DeepEqual(existing.Spec.Storage, desired.Spec.Storage) { | ||
existing.Spec.Storage = desired.Spec.Storage | ||
update = true | ||
} | ||
return update | ||
} | ||
|
||
func LimitadorOwnerRefsMutator(desired, existing *limitadorv1alpha1.Limitador) bool { | ||
update := false | ||
if !reflect.DeepEqual(existing.OwnerReferences, desired.OwnerReferences) { | ||
existing.OwnerReferences = desired.OwnerReferences | ||
update = true | ||
} | ||
return update | ||
} | ||
|
||
func LimitadorRateLimitHeadersMutator(desired, existing *limitadorv1alpha1.Limitador) bool { | ||
update := false | ||
if !reflect.DeepEqual(existing.Spec.RateLimitHeaders, desired.Spec.RateLimitHeaders) { | ||
existing.Spec.RateLimitHeaders = desired.Spec.RateLimitHeaders | ||
update = true | ||
} | ||
return update | ||
} | ||
|
||
func LimitadorTelemetryMutator(desired, existing *limitadorv1alpha1.Limitador) bool { | ||
update := false | ||
if !reflect.DeepEqual(existing.Spec.Telemetry, desired.Spec.Telemetry) { | ||
existing.Spec.Telemetry = desired.Spec.Telemetry | ||
update = true | ||
} | ||
return update | ||
} | ||
|
||
func LimitadorPodDisruptionBudgetMutator(desired, existing *limitadorv1alpha1.Limitador) bool { | ||
update := false | ||
if !reflect.DeepEqual(existing.Spec.PodDisruptionBudget, desired.Spec.PodDisruptionBudget) { | ||
existing.Spec.PodDisruptionBudget = desired.Spec.PodDisruptionBudget | ||
update = true | ||
} | ||
return update | ||
} | ||
|
||
func LimitadorResourceRequirementsMutator(desired, existing *limitadorv1alpha1.Limitador) bool { | ||
update := false | ||
if !reflect.DeepEqual(existing.Spec.ResourceRequirements, desired.Spec.ResourceRequirements) { | ||
existing.Spec.ResourceRequirements = desired.Spec.ResourceRequirements | ||
update = true | ||
} | ||
return update | ||
} | ||
|
||
func LimitadorVerbosityMutator(desired, existing *limitadorv1alpha1.Limitador) bool { | ||
update := false | ||
if !reflect.DeepEqual(existing.Spec.Verbosity, desired.Spec.Verbosity) { | ||
existing.Spec.Verbosity = desired.Spec.Verbosity | ||
update = true | ||
} | ||
return update | ||
} | ||
Oops, something went wrong.
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.
Do you think it's possible to DRY these funcs a bit, with something like...
Since we are updating fields when are not matching the desired state, then we can populate the fields in an array and call it either in a for loop or reducer fn like...
not sure if we can even use the limitador spec types for the iteration instead of strings and interface{}
Maybe worth to try... maybe not
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.
It seems a great idea to avoid DRY. However, I have few little issues with the proposed implementation
Equal
method? Each field may need different comparing method.