Skip to content

Commit

Permalink
Add pointerOf
Browse files Browse the repository at this point in the history
  • Loading branch information
arybolovlev committed Nov 27, 2023
1 parent 377558c commit d5c0666
Show file tree
Hide file tree
Showing 39 changed files with 236 additions and 224 deletions.
4 changes: 2 additions & 2 deletions kubernetes/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ func useAdmissionregistrationV1beta1(conn *kubernetes.Clientset) (bool, error) {
err = discovery.ServerSupportsVersion(d, v1)
if err == nil {
log.Printf("[INFO] Using %s/v1", group)
useadmissionregistrationv1beta1 = ptrToBool(false)
useadmissionregistrationv1beta1 = pointerOf(false)
return false, nil
}

Expand All @@ -655,7 +655,7 @@ func useAdmissionregistrationV1beta1(conn *kubernetes.Clientset) (bool, error) {
}

log.Printf("[INFO] Using %s/v1beta1", group)
useadmissionregistrationv1beta1 = ptrToBool(true)
useadmissionregistrationv1beta1 = pointerOf(true)
return true, nil
}

Expand Down
2 changes: 1 addition & 1 deletion kubernetes/resource_kubernetes_annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func resourceKubernetesAnnotationsUpdate(ctx context.Context, d *schema.Resource
patchbytes,
v1.PatchOptions{
FieldManager: d.Get("field_manager").(string),
Force: ptrToBool(d.Get("force").(bool)),
Force: pointerOf(d.Get("force").(bool)),
},
)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/resource_kubernetes_config_map_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func resourceKubernetesConfigMapV1Create(ctx context.Context, d *schema.Resource
ObjectMeta: metadata,
BinaryData: expandBase64MapToByteMap(d.Get("binary_data").(map[string]interface{})),
Data: expandStringMap(d.Get("data").(map[string]interface{})),
Immutable: ptrToBool(d.Get("immutable").(bool)),
Immutable: pointerOf(d.Get("immutable").(bool)),
}

log.Printf("[INFO] Creating new config map: %#v", cfgMap)
Expand Down Expand Up @@ -160,7 +160,7 @@ func resourceKubernetesConfigMapV1Update(ctx context.Context, d *schema.Resource
if d.HasChange("immutable") {
ops = append(ops, &ReplaceOperation{
Path: "/immutable",
Value: ptrToBool(d.Get("immutable").(bool)),
Value: pointerOf(d.Get("immutable").(bool)),
})
}

Expand Down
2 changes: 1 addition & 1 deletion kubernetes/resource_kubernetes_config_map_v1_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func resourceKubernetesConfigMapV1DataUpdate(ctx context.Context, d *schema.Reso
patchbytes,
v1.PatchOptions{
FieldManager: d.Get("field_manager").(string),
Force: ptrToBool(d.Get("force").(bool)),
Force: pointerOf(d.Get("force").(bool)),
},
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/resource_kubernetes_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ func resourceKubernetesEnvUpdate(ctx context.Context, d *schema.ResourceData, m
patchbytes,
v1.PatchOptions{
FieldManager: d.Get("field_manager").(string),
Force: ptrToBool(d.Get("force").(bool)),
Force: pointerOf(d.Get("force").(bool)),
},
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/resource_kubernetes_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func resourceKubernetesLabelsUpdate(ctx context.Context, d *schema.ResourceData,
patchbytes,
v1.PatchOptions{
FieldManager: d.Get("field_manager").(string),
Force: ptrToBool(d.Get("force").(bool)),
Force: pointerOf(d.Get("force").(bool)),
},
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/resource_kubernetes_node_taint.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func resourceKubernetesNodeTaintUpdate(ctx context.Context, d *schema.ResourceDa
}
patchOpts := metav1.PatchOptions{
FieldManager: d.Get("field_manager").(string),
Force: ptrToBool(d.Get("force").(bool)),
Force: pointerOf(d.Get("force").(bool)),
}
node, err := nodeApi.Patch(ctx, nodeName, types.ApplyPatchType, patchBytes, patchOpts)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/resource_kubernetes_secret_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func resourceKubernetesSecretV1Create(ctx context.Context, d *schema.ResourceDat
}

if v, ok := d.GetOkExists("immutable"); ok {
secret.Immutable = ptrToBool(v.(bool))
secret.Immutable = pointerOf(v.(bool))
}

log.Printf("[INFO] Creating new secret: %#v", secret)
Expand Down Expand Up @@ -268,7 +268,7 @@ func resourceKubernetesSecretV1Update(ctx context.Context, d *schema.ResourceDat
if d.HasChange("immutable") {
ops = append(ops, &ReplaceOperation{
Path: "/immutable",
Value: ptrToBool(d.Get("immutable").(bool)),
Value: pointerOf(d.Get("immutable").(bool)),
})
}

Expand Down
2 changes: 1 addition & 1 deletion kubernetes/resource_kubernetes_service_account_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func resourceKubernetesServiceAccountV1Create(ctx context.Context, d *schema.Res

metadata := expandMetadata(d.Get("metadata").([]interface{}))
svcAcc := corev1.ServiceAccount{
AutomountServiceAccountToken: ptrToBool(d.Get("automount_service_account_token").(bool)),
AutomountServiceAccountToken: pointerOf(d.Get("automount_service_account_token").(bool)),
ObjectMeta: metadata,
ImagePullSecrets: expandLocalObjectReferenceArray(d.Get("image_pull_secret").(*schema.Set).List()),
Secrets: expandServiceAccountSecrets(d.Get("secret").(*schema.Set).List(), ""),
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/resource_kubernetes_service_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,14 +504,14 @@ func TestAccKubernetesServiceV1_nodePort(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "spec.0.type", "NodePort"),
testAccCheckServiceV1Ports(&conf, []corev1.ServicePort{
{
AppProtocol: ptrToString("ssh"),
AppProtocol: pointerOf("ssh"),
Name: "first",
Port: int32(10222),
Protocol: corev1.ProtocolTCP,
TargetPort: intstr.FromInt(22),
},
{
AppProtocol: ptrToString("terraform.io/kubernetes"),
AppProtocol: pointerOf("terraform.io/kubernetes"),
Name: "second",
Port: int32(10333),
Protocol: corev1.ProtocolTCP,
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/structure_api_service_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func expandAPIServiceV1Spec(l []interface{}) v1.APIServiceSpec {
}

if v, ok := m["port"].(int); ok && v > 0 {
obj.Service.Port = ptrToInt32(int32(v))
obj.Service.Port = pointerOf(int32(v))
}
}
if v, ok := in["version"].(string); ok {
Expand Down
8 changes: 4 additions & 4 deletions kubernetes/structure_cron_job_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func expandCronJobSpecV1(j []interface{}) (batch.CronJobSpec, error) {
}

if v, ok := in["failed_jobs_history_limit"].(int); ok && v != 1 {
obj.FailedJobsHistoryLimit = ptrToInt32(int32(v))
obj.FailedJobsHistoryLimit = pointerOf(int32(v))
}

if v, ok := in["schedule"].(string); ok && v != "" {
Expand All @@ -87,15 +87,15 @@ func expandCronJobSpecV1(j []interface{}) (batch.CronJobSpec, error) {
obj.JobTemplate = jtSpec

if v, ok := in["starting_deadline_seconds"].(int); ok && v > 0 {
obj.StartingDeadlineSeconds = ptrToInt64(int64(v))
obj.StartingDeadlineSeconds = pointerOf(int64(v))
}

if v, ok := in["successful_jobs_history_limit"].(int); ok && v != 3 {
obj.SuccessfulJobsHistoryLimit = ptrToInt32(int32(v))
obj.SuccessfulJobsHistoryLimit = pointerOf(int32(v))
}

if v, ok := in["suspend"].(bool); ok {
obj.Suspend = ptrToBool(v)
obj.Suspend = pointerOf(v)
}

return obj, nil
Expand Down
8 changes: 4 additions & 4 deletions kubernetes/structure_cron_job_v1beta1.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func expandCronJobSpecV1Beta1(j []interface{}) (v1beta1.CronJobSpec, error) {
}

if v, ok := in["failed_jobs_history_limit"].(int); ok && v != 1 {
obj.FailedJobsHistoryLimit = ptrToInt32(int32(v))
obj.FailedJobsHistoryLimit = pointerOf(int32(v))
}

if v, ok := in["schedule"].(string); ok && v != "" {
Expand All @@ -80,15 +80,15 @@ func expandCronJobSpecV1Beta1(j []interface{}) (v1beta1.CronJobSpec, error) {
obj.JobTemplate = jtSpec

if v, ok := in["starting_deadline_seconds"].(int); ok && v > 0 {
obj.StartingDeadlineSeconds = ptrToInt64(int64(v))
obj.StartingDeadlineSeconds = pointerOf(int64(v))
}

if v, ok := in["successful_jobs_history_limit"].(int); ok && v != 3 {
obj.SuccessfulJobsHistoryLimit = ptrToInt32(int32(v))
obj.SuccessfulJobsHistoryLimit = pointerOf(int32(v))
}

if v, ok := in["suspend"].(bool); ok {
obj.Suspend = ptrToBool(v)
obj.Suspend = pointerOf(v)
}

return obj, nil
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/structure_csi_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ func expandCSIDriverSpec(l []interface{}) storage.CSIDriverSpec {
obj := storage.CSIDriverSpec{}

if v, ok := in["attach_required"].(bool); ok {
obj.AttachRequired = ptrToBool(v)
obj.AttachRequired = pointerOf(v)
}

if v, ok := in["pod_info_on_mount"].(bool); ok {
obj.PodInfoOnMount = ptrToBool(v)
obj.PodInfoOnMount = pointerOf(v)
}

if v, ok := in["volume_lifecycle_modes"].([]interface{}); ok && len(v) > 0 {
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/structure_csi_driver_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ func expandCSIDriverV1Spec(l []interface{}) storage.CSIDriverSpec {
obj := storage.CSIDriverSpec{}

if v, ok := in["attach_required"].(bool); ok {
obj.AttachRequired = ptrToBool(v)
obj.AttachRequired = pointerOf(v)
}

if v, ok := in["pod_info_on_mount"].(bool); ok {
obj.PodInfoOnMount = ptrToBool(v)
obj.PodInfoOnMount = pointerOf(v)
}

if v, ok := in["volume_lifecycle_modes"].([]interface{}); ok && len(v) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/structure_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func expandEndpointsAddresses(in *schema.Set) []api.EndpointAddress {
r.IP = v
}
if v, ok := addrCfg["node_name"].(string); ok && v != "" {
r.NodeName = ptrToString(v)
r.NodeName = pointerOf(v)
}
addresses[i] = r
}
Expand Down
18 changes: 9 additions & 9 deletions kubernetes/structure_endpointslice.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ func expandEndpointSliceEndpoints(in []interface{}) []api.Endpoint {
r.Conditions = expandEndpointSliceConditions(v)
}
if v, ok := endpointConfig["hostname"].(string); ok && v != "" {
r.Hostname = ptrToString(v)
r.Hostname = pointerOf(v)
}
if v, ok := endpointConfig["node_name"].(string); ok && v != "" {
r.NodeName = ptrToString(v)
r.NodeName = pointerOf(v)
}
if v, ok := endpointConfig["target_ref"].([]interface{}); ok && len(v) != 0 {
r.TargetRef = expandObjectReference(v)
}
if v, ok := endpointConfig["zone"].(string); ok && v != "" {
r.Zone = ptrToString(v)
r.Zone = pointerOf(v)
}

endpoints[i] = r
Expand Down Expand Up @@ -78,20 +78,20 @@ func expandEndpointSlicePorts(in []interface{}) []api.EndpointPort {
r := api.EndpointPort{}
portCfg := port.(map[string]interface{})
if v, ok := portCfg["name"].(string); ok {
r.Name = ptrToString(v)
r.Name = pointerOf(v)
}
if v, ok := portCfg["port"].(string); ok {
if v == "" {
continue
}
v, _ := strconv.ParseInt(v, 10, 32)
r.Port = ptrToInt32(int32(v))
r.Port = pointerOf(int32(v))
}
if v, ok := portCfg["protocol"].(v1.Protocol); ok {
r.Protocol = &v
}
if v, ok := portCfg["app_protocol"].(string); ok {
r.AppProtocol = ptrToString(v)
r.AppProtocol = pointerOf(v)
}
ports[i] = r
}
Expand All @@ -107,13 +107,13 @@ func expandEndpointSliceConditions(in []interface{}) api.EndpointConditions {
cond := in[0].(map[string]interface{})

if v, ok := cond["ready"].(bool); ok {
obj.Ready = ptrToBool(v)
obj.Ready = pointerOf(v)
}
if v, ok := cond["serving"].(bool); ok {
obj.Serving = ptrToBool(v)
obj.Serving = pointerOf(v)
}
if v, ok := cond["terminating"].(bool); ok {
obj.Terminating = ptrToBool(v)
obj.Terminating = pointerOf(v)
}

return obj
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/structure_horizontal_pod_autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ func expandHorizontalPodAutoscalerSpec(in []interface{}) (*api.HorizontalPodAuto
spec.MaxReplicas = int32(v.(int))
}
if v, ok := m["min_replicas"].(int); ok && v > 0 {
spec.MinReplicas = ptrToInt32(int32(v))
spec.MinReplicas = pointerOf(int32(v))
}
if v, ok := m["scale_target_ref"]; ok {
spec.ScaleTargetRef = expandCrossVersionObjectReference(v.([]interface{}))
}
if v, ok := m["target_cpu_utilization_percentage"].(int); ok && v > 0 {
spec.TargetCPUUtilizationPercentage = ptrToInt32(int32(v))
spec.TargetCPUUtilizationPercentage = pointerOf(int32(v))
}

return spec, nil
Expand Down
6 changes: 3 additions & 3 deletions kubernetes/structure_horizontal_pod_autoscaler_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func expandHorizontalPodAutoscalerV2Spec(in []interface{}) (*autoscalingv2.Horiz
}

if v, ok := m["min_replicas"].(int); ok && v > 0 {
spec.MinReplicas = ptrToInt32(int32(v))
spec.MinReplicas = pointerOf(int32(v))
}

if v, ok := m["scale_target_ref"]; ok {
Expand Down Expand Up @@ -68,7 +68,7 @@ func expandV2MetricTarget(m map[string]interface{}) autoscalingv2.MetricTarget {
}
case autoscalingv2.UtilizationMetricType:
if v, ok := m["average_utilization"].(int); ok && v > 0 {
target.AverageUtilization = ptrToInt32(int32(v))
target.AverageUtilization = pointerOf(int32(v))
}
case autoscalingv2.ValueMetricType:
if v, ok := m["value"].(string); ok && v != "0" && v != "" {
Expand Down Expand Up @@ -235,7 +235,7 @@ func expandV2ScalingRules(in []interface{}) *autoscalingv2.HPAScalingRules {
}

if v, ok := r["stabilization_window_seconds"].(int); ok {
spec.StabilizationWindowSeconds = ptrToInt32(int32(v))
spec.StabilizationWindowSeconds = pointerOf(int32(v))
}

return spec
Expand Down
6 changes: 3 additions & 3 deletions kubernetes/structure_horizontal_pod_autoscaler_v2beta2.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func expandHorizontalPodAutoscalerV2Beta2Spec(in []interface{}) (*autoscalingv2b
}

if v, ok := m["min_replicas"].(int); ok && v > 0 {
spec.MinReplicas = ptrToInt32(int32(v))
spec.MinReplicas = pointerOf(int32(v))
}

if v, ok := m["scale_target_ref"]; ok {
Expand Down Expand Up @@ -68,7 +68,7 @@ func expandV2Beta2MetricTarget(m map[string]interface{}) autoscalingv2beta2.Metr
}
case autoscalingv2beta2.UtilizationMetricType:
if v, ok := m["average_utilization"].(int); ok && v > 0 {
target.AverageUtilization = ptrToInt32(int32(v))
target.AverageUtilization = pointerOf(int32(v))
}
case autoscalingv2beta2.ValueMetricType:
if v, ok := m["value"].(string); ok && v != "0" && v != "" {
Expand Down Expand Up @@ -235,7 +235,7 @@ func expandV2Beta2ScalingRules(in []interface{}) *autoscalingv2beta2.HPAScalingR
}

if v, ok := r["stabilization_window_seconds"].(int); ok {
spec.StabilizationWindowSeconds = ptrToInt32(int32(v))
spec.StabilizationWindowSeconds = pointerOf(int32(v))
}

return spec
Expand Down
12 changes: 6 additions & 6 deletions kubernetes/structure_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ func expandJobV1Spec(j []interface{}) (batchv1.JobSpec, error) {
in := j[0].(map[string]interface{})

if v, ok := in["active_deadline_seconds"].(int); ok && v > 0 {
obj.ActiveDeadlineSeconds = ptrToInt64(int64(v))
obj.ActiveDeadlineSeconds = pointerOf(int64(v))
}

if v, ok := in["backoff_limit"].(int); ok && v >= 0 {
obj.BackoffLimit = ptrToInt32(int32(v))
obj.BackoffLimit = pointerOf(int32(v))
}

if v, ok := in["completions"].(int); ok && v > 0 {
obj.Completions = ptrToInt32(int32(v))
obj.Completions = pointerOf(int32(v))
}

if v, ok := in["completion_mode"].(string); ok && v != "" {
Expand All @@ -83,11 +83,11 @@ func expandJobV1Spec(j []interface{}) (batchv1.JobSpec, error) {
}

if v, ok := in["manual_selector"]; ok {
obj.ManualSelector = ptrToBool(v.(bool))
obj.ManualSelector = pointerOf(v.(bool))
}

if v, ok := in["parallelism"].(int); ok && v >= 0 {
obj.Parallelism = ptrToInt32(int32(v))
obj.Parallelism = pointerOf(int32(v))
}

if v, ok := in["selector"].([]interface{}); ok && len(v) > 0 {
Expand All @@ -105,7 +105,7 @@ func expandJobV1Spec(j []interface{}) (batchv1.JobSpec, error) {
if err != nil {
return obj, err
}
obj.TTLSecondsAfterFinished = ptrToInt32(int32(i))
obj.TTLSecondsAfterFinished = pointerOf(int32(i))
}

return obj, nil
Expand Down
Loading

0 comments on commit d5c0666

Please sign in to comment.