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

[TK-1897] Fix behavior attribute of kubernetes_horizontal_pod_autoscaler_v2(beta2) #1853

Merged
merged 2 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 23 additions & 0 deletions .changelog/1853.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
```release-note:enhancement
r/kubernetes_horizontal_pod_autoscaler_v2: make attribute `spec.behavior` computed
```

```release-note:enhancement
r/kubernetes_horizontal_pod_autoscaler_v2: make attribute `spec.behavior.scale_up` computed
```

```release-note:enhancement
r/kubernetes_horizontal_pod_autoscaler_v2: make attribute `spec.behavior.scale_down` computed
```

```release-note:enhancement
r/kubernetes_horizontal_pod_autoscaler_v2beta2: make attribute `spec.behavior` computed
```

```release-note:enhancement
r/kubernetes_horizontal_pod_autoscaler_v2beta2: make attribute `spec.behavior.scale_up` computed
```

```release-note:enhancement
r/kubernetes_horizontal_pod_autoscaler_v2beta2: make attribute `spec.behavior.scale_down` computed
```
93 changes: 5 additions & 88 deletions kubernetes/resource_kubernetes_horizontal_pod_autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
api "k8s.io/api/autoscaling/v1"
autoscalingv1 "k8s.io/api/autoscaling/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkgApi "k8s.io/apimachinery/pkg/types"
Expand All @@ -22,90 +22,7 @@ func resourceKubernetesHorizontalPodAutoscaler() *schema.Resource {
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Schema: map[string]*schema.Schema{
"metadata": namespacedMetadataSchema("horizontal pod autoscaler", true),
"spec": {
Type: schema.TypeList,
Description: "Behaviour of the autoscaler. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status",
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"max_replicas": {
Type: schema.TypeInt,
Description: "Upper limit for the number of pods that can be set by the autoscaler.",
Required: true,
},
"metric": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Description: "The specifications for which to use to calculate the desired replica count (the maximum replica count across all metrics will be used). The desired replica count is calculated multiplying the ratio between the target value and the current value by the current number of pods. Ergo, metrics used must decrease as the pod count is increased, and vice-versa. See the individual metric source types for more information about how each type of metric must respond. If not set, the default metric will be set to 80% average CPU utilization.",
Elem: metricSpecFields(),
},
"min_replicas": {
Type: schema.TypeInt,
Description: "Lower limit for the number of pods that can be set by the autoscaler, defaults to `1`.",
Optional: true,
Default: 1,
},
"behavior": {
Type: schema.TypeList,
Description: "Behavior configures the scaling behavior of the target in both Up and Down directions (scale_up and scale_down fields respectively).",
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"scale_up": {
Type: schema.TypeList,
Description: "Scaling policy for scaling Up",
Optional: true,
Elem: scalingRulesSpecFields(),
},
"scale_down": {
Type: schema.TypeList,
Description: "Scaling policy for scaling Down",
Optional: true,
Elem: scalingRulesSpecFields(),
},
},
},
},
"scale_target_ref": {
Type: schema.TypeList,
Description: "Reference to scaled resource. e.g. Replication Controller",
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"api_version": {
Type: schema.TypeString,
Description: "API version of the referent",
Optional: true,
},
"kind": {
Type: schema.TypeString,
Description: "Kind of the referent. e.g. `ReplicationController`. More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds",
Required: true,
},
"name": {
Type: schema.TypeString,
Description: "Name of the referent. More info: http://kubernetes.io/docs/user-guide/identifiers#names",
Required: true,
},
},
},
},
"target_cpu_utilization_percentage": {
Type: schema.TypeInt,
Description: "Target average CPU utilization (represented as a percentage of requested CPU) over all the pods. If not specified the default autoscaling policy will be used.",
Optional: true,
Computed: true,
},
},
},
},
},
Schema: horizontalPodAutoscalerSchemaV2(),
}
}

Expand All @@ -125,12 +42,12 @@ func resourceKubernetesHorizontalPodAutoscalerCreate(ctx context.Context, d *sch
return diag.FromErr(err)
}

svc := api.HorizontalPodAutoscaler{
hpa := autoscalingv1.HorizontalPodAutoscaler{
ObjectMeta: metadata,
Spec: *spec,
}
log.Printf("[INFO] Creating new horizontal pod autoscaler: %#v", svc)
out, err := conn.AutoscalingV1().HorizontalPodAutoscalers(metadata.Namespace).Create(ctx, &svc, metav1.CreateOptions{})
log.Printf("[INFO] Creating new horizontal pod autoscaler: %#v", hpa)
out, err := conn.AutoscalingV1().HorizontalPodAutoscalers(metadata.Namespace).Create(ctx, &hpa, metav1.CreateOptions{})
if err != nil {
return diag.FromErr(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

api "k8s.io/api/autoscaling/v1"
autoscalingv1 "k8s.io/api/autoscaling/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkgApi "k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -92,12 +92,12 @@ func resourceKubernetesHorizontalPodAutoscalerV1Create(ctx context.Context, d *s
return diag.FromErr(err)
}

svc := api.HorizontalPodAutoscaler{
hpa := autoscalingv1.HorizontalPodAutoscaler{
ObjectMeta: metadata,
Spec: *spec,
}
log.Printf("[INFO] Creating new horizontal pod autoscaler: %#v", svc)
out, err := conn.AutoscalingV1().HorizontalPodAutoscalers(metadata.Namespace).Create(ctx, &svc, metav1.CreateOptions{})
log.Printf("[INFO] Creating new horizontal pod autoscaler: %#v", hpa)
out, err := conn.AutoscalingV1().HorizontalPodAutoscalers(metadata.Namespace).Create(ctx, &hpa, metav1.CreateOptions{})
if err != nil {
return diag.FromErr(err)
}
Expand Down
85 changes: 1 addition & 84 deletions kubernetes/resource_kubernetes_horizontal_pod_autoscaler_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,90 +23,7 @@ func resourceKubernetesHorizontalPodAutoscalerV2() *schema.Resource {
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Schema: map[string]*schema.Schema{
"metadata": namespacedMetadataSchema("horizontal pod autoscaler", true),
"spec": {
Type: schema.TypeList,
Description: "Behaviour of the autoscaler. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status",
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"max_replicas": {
Type: schema.TypeInt,
Description: "Upper limit for the number of pods that can be set by the autoscaler.",
Required: true,
},
"metric": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Description: "The specifications for which to use to calculate the desired replica count (the maximum replica count across all metrics will be used). The desired replica count is calculated multiplying the ratio between the target value and the current value by the current number of pods. Ergo, metrics used must decrease as the pod count is increased, and vice-versa. See the individual metric source types for more information about how each type of metric must respond. If not set, the default metric will be set to 80% average CPU utilization.",
Elem: metricSpecFields(),
},
"min_replicas": {
Type: schema.TypeInt,
Description: "Lower limit for the number of pods that can be set by the autoscaler, defaults to `1`.",
Optional: true,
Default: 1,
},
"behavior": {
Type: schema.TypeList,
Description: "Behavior configures the scaling behavior of the target in both Up and Down directions (scale_up and scale_down fields respectively).",
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"scale_up": {
Type: schema.TypeList,
Description: "Scaling policy for scaling Up",
Optional: true,
Elem: scalingRulesSpecFields(),
},
"scale_down": {
Type: schema.TypeList,
Description: "Scaling policy for scaling Down",
Optional: true,
Elem: scalingRulesSpecFields(),
},
},
},
},
"scale_target_ref": {
Type: schema.TypeList,
Description: "Reference to scaled resource. e.g. Replication Controller",
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"api_version": {
Type: schema.TypeString,
Description: "API version of the referent",
Optional: true,
},
"kind": {
Type: schema.TypeString,
Description: "Kind of the referent. e.g. `ReplicationController`. More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds",
Required: true,
},
"name": {
Type: schema.TypeString,
Description: "Name of the referent. More info: http://kubernetes.io/docs/user-guide/identifiers#names",
Required: true,
},
},
},
},
"target_cpu_utilization_percentage": {
Type: schema.TypeInt,
Description: "Target average CPU utilization (represented as a percentage of requested CPU) over all the pods. If not specified the default autoscaling policy will be used.",
Optional: true,
Computed: true,
},
},
},
},
},
Schema: horizontalPodAutoscalerSchemaV2(),
}
}

Expand Down
Loading