← All recipes
Moderne licensed

Migrate HorizontalPodAutoscaler to autoscaling/v2

Recipe IDorg.openrewrite.kubernetes.migrate.MigrateHorizontalPodAutoscalerToV2Artifactorg.openrewrite.recipe:rewrite-kubernetes

Move HorizontalPodAutoscaler off the autoscaling beta APIs — v2beta1, removed in Kubernetes v1.25, and v2beta2, removed in v1.26 — onto autoscaling/v2, restructuring the metric targets v2beta1 wrote inline. v2beta2 is autoscaling/v2 under another name, so those resources only change version. A v2beta1 resource is rewritten the way the apiserver itself converted it: targetAverageUtilization becomes target.averageUtilization under target.type: Utilization and targetAverageValue becomes target.averageValue under target.type: AverageValue; metricName and its selector become the metric identifier; and for an object metric the target naming the described object becomes describedObject, freeing target for the metric target built from targetValue and averageValue. A metric that sets a combination autoscaling/v2 validation rejects — a resource metric targeting both a utilization and a raw value, or an external metric targeting both a total and a per-pod value — is left on its old API version and marked with the reason.

Single recipeProprietary

Usage

This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe org.openrewrite.kubernetes.migrate.MigrateHorizontalPodAutoscalerToV2

If the recipe isn’t available locally, install it with:

mod config recipes jar install org.openrewrite.recipe:rewrite-kubernetes:RELEASE

Options

NameTypeDescription
fileMatcherStringMatching files will be modified. This is a glob expression.
e.g. **/hpa-*.yml

Data tables

Structured output this recipe can produce.

  • Source files that had resultsSource files that were modified by the recipe run.org.openrewrite.table.SourcesFileResults
  • Source files that had search resultsSearch results that were found during the recipe run.org.openrewrite.table.SearchResults
  • Source files that errored on a recipeThe details of all errors produced by a recipe run.org.openrewrite.table.SourcesFileErrors
  • Recipe performanceStatistics used in analyzing the performance of recipes.org.openrewrite.table.RecipeRunStats