Skip to content

Commit b3998f3

Browse files
authored
Fix behavior attribute of kubernetes_horizontal_pod_autoscaler_v2(beta2) (#1853)
1 parent d0a8f2c commit b3998f3

10 files changed

+434
-440
lines changed

.changelog/1853.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
```release-note:enhancement
2+
r/kubernetes_horizontal_pod_autoscaler_v2: make attribute `spec.behavior` computed
3+
```
4+
5+
```release-note:enhancement
6+
r/kubernetes_horizontal_pod_autoscaler_v2: make attribute `spec.behavior.scale_up` computed
7+
```
8+
9+
```release-note:enhancement
10+
r/kubernetes_horizontal_pod_autoscaler_v2: make attribute `spec.behavior.scale_down` computed
11+
```
12+
13+
```release-note:enhancement
14+
r/kubernetes_horizontal_pod_autoscaler_v2beta2: make attribute `spec.behavior` computed
15+
```
16+
17+
```release-note:enhancement
18+
r/kubernetes_horizontal_pod_autoscaler_v2beta2: make attribute `spec.behavior.scale_up` computed
19+
```
20+
21+
```release-note:enhancement
22+
r/kubernetes_horizontal_pod_autoscaler_v2beta2: make attribute `spec.behavior.scale_down` computed
23+
```

kubernetes/resource_kubernetes_horizontal_pod_autoscaler.go

Lines changed: 5 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
88

99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10-
api "k8s.io/api/autoscaling/v1"
10+
autoscalingv1 "k8s.io/api/autoscaling/v1"
1111
"k8s.io/apimachinery/pkg/api/errors"
1212
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1313
pkgApi "k8s.io/apimachinery/pkg/types"
@@ -22,90 +22,7 @@ func resourceKubernetesHorizontalPodAutoscaler() *schema.Resource {
2222
Importer: &schema.ResourceImporter{
2323
StateContext: schema.ImportStatePassthroughContext,
2424
},
25-
Schema: map[string]*schema.Schema{
26-
"metadata": namespacedMetadataSchema("horizontal pod autoscaler", true),
27-
"spec": {
28-
Type: schema.TypeList,
29-
Description: "Behaviour of the autoscaler. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status",
30-
Required: true,
31-
MaxItems: 1,
32-
Elem: &schema.Resource{
33-
Schema: map[string]*schema.Schema{
34-
"max_replicas": {
35-
Type: schema.TypeInt,
36-
Description: "Upper limit for the number of pods that can be set by the autoscaler.",
37-
Required: true,
38-
},
39-
"metric": {
40-
Type: schema.TypeList,
41-
Computed: true,
42-
Optional: true,
43-
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.",
44-
Elem: metricSpecFields(),
45-
},
46-
"min_replicas": {
47-
Type: schema.TypeInt,
48-
Description: "Lower limit for the number of pods that can be set by the autoscaler, defaults to `1`.",
49-
Optional: true,
50-
Default: 1,
51-
},
52-
"behavior": {
53-
Type: schema.TypeList,
54-
Description: "Behavior configures the scaling behavior of the target in both Up and Down directions (scale_up and scale_down fields respectively).",
55-
Optional: true,
56-
MaxItems: 1,
57-
Elem: &schema.Resource{
58-
Schema: map[string]*schema.Schema{
59-
"scale_up": {
60-
Type: schema.TypeList,
61-
Description: "Scaling policy for scaling Up",
62-
Optional: true,
63-
Elem: scalingRulesSpecFields(),
64-
},
65-
"scale_down": {
66-
Type: schema.TypeList,
67-
Description: "Scaling policy for scaling Down",
68-
Optional: true,
69-
Elem: scalingRulesSpecFields(),
70-
},
71-
},
72-
},
73-
},
74-
"scale_target_ref": {
75-
Type: schema.TypeList,
76-
Description: "Reference to scaled resource. e.g. Replication Controller",
77-
Required: true,
78-
MaxItems: 1,
79-
Elem: &schema.Resource{
80-
Schema: map[string]*schema.Schema{
81-
"api_version": {
82-
Type: schema.TypeString,
83-
Description: "API version of the referent",
84-
Optional: true,
85-
},
86-
"kind": {
87-
Type: schema.TypeString,
88-
Description: "Kind of the referent. e.g. `ReplicationController`. More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds",
89-
Required: true,
90-
},
91-
"name": {
92-
Type: schema.TypeString,
93-
Description: "Name of the referent. More info: http://kubernetes.io/docs/user-guide/identifiers#names",
94-
Required: true,
95-
},
96-
},
97-
},
98-
},
99-
"target_cpu_utilization_percentage": {
100-
Type: schema.TypeInt,
101-
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.",
102-
Optional: true,
103-
Computed: true,
104-
},
105-
},
106-
},
107-
},
108-
},
25+
Schema: horizontalPodAutoscalerSchemaV2(),
10926
}
11027
}
11128

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

128-
svc := api.HorizontalPodAutoscaler{
45+
hpa := autoscalingv1.HorizontalPodAutoscaler{
12946
ObjectMeta: metadata,
13047
Spec: *spec,
13148
}
132-
log.Printf("[INFO] Creating new horizontal pod autoscaler: %#v", svc)
133-
out, err := conn.AutoscalingV1().HorizontalPodAutoscalers(metadata.Namespace).Create(ctx, &svc, metav1.CreateOptions{})
49+
log.Printf("[INFO] Creating new horizontal pod autoscaler: %#v", hpa)
50+
out, err := conn.AutoscalingV1().HorizontalPodAutoscalers(metadata.Namespace).Create(ctx, &hpa, metav1.CreateOptions{})
13451
if err != nil {
13552
return diag.FromErr(err)
13653
}

kubernetes/resource_kubernetes_horizontal_pod_autoscaler_v1.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
99

10-
api "k8s.io/api/autoscaling/v1"
10+
autoscalingv1 "k8s.io/api/autoscaling/v1"
1111
"k8s.io/apimachinery/pkg/api/errors"
1212
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1313
pkgApi "k8s.io/apimachinery/pkg/types"
@@ -92,12 +92,12 @@ func resourceKubernetesHorizontalPodAutoscalerV1Create(ctx context.Context, d *s
9292
return diag.FromErr(err)
9393
}
9494

95-
svc := api.HorizontalPodAutoscaler{
95+
hpa := autoscalingv1.HorizontalPodAutoscaler{
9696
ObjectMeta: metadata,
9797
Spec: *spec,
9898
}
99-
log.Printf("[INFO] Creating new horizontal pod autoscaler: %#v", svc)
100-
out, err := conn.AutoscalingV1().HorizontalPodAutoscalers(metadata.Namespace).Create(ctx, &svc, metav1.CreateOptions{})
99+
log.Printf("[INFO] Creating new horizontal pod autoscaler: %#v", hpa)
100+
out, err := conn.AutoscalingV1().HorizontalPodAutoscalers(metadata.Namespace).Create(ctx, &hpa, metav1.CreateOptions{})
101101
if err != nil {
102102
return diag.FromErr(err)
103103
}

kubernetes/resource_kubernetes_horizontal_pod_autoscaler_v2.go

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -23,90 +23,7 @@ func resourceKubernetesHorizontalPodAutoscalerV2() *schema.Resource {
2323
Importer: &schema.ResourceImporter{
2424
StateContext: schema.ImportStatePassthroughContext,
2525
},
26-
Schema: map[string]*schema.Schema{
27-
"metadata": namespacedMetadataSchema("horizontal pod autoscaler", true),
28-
"spec": {
29-
Type: schema.TypeList,
30-
Description: "Behaviour of the autoscaler. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status",
31-
Required: true,
32-
MaxItems: 1,
33-
Elem: &schema.Resource{
34-
Schema: map[string]*schema.Schema{
35-
"max_replicas": {
36-
Type: schema.TypeInt,
37-
Description: "Upper limit for the number of pods that can be set by the autoscaler.",
38-
Required: true,
39-
},
40-
"metric": {
41-
Type: schema.TypeList,
42-
Computed: true,
43-
Optional: true,
44-
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.",
45-
Elem: metricSpecFields(),
46-
},
47-
"min_replicas": {
48-
Type: schema.TypeInt,
49-
Description: "Lower limit for the number of pods that can be set by the autoscaler, defaults to `1`.",
50-
Optional: true,
51-
Default: 1,
52-
},
53-
"behavior": {
54-
Type: schema.TypeList,
55-
Description: "Behavior configures the scaling behavior of the target in both Up and Down directions (scale_up and scale_down fields respectively).",
56-
Optional: true,
57-
MaxItems: 1,
58-
Elem: &schema.Resource{
59-
Schema: map[string]*schema.Schema{
60-
"scale_up": {
61-
Type: schema.TypeList,
62-
Description: "Scaling policy for scaling Up",
63-
Optional: true,
64-
Elem: scalingRulesSpecFields(),
65-
},
66-
"scale_down": {
67-
Type: schema.TypeList,
68-
Description: "Scaling policy for scaling Down",
69-
Optional: true,
70-
Elem: scalingRulesSpecFields(),
71-
},
72-
},
73-
},
74-
},
75-
"scale_target_ref": {
76-
Type: schema.TypeList,
77-
Description: "Reference to scaled resource. e.g. Replication Controller",
78-
Required: true,
79-
MaxItems: 1,
80-
Elem: &schema.Resource{
81-
Schema: map[string]*schema.Schema{
82-
"api_version": {
83-
Type: schema.TypeString,
84-
Description: "API version of the referent",
85-
Optional: true,
86-
},
87-
"kind": {
88-
Type: schema.TypeString,
89-
Description: "Kind of the referent. e.g. `ReplicationController`. More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds",
90-
Required: true,
91-
},
92-
"name": {
93-
Type: schema.TypeString,
94-
Description: "Name of the referent. More info: http://kubernetes.io/docs/user-guide/identifiers#names",
95-
Required: true,
96-
},
97-
},
98-
},
99-
},
100-
"target_cpu_utilization_percentage": {
101-
Type: schema.TypeInt,
102-
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.",
103-
Optional: true,
104-
Computed: true,
105-
},
106-
},
107-
},
108-
},
109-
},
26+
Schema: horizontalPodAutoscalerSchemaV2(),
11027
}
11128
}
11229

0 commit comments

Comments
 (0)