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

Implement weighted queues #307

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
7 changes: 7 additions & 0 deletions api/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ type ResourceGraphDefinitionSpec struct {
//
// +kubebuilder:validation:Optional
DefaultServiceAccounts map[string]string `json:"defaultServiceAccounts,omitempty"`
// The weight used to determine priority when queuing reconciliation.
//
// +kubebuilder:default=100
// +kubebuilder:validation:Maximum=1000
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Optional
Weight int `json:"weight,omitempty"`
}

// Schema represents the attributes that define an instance of
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/kro.run_resourcegraphdefinitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ spec:
- apiVersion
- kind
type: object
weight:
default: 100
description: The weight used to determine priority when queuing reconciliation.
maximum: 1000
minimum: 1
type: integer
required:
- schema
type: object
Expand Down
5 changes: 3 additions & 2 deletions examples/kubernetes/webapp/rg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ kind: ResourceGraphDefinition
metadata:
name: webapp.kro.run
spec:
weight: 150
schema:
apiVersion: v1alpha1
kind: WebApp
Expand Down Expand Up @@ -68,7 +69,7 @@ spec:

- id: service
includeWhen:
- ${schema.spec.service.enabled}
- ${schema.spec.service.enabled}
template:
apiVersion: v1
kind: Service
Expand All @@ -86,7 +87,7 @@ spec:

- id: ingress
includeWhen:
- ${schema.spec.ingress.enabled}
- ${schema.spec.ingress.enabled}
template:
apiVersion: networking.k8s.io/v1
kind: Ingress
Expand Down
6 changes: 6 additions & 0 deletions helm/crds/kro.run_resourcegraphdefinitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ spec:
- apiVersion
- kind
type: object
weight:
default: 100
description: The weight used to determine priority when queuing reconciliation.
maximum: 1000
minimum: 1
type: integer
required:
- schema
type: object
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/instance/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ type ReconcileConfig struct {
// TODO(a-hilaly): need to define think the different deletion policies we need to
// support.
DeletionPolicy string

// Instance controller events are queued in a weighted queue.
Weight int
}

// Controller manages the reconciliation of a single instance of a ResourceGraphDefinition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (r *ResourceGraphDefinitionReconciler) reconcileResourceGraphDefinition(ctx
controller := r.setupMicroController(gvr, processedRGD, rgd.Spec.DefaultServiceAccounts, graphExecLabeler)

log.V(1).Info("reconciling resource graph definition micro controller")
if err := r.reconcileResourceGraphDefinitionMicroController(ctx, &gvr, controller.Reconcile); err != nil {
if err := r.reconcileResourceGraphDefinitionMicroController(ctx, &gvr, controller.Reconcile, rgd.Spec.Weight); err != nil {
return processedRGD.TopologicalOrder, resourcesInfo, err
}

Expand Down Expand Up @@ -141,8 +141,8 @@ func (r *ResourceGraphDefinitionReconciler) reconcileResourceGraphDefinitionCRD(
}

// reconcileResourceGraphDefinitionMicroController starts the microcontroller for handling the resources
func (r *ResourceGraphDefinitionReconciler) reconcileResourceGraphDefinitionMicroController(ctx context.Context, gvr *schema.GroupVersionResource, handler dynamiccontroller.Handler) error {
err := r.dynamicController.StartServingGVK(ctx, *gvr, handler)
func (r *ResourceGraphDefinitionReconciler) reconcileResourceGraphDefinitionMicroController(ctx context.Context, gvr *schema.GroupVersionResource, handler dynamiccontroller.Handler, weight int) error {
err := r.dynamicController.StartServingGVK(ctx, *gvr, handler, weight)
if err != nil {
return newMicroControllerError(err)
}
Expand Down
Loading
Loading