Skip to content

Commit

Permalink
Fix 'behavior' attribute of 'kubernetes_horizontal_pod_autoscaler_v2(…
Browse files Browse the repository at this point in the history
…beta2)'
  • Loading branch information
arybolovlev committed Oct 4, 2022
1 parent b466fb5 commit 81ddc37
Show file tree
Hide file tree
Showing 9 changed files with 408 additions and 431 deletions.
90 changes: 5 additions & 85 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 @@ -24,87 +24,7 @@ func resourceKubernetesHorizontalPodAutoscaler() *schema.Resource {
},
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,
},
},
},
},
"spec": horizontalPodAutoscalerSpecV2(),
},
}
}
Expand All @@ -125,12 +45,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
82 changes: 1 addition & 81 deletions kubernetes/resource_kubernetes_horizontal_pod_autoscaler_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,87 +25,7 @@ func resourceKubernetesHorizontalPodAutoscalerV2() *schema.Resource {
},
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,
},
},
},
},
"spec": horizontalPodAutoscalerSpecV2(),
},
}
}
Expand Down

0 comments on commit 81ddc37

Please sign in to comment.