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

Apply fails when hpa metric type was changed in the cluster #2641

Open
shysank opened this issue Dec 6, 2024 · 2 comments
Open

Apply fails when hpa metric type was changed in the cluster #2641

shysank opened this issue Dec 6, 2024 · 2 comments
Assignees
Labels

Comments

@shysank
Copy link

shysank commented Dec 6, 2024

Terraform Version, Provider Version and Kubernetes Version

Terraform version: 1.7.5
Kubernetes provider version: 2.31.0
Kubernetes version: 1.28

Affected Resource(s)

  • kuberenetes_manifest

Terraform Configuration Files

resource "kubernetes_manifest" "hpa" {
  manifest        = yamldecode(file("path_to_hpa"))
  field_manager {
    force_conflicts = true
  }
}

Debug Output

Panic Output

Steps to Reproduce

  1. Add a kuberetnes hpa manifest with cpu metric as a kuberetes_manifest resource
    Eg.
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
...
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          averageUtilization: 80
          type: Utilization 
  1. Update the hpa directly in the cluster using kubectl edit to something like (note: target:)
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          averageValue: 100m
          type: AverageValue 
  1. terraform apply

Expected Behavior

It should override the hpa with the configured spec in kuberenetes_manifest resource

Actual Behavior

Apply failed with the following error

╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to
│ module.service.kubernetes_manifest.service_components["autoscale.yaml"],
│ provider "provider[\"registry.terraform.io/hashicorp/kubernetes\"]"
│ produced an unexpected new value:
│ .object.spec.metrics[1].resource.target.type: was
│ cty.StringVal("Utilization"), but now cty.StringVal("AverageValue").
│ 
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker

Important Factoids

References

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@yashrajdighe
Copy link

│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to
│ kubernetes_manifest.deployment_kafka_strimzi_cluster_operator, provider
│ "provider[\"registry.terraform.io/hashicorp/kubernetes\"]" produced an
│ unexpected new value:
│ .object.spec.template.spec.containers[0].resources.limits["cpu"]: was
│ cty.StringVal("1000m"), but now cty.StringVal("1").
│ 
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.

Faced a similar issue.

@shysank
Copy link
Author

shysank commented Jan 2, 2025

Adding computed_fields resolved the original issue but a similar issue happened if the CPU target utilization was changed.

Steps to Reproduce

  1. Repeat the original issue with computed_fields = ["metadata.annotations", "metadata.labels", "spec.metrics"]
  2. Update spec.metrics[0].target. averageUtilization = 70
  3. terraform plan
  4. terraform apply

Expected Behavior
It should override the hpa with the configured spec in kuberenetes_manifest resource

Actual Behavior
Apply failed with the following error

╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to
│ module.service.kubernetes_manifest.service_components["autoscale.yaml"],
│ provider "provider[\"registry.terraform.io/hashicorp/kubernetes\"]"
│ produced an unexpected new value:
│ .object.metadata.annotations["analysis.scaleops.io/original-metrics"]: was
│ cty.StringVal("[{\"type\":\"Resource\",\"resource\":{\"name\":\"cpu\",\"target\":{\"type\":\"Utilization\",\"averageUtilization\":55}}},{\"type\":\"Pods\",\"pods\":{\"metric\":{\"name\":\"istio_requests_pod_per_second\"},\"target\":{\"type\":\"AverageValue\",\"averageValue\":\"300\"}}}]"),
│ but now
│ cty.StringVal("[{\"type\":\"Resource\",\"resource\":{\"name\":\"cpu\",\"target\":{\"type\":\"Utilization\",\"averageUtilization\":58}}},{\"type\":\"Pods\",\"pods\":{\"metric\":{\"name\":\"istio_requests_pod_per_second\"},\"target\":{\"type\":\"AverageValue\",\"averageValue\":\"300\"}}}]").
│ 
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.
╵

Note: The changes get applied. Running terraform plan again shows no infrastructure changes.

@alexsomesan Whenever you get a chance, it'd be great if you can share some thoughts on this. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants