Skip to content

Propagate custom labels from Tortoise to HPA/VPA managed by Tortoise #430

@minhthong582000

Description

@minhthong582000

I would like Tortoise to propagate its resource labels to the HPA and VPA it creates.

Why

Tortoise should keep labels consistent across all Kubernetes resources, which allows us to attribute resources by teams or projects, or manage logical links between resources.This also help us to have monitoring and reporting based on labels.

Current behavior

Tortoise does not currently propagate its labels to the HPA/VPA it creates, and any updates to Tortoise labels are not reflected in the HPA/VPA.

Expected behavior

For HPA:

  • When update mode is off, or no horizontal policy or user specified existing HPA, ignore the changes in labels. Otherwise...
  • Whenever Tortoise creates an HPA, it should propagate its labels to these child resources.
  • When a user updates the labels on a Tortoise resource, the same changes should be reflected in the HPA.

For VPA:

  • Whenever Tortoise creates an VPA, it should propagate its labels to these child resources.
  • When a user updates the labels on a Tortoise resource, the same changes should be reflected in the VPA.

Propose changes

In internal/controller/tortoise_controller, 2 new methods should be added within the HPA and VPA services to handle label propagation: UpdateHPALabelsFromTortoise and UpdateVPALabelsFromTortoise.

Some high level proposed code change:

func (r *TortoiseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) {
// ...

tortoise, err = r.HpaService.UpdateHPASpecFromTortoiseAutoscalingPolicy(ctx, tortoise, hpa, currentDesiredReplicaNum, now)
if err != nil {
	logger.Error(err, "update HPA spec from Tortoise autoscaling policy", "tortoise", req.NamespacedName)
	return ctrl.Result{}, err
}

// NEW: Update HPA labels to match Tortoise labels
// err = r.HpaService.UpdateHPALabelsFromTortoise(ctx, tortoise)
// if err != nil {
//	return ctrl.Result{}, err
//}

monitorvpa, vpaReady, err := r.VpaService.GetTortoiseMonitorVPA(ctx, tortoise)
if err != nil {
	logger.Error(err, "failed to get tortoise VPA", "tortoise", req.NamespacedName)
	return ctrl.Result{}, err
}

// NEW: Update VPA labels to match Tortoise labels
// _, err = r.VpaService.UpdateVPALabelsFromTorotise(ctx, tortoise)
// if err != nil {
// 	return ctrl.Result{}, err
// }

// ...

Also It would be great if team could assign this to me for the implementation.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions