Skip to content
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 7 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
14 changes: 12 additions & 2 deletions api/v1beta1/kuadrant_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,23 @@ type LimitadorSpec struct {
Replicas *int `json:"replicas,omitempty"`

// +optional
ResourceRequirements *corev1.ResourceRequirements `json:"resourceRequirements,omitempty"`
Storage *limitadorv1alpha1.Storage `json:"storage,omitempty"`

// +optional
RateLimitHeaders *limitadorv1alpha1.RateLimitHeadersType `json:"rateLimitHeaders,omitempty"`

// +optional
Telemetry *limitadorv1alpha1.Telemetry `json:"telemetry,omitempty"`

// +optional
PodDisruptionBudget *limitadorv1alpha1.PodDisruptionBudgetType `json:"pdb,omitempty"`

// +optional
Storage *limitadorv1alpha1.Storage `json:"storage,omitempty"`
ResourceRequirements *corev1.ResourceRequirements `json:"resourceRequirements,omitempty"`

// Sets the level of verbosity
// +optional
Verbosity *limitadorv1alpha1.VerbosityLevel `json:"verbosity,omitempty"`
}

// KuadrantStatus defines the observed state of Kuadrant
Expand Down
27 changes: 21 additions & 6 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ metadata:
capabilities: Basic Install
categories: Integration & Delivery
containerImage: quay.io/kuadrant/kuadrant-operator:latest
createdAt: "2024-07-05T16:23:56Z"
createdAt: "2024-07-10T15:04:27Z"
operators.operatorframework.io/builder: operator-sdk-v1.32.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: https://github.com/Kuadrant/kuadrant-operator
Expand Down
33 changes: 26 additions & 7 deletions bundle/manifests/kuadrant.io_kuadrants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,13 @@ spec:
evictions by specifying "100%".
x-kubernetes-int-or-string: true
type: object
rateLimitHeaders:
description: RateLimitHeadersType defines the valid options for
the --rate-limit-headers arg
enum:
- NONE
- DRAFT_VERSION_03
type: string
replicas:
type: integer
resourceRequirements:
Expand Down Expand Up @@ -976,6 +983,10 @@ spec:
x-kubernetes-map-type: atomic
options:
properties:
batch-size:
description: 'BatchSize defines the size of entries
to flush in as single flush [default: 100]'
type: integer
flush-period:
description: 'FlushPeriod for counters in milliseconds
[default: 1000]'
Expand All @@ -984,17 +995,25 @@ spec:
description: 'MaxCached refers to the maximum amount
of counters cached [default: 10000]'
type: integer
ratio:
description: 'Ratio to apply to the TTL from Redis
on cached counters [default: 10]'
type: integer
ttl:
description: 'TTL for cached counters in milliseconds
[default: 5000]'
response-timeout:
description: 'ResponseTimeout defines the timeout
for Redis commands in milliseconds [default: 350]'
type: integer
type: object
type: object
type: object
telemetry:
description: Telemetry defines the level of metrics Limitador
will expose to the user
enum:
- basic
- exhaustive
type: string
verbosity:
description: Sets the level of verbosity
maximum: 4
minimum: 1
type: integer
type: object
type: object
status:
Expand Down
33 changes: 26 additions & 7 deletions config/crd/bases/kuadrant.io_kuadrants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,13 @@ spec:
evictions by specifying "100%".
x-kubernetes-int-or-string: true
type: object
rateLimitHeaders:
description: RateLimitHeadersType defines the valid options for
the --rate-limit-headers arg
enum:
- NONE
- DRAFT_VERSION_03
type: string
replicas:
type: integer
resourceRequirements:
Expand Down Expand Up @@ -974,6 +981,10 @@ spec:
x-kubernetes-map-type: atomic
options:
properties:
batch-size:
description: 'BatchSize defines the size of entries
to flush in as single flush [default: 100]'
type: integer
flush-period:
description: 'FlushPeriod for counters in milliseconds
[default: 1000]'
Expand All @@ -982,17 +993,25 @@ spec:
description: 'MaxCached refers to the maximum amount
of counters cached [default: 10000]'
type: integer
ratio:
description: 'Ratio to apply to the TTL from Redis
on cached counters [default: 10]'
type: integer
ttl:
description: 'TTL for cached counters in milliseconds
[default: 5000]'
response-timeout:
description: 'ResponseTimeout defines the timeout
for Redis commands in milliseconds [default: 350]'
type: integer
type: object
type: object
type: object
telemetry:
description: Telemetry defines the level of metrics Limitador
will expose to the user
enum:
- basic
- exhaustive
type: string
verbosity:
description: Sets the level of verbosity
maximum: 4
minimum: 1
type: integer
type: object
type: object
status:
Expand Down
82 changes: 47 additions & 35 deletions controllers/kuadrant_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,54 +408,66 @@ func (r *KuadrantReconciler) reconcileSpec(ctx context.Context, kObj *kuadrantv1
}

func (r *KuadrantReconciler) reconcileLimitador(ctx context.Context, kObj *kuadrantv1beta1.Kuadrant) error {
limitadorKey := client.ObjectKey{Name: common.LimitadorName, Namespace: kObj.Namespace}
limitador := &limitadorv1alpha1.Limitador{}
err := r.Client().Get(ctx, limitadorKey, limitador)
limitador := &limitadorv1alpha1.Limitador{
TypeMeta: metav1.TypeMeta{
Kind: "Limitador",
APIVersion: "limitador.kuadrant.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: common.LimitadorName,
Namespace: kObj.Namespace,
},
Spec: limitadorv1alpha1.LimitadorSpec{},
}

if kObj.Spec.Limitador != nil {
limitador.Spec.Affinity = kObj.Spec.Limitador.Affinity
limitador.Spec.Replicas = kObj.Spec.Limitador.Replicas
limitador.Spec.Storage = kObj.Spec.Limitador.Storage
limitador.Spec.RateLimitHeaders = kObj.Spec.Limitador.RateLimitHeaders
limitador.Spec.Telemetry = kObj.Spec.Limitador.Telemetry
limitador.Spec.PodDisruptionBudget = kObj.Spec.Limitador.PodDisruptionBudget
limitador.Spec.ResourceRequirements = kObj.Spec.Limitador.ResourceRequirements
limitador.Spec.Verbosity = kObj.Spec.Limitador.Verbosity
}

err := r.SetOwnerReference(kObj, limitador)
if err != nil {
if apierrors.IsNotFound(err) {
limitador = &limitadorv1alpha1.Limitador{
TypeMeta: metav1.TypeMeta{
Kind: "Limitador",
APIVersion: "limitador.kuadrant.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: common.LimitadorName,
Namespace: kObj.Namespace,
},
Spec: limitadorv1alpha1.LimitadorSpec{
RateLimitHeaders: &[]limitadorv1alpha1.RateLimitHeadersType{limitadorv1alpha1.RateLimitHeadersTypeDraft03}[0],
Telemetry: &[]limitadorv1alpha1.Telemetry{limitadorv1alpha1.TelemetryExhaustive}[0],
},
}
} else {
return err
}
return err
}

limitadorMutators := make([]kuadranttools.LimitadorMutateFn, 0)

limitadorMutators = append(limitadorMutators, kuadranttools.LimitadorOwnerRefsMutator)

if kObj.Spec.Limitador != nil {
Copy link
Member

Choose a reason for hiding this comment

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

If you feel the DRYing is worthy, maybe the reflect lib can help with iteration...

if kObj.Spec.Limitador != nil {
fields := reflect.ValueOf(kObj.Spec.Limitador)
for i := 0; i < v.NumField(); i++ {
// here check if the value `v.Field(i).Interface()` is nil and call the mutator with the desired and expected
}

if kObj.Spec.Limitador.Affinity != nil {
limitador.Spec.Affinity = kObj.Spec.Limitador.Affinity
}
if kObj.Spec.Limitador.PodDisruptionBudget != nil {
limitador.Spec.PodDisruptionBudget = kObj.Spec.Limitador.PodDisruptionBudget
limitadorMutators = append(limitadorMutators, kuadranttools.LimitadorAffinityMutator)
}
if kObj.Spec.Limitador.Replicas != nil {
limitador.Spec.Replicas = kObj.Spec.Limitador.Replicas
limitadorMutators = append(limitadorMutators, kuadranttools.LimitadorReplicasMutator)
}
if kObj.Spec.Limitador.Storage != nil {
limitadorMutators = append(limitadorMutators, kuadranttools.LimitadorStorageMutator)
}
if kObj.Spec.Limitador.RateLimitHeaders != nil {
limitadorMutators = append(limitadorMutators, kuadranttools.LimitadorRateLimitHeadersMutator)
}
if kObj.Spec.Limitador.Telemetry != nil {
limitadorMutators = append(limitadorMutators, kuadranttools.LimitadorTelemetryMutator)
}
if kObj.Spec.Limitador.PodDisruptionBudget != nil {
limitadorMutators = append(limitadorMutators, kuadranttools.LimitadorPodDisruptionBudgetMutator)
}
if kObj.Spec.Limitador.ResourceRequirements != nil {
limitador.Spec.ResourceRequirements = kObj.Spec.Limitador.ResourceRequirements
limitadorMutators = append(limitadorMutators, kuadranttools.LimitadorResourceRequirementsMutator)
}
if kObj.Spec.Limitador.Storage != nil {
limitador.Spec.Storage = kObj.Spec.Limitador.Storage
if kObj.Spec.Limitador.Verbosity != nil {
limitadorMutators = append(limitadorMutators, kuadranttools.LimitadorVerbosityMutator)
}
}

err = r.SetOwnerReference(kObj, limitador)
if err != nil {
return err
}

return r.ReconcileResource(ctx, &limitadorv1alpha1.Limitador{}, limitador, kuadranttools.LimitadorMutator)
return r.ReconcileResource(ctx, &limitadorv1alpha1.Limitador{}, limitador, kuadranttools.LimitadorMutator(limitadorMutators...))
}

func (r *KuadrantReconciler) reconcileAuthorino(ctx context.Context, kObj *kuadrantv1beta1.Kuadrant) error {
Expand Down
86 changes: 0 additions & 86 deletions controllers/suite_test.go

This file was deleted.

Loading