diff --git a/kubernetes/provider.go b/kubernetes/provider.go index f39ac86b1d..320eb12a66 100644 --- a/kubernetes/provider.go +++ b/kubernetes/provider.go @@ -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 } @@ -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 } diff --git a/kubernetes/resource_kubernetes_annotations.go b/kubernetes/resource_kubernetes_annotations.go index 409fb56108..5b6d20f677 100644 --- a/kubernetes/resource_kubernetes_annotations.go +++ b/kubernetes/resource_kubernetes_annotations.go @@ -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 { diff --git a/kubernetes/resource_kubernetes_config_map_v1.go b/kubernetes/resource_kubernetes_config_map_v1.go index 6a314e6496..6a0aabe5c8 100644 --- a/kubernetes/resource_kubernetes_config_map_v1.go +++ b/kubernetes/resource_kubernetes_config_map_v1.go @@ -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) @@ -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)), }) } diff --git a/kubernetes/resource_kubernetes_config_map_v1_data.go b/kubernetes/resource_kubernetes_config_map_v1_data.go index 85ddb01b29..3517e512fc 100644 --- a/kubernetes/resource_kubernetes_config_map_v1_data.go +++ b/kubernetes/resource_kubernetes_config_map_v1_data.go @@ -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 { diff --git a/kubernetes/resource_kubernetes_env.go b/kubernetes/resource_kubernetes_env.go index e4f64a5c72..110a8ab1e6 100644 --- a/kubernetes/resource_kubernetes_env.go +++ b/kubernetes/resource_kubernetes_env.go @@ -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 { diff --git a/kubernetes/resource_kubernetes_labels.go b/kubernetes/resource_kubernetes_labels.go index 82171e7a73..02aa2e0293 100644 --- a/kubernetes/resource_kubernetes_labels.go +++ b/kubernetes/resource_kubernetes_labels.go @@ -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 { diff --git a/kubernetes/resource_kubernetes_node_taint.go b/kubernetes/resource_kubernetes_node_taint.go index 5fa19c52bf..89db2d0c4d 100644 --- a/kubernetes/resource_kubernetes_node_taint.go +++ b/kubernetes/resource_kubernetes_node_taint.go @@ -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 { diff --git a/kubernetes/resource_kubernetes_secret_v1.go b/kubernetes/resource_kubernetes_secret_v1.go index 1a4d0d292b..2b47f3406c 100644 --- a/kubernetes/resource_kubernetes_secret_v1.go +++ b/kubernetes/resource_kubernetes_secret_v1.go @@ -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) @@ -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)), }) } diff --git a/kubernetes/resource_kubernetes_service_account_v1.go b/kubernetes/resource_kubernetes_service_account_v1.go index a54e8c5779..ec05a10f0f 100644 --- a/kubernetes/resource_kubernetes_service_account_v1.go +++ b/kubernetes/resource_kubernetes_service_account_v1.go @@ -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(), ""), diff --git a/kubernetes/resource_kubernetes_service_v1_test.go b/kubernetes/resource_kubernetes_service_v1_test.go index 65f7b7028f..248579bc26 100644 --- a/kubernetes/resource_kubernetes_service_v1_test.go +++ b/kubernetes/resource_kubernetes_service_v1_test.go @@ -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, diff --git a/kubernetes/structure_api_service_spec.go b/kubernetes/structure_api_service_spec.go index cadd2e0739..8c0cdd52d8 100644 --- a/kubernetes/structure_api_service_spec.go +++ b/kubernetes/structure_api_service_spec.go @@ -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 { diff --git a/kubernetes/structure_cron_job_v1.go b/kubernetes/structure_cron_job_v1.go index 1a2128fd7a..b8c93f662c 100644 --- a/kubernetes/structure_cron_job_v1.go +++ b/kubernetes/structure_cron_job_v1.go @@ -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 != "" { @@ -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 diff --git a/kubernetes/structure_cron_job_v1beta1.go b/kubernetes/structure_cron_job_v1beta1.go index c03ca2316e..4792eba514 100644 --- a/kubernetes/structure_cron_job_v1beta1.go +++ b/kubernetes/structure_cron_job_v1beta1.go @@ -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 != "" { @@ -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 diff --git a/kubernetes/structure_csi_driver.go b/kubernetes/structure_csi_driver.go index c2a00779f3..2766ae0d2c 100644 --- a/kubernetes/structure_csi_driver.go +++ b/kubernetes/structure_csi_driver.go @@ -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 { diff --git a/kubernetes/structure_csi_driver_v1.go b/kubernetes/structure_csi_driver_v1.go index be85e146bf..a44087e023 100644 --- a/kubernetes/structure_csi_driver_v1.go +++ b/kubernetes/structure_csi_driver_v1.go @@ -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 { diff --git a/kubernetes/structure_endpoints.go b/kubernetes/structure_endpoints.go index f709c028c9..d9c5d32a57 100644 --- a/kubernetes/structure_endpoints.go +++ b/kubernetes/structure_endpoints.go @@ -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 } diff --git a/kubernetes/structure_endpointslice.go b/kubernetes/structure_endpointslice.go index a555454fe0..1e09bfc510 100644 --- a/kubernetes/structure_endpointslice.go +++ b/kubernetes/structure_endpointslice.go @@ -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 @@ -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 } @@ -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 diff --git a/kubernetes/structure_horizontal_pod_autoscaler.go b/kubernetes/structure_horizontal_pod_autoscaler.go index 82261e955a..5888c2b571 100644 --- a/kubernetes/structure_horizontal_pod_autoscaler.go +++ b/kubernetes/structure_horizontal_pod_autoscaler.go @@ -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 diff --git a/kubernetes/structure_horizontal_pod_autoscaler_v2.go b/kubernetes/structure_horizontal_pod_autoscaler_v2.go index fa5973f97e..3a8c849183 100644 --- a/kubernetes/structure_horizontal_pod_autoscaler_v2.go +++ b/kubernetes/structure_horizontal_pod_autoscaler_v2.go @@ -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 { @@ -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 != "" { @@ -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 diff --git a/kubernetes/structure_horizontal_pod_autoscaler_v2beta2.go b/kubernetes/structure_horizontal_pod_autoscaler_v2beta2.go index e37968d992..5b1f9cda85 100644 --- a/kubernetes/structure_horizontal_pod_autoscaler_v2beta2.go +++ b/kubernetes/structure_horizontal_pod_autoscaler_v2beta2.go @@ -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 { @@ -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 != "" { @@ -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 diff --git a/kubernetes/structure_job.go b/kubernetes/structure_job.go index 0aaedfb4f5..8df8a4c01c 100644 --- a/kubernetes/structure_job.go +++ b/kubernetes/structure_job.go @@ -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 != "" { @@ -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 { @@ -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 diff --git a/kubernetes/structure_mutating_webhook_configuration.go b/kubernetes/structure_mutating_webhook_configuration.go index 3c777748be..06370bd109 100644 --- a/kubernetes/structure_mutating_webhook_configuration.go +++ b/kubernetes/structure_mutating_webhook_configuration.go @@ -109,7 +109,7 @@ func expandMutatingWebhook(in map[string]interface{}) admissionregistrationv1.Mu } if v, ok := in["timeout_seconds"].(int); ok { - obj.TimeoutSeconds = ptrToInt32(int32(v)) + obj.TimeoutSeconds = pointerOf(int32(v)) } return obj diff --git a/kubernetes/structure_persistent_volume_claim.go b/kubernetes/structure_persistent_volume_claim.go index fca05bad8f..0487dbaad9 100644 --- a/kubernetes/structure_persistent_volume_claim.go +++ b/kubernetes/structure_persistent_volume_claim.go @@ -7,13 +7,12 @@ import ( "errors" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1" ) // Flatteners -func flattenPersistentVolumeClaimSpec(in v1.PersistentVolumeClaimSpec) []interface{} { +func flattenPersistentVolumeClaimSpec(in corev1.PersistentVolumeClaimSpec) []interface{} { att := make(map[string]interface{}) att["access_modes"] = flattenPersistentVolumeAccessModes(in.AccessModes) att["resources"] = flattenResourceRequirements(in.Resources) @@ -29,7 +28,7 @@ func flattenPersistentVolumeClaimSpec(in v1.PersistentVolumeClaimSpec) []interfa return []interface{}{att} } -func flattenResourceRequirements(in v1.ResourceRequirements) []interface{} { +func flattenResourceRequirements(in corev1.ResourceRequirements) []interface{} { att := make(map[string]interface{}) if len(in.Limits) > 0 { att["limits"] = flattenResourceList(in.Limits) @@ -64,8 +63,8 @@ func expandPersistentVolumeClaim(p map[string]interface{}) (*corev1.PersistentVo return pvc, nil } -func expandPersistentVolumeClaimSpec(l []interface{}) (*v1.PersistentVolumeClaimSpec, error) { - obj := &v1.PersistentVolumeClaimSpec{} +func expandPersistentVolumeClaimSpec(l []interface{}) (*corev1.PersistentVolumeClaimSpec, error) { + obj := &corev1.PersistentVolumeClaimSpec{} if len(l) == 0 || l[0] == nil { return obj, nil } @@ -83,13 +82,13 @@ func expandPersistentVolumeClaimSpec(l []interface{}) (*v1.PersistentVolumeClaim obj.VolumeName = v } if v, ok := in["storage_class_name"].(string); ok && v != "" { - obj.StorageClassName = ptrToString(v) + obj.StorageClassName = pointerOf(v) } return obj, nil } -func expandResourceRequirements(l []interface{}) (*v1.ResourceRequirements, error) { - obj := &v1.ResourceRequirements{} +func expandResourceRequirements(l []interface{}) (*corev1.ResourceRequirements, error) { + obj := &corev1.ResourceRequirements{} if len(l) == 0 || l[0] == nil { return obj, nil } diff --git a/kubernetes/structure_persistent_volume_spec.go b/kubernetes/structure_persistent_volume_spec.go index ac44acd4a5..f06e3a8777 100644 --- a/kubernetes/structure_persistent_volume_spec.go +++ b/kubernetes/structure_persistent_volume_spec.go @@ -579,10 +579,10 @@ func expandAzureDiskVolumeSource(l []interface{}) *v1.AzureDiskVolumeSource { DataDiskURI: in["data_disk_uri"].(string), } if v, ok := in["fs_type"].(string); ok { - obj.FSType = ptrToString(v) + obj.FSType = pointerOf(v) } if v, ok := in["read_only"].(bool); ok { - obj.ReadOnly = ptrToBool(v) + obj.ReadOnly = pointerOf(v) } if v, ok := in["kind"].(string); ok && in["kind"].(string) != "" { kind := v1.AzureDataDiskKind(v) @@ -717,7 +717,7 @@ func expandFCVolumeSource(l []interface{}) *v1.FCVolumeSource { in := l[0].(map[string]interface{}) obj := &v1.FCVolumeSource{ TargetWWNs: sliceOfString(in["target_ww_ns"].(*schema.Set).List()), - Lun: ptrToInt32(int32(in["lun"].(int))), + Lun: pointerOf(int32(in["lun"].(int))), } if v, ok := in["fs_type"].(string); ok { obj.FSType = v diff --git a/kubernetes/structure_pod_security_policy_spec.go b/kubernetes/structure_pod_security_policy_spec.go index fe3a555744..90f1791ac6 100644 --- a/kubernetes/structure_pod_security_policy_spec.go +++ b/kubernetes/structure_pod_security_policy_spec.go @@ -221,7 +221,7 @@ func expandPodSecurityPolicySpec(in []interface{}) (v1beta1.PodSecurityPolicySpe } if v, ok := m["allow_privilege_escalation"].(bool); ok { - spec.AllowPrivilegeEscalation = ptrToBool(v) + spec.AllowPrivilegeEscalation = pointerOf(v) } if v, ok := m["allowed_capabilities"].([]interface{}); ok && len(v) > 0 { @@ -249,7 +249,7 @@ func expandPodSecurityPolicySpec(in []interface{}) (v1beta1.PodSecurityPolicySpe } if v, ok := m["default_allow_privilege_escalation"].(bool); ok { - spec.DefaultAllowPrivilegeEscalation = ptrToBool(v) + spec.DefaultAllowPrivilegeEscalation = pointerOf(v) } if v, ok := m["forbidden_sysctls"].([]interface{}); ok && len(v) > 0 { diff --git a/kubernetes/structure_service_spec.go b/kubernetes/structure_service_spec.go index fd02da747e..30d7e7d9c6 100644 --- a/kubernetes/structure_service_spec.go +++ b/kubernetes/structure_service_spec.go @@ -188,7 +188,7 @@ func expandSessionAffinityConfigClientIP(l []interface{}) *v1.ClientIPConfig { in := l[0].(map[string]interface{}) if v, ok := in["timeout_seconds"].(int); ok { - obj.TimeoutSeconds = ptrToInt32(int32(v)) + obj.TimeoutSeconds = pointerOf(int32(v)) } return obj diff --git a/kubernetes/structure_validating_webhook_configuration.go b/kubernetes/structure_validating_webhook_configuration.go index 90a433d7c1..00b550c0ae 100644 --- a/kubernetes/structure_validating_webhook_configuration.go +++ b/kubernetes/structure_validating_webhook_configuration.go @@ -100,7 +100,7 @@ func expandValidatingWebhook(in map[string]interface{}) admissionregistrationv1. } if v, ok := in["timeout_seconds"].(int); ok { - obj.TimeoutSeconds = ptrToInt32(int32(v)) + obj.TimeoutSeconds = pointerOf(int32(v)) } return obj diff --git a/kubernetes/structures.go b/kubernetes/structures.go index cdcea644a3..c02f46c3fb 100644 --- a/kubernetes/structures.go +++ b/kubernetes/structures.go @@ -227,20 +227,8 @@ func flattenByteMapToStringMap(m map[string][]byte) map[string]string { return result } -func ptrToString(s string) *string { - return &s -} - -func ptrToBool(b bool) *bool { - return &b -} - -func ptrToInt32(i int32) *int32 { - return &i -} - -func ptrToInt64(i int64) *int64 { - return &i +func pointerOf[A any](a A) *A { + return &a } func sliceOfString(slice []interface{}) []string { diff --git a/kubernetes/structures_admissionregistration.go b/kubernetes/structures_admissionregistration.go index 8efcd6cf89..38ae028451 100644 --- a/kubernetes/structures_admissionregistration.go +++ b/kubernetes/structures_admissionregistration.go @@ -42,11 +42,11 @@ func expandServiceReference(l []interface{}) *admissionregistrationv1.ServiceRef } if v, ok := in["path"].(string); ok && v != "" { - obj.Path = ptrToString(v) + obj.Path = pointerOf(v) } if v, ok := in["port"].(int); ok { - obj.Port = ptrToInt32(int32(v)) + obj.Port = pointerOf(int32(v)) } return obj @@ -88,7 +88,7 @@ func expandWebhookClientConfig(l []interface{}) admissionregistrationv1.WebhookC } if v, ok := in["url"].(string); ok && v != "" { - obj.URL = ptrToString(v) + obj.URL = pointerOf(v) } return obj diff --git a/kubernetes/structures_container.go b/kubernetes/structures_container.go index 66f7ce712f..20f8115a8d 100644 --- a/kubernetes/structures_container.go +++ b/kubernetes/structures_container.go @@ -600,33 +600,33 @@ func expandContainerSecurityContext(l []interface{}) (*v1.SecurityContext, error in := l[0].(map[string]interface{}) obj := v1.SecurityContext{} if v, ok := in["allow_privilege_escalation"]; ok { - obj.AllowPrivilegeEscalation = ptrToBool(v.(bool)) + obj.AllowPrivilegeEscalation = pointerOf(v.(bool)) } if v, ok := in["capabilities"].([]interface{}); ok && len(v) > 0 { obj.Capabilities = expandSecurityCapabilities(v) } if v, ok := in["privileged"]; ok { - obj.Privileged = ptrToBool(v.(bool)) + obj.Privileged = pointerOf(v.(bool)) } if v, ok := in["read_only_root_filesystem"]; ok { - obj.ReadOnlyRootFilesystem = ptrToBool(v.(bool)) + obj.ReadOnlyRootFilesystem = pointerOf(v.(bool)) } if v, ok := in["run_as_group"].(string); ok && v != "" { i, err := strconv.ParseInt(v, 10, 64) if err != nil { return &obj, err } - obj.RunAsGroup = ptrToInt64(int64(i)) + obj.RunAsGroup = pointerOf(int64(i)) } if v, ok := in["run_as_non_root"]; ok { - obj.RunAsNonRoot = ptrToBool(v.(bool)) + obj.RunAsNonRoot = pointerOf(v.(bool)) } if v, ok := in["run_as_user"].(string); ok && v != "" { i, err := strconv.ParseInt(v, 10, 64) if err != nil { return &obj, err } - obj.RunAsUser = ptrToInt64(int64(i)) + obj.RunAsUser = pointerOf(int64(i)) } if v, ok := in["seccomp_profile"].([]interface{}); ok && len(v) > 0 { obj.SeccompProfile = expandSeccompProfile(v) @@ -683,7 +683,7 @@ func expandGRPC(l []interface{}) *v1.GRPCAction { obj.Port = int32(v) } if v, ok := in["service"].(string); ok { - obj.Service = ptrToString(v) + obj.Service = pointerOf(v) } return &obj } @@ -910,7 +910,7 @@ func expandConfigMapKeyRef(r []interface{}) (*v1.ConfigMapKeySelector, error) { obj.Name = v } if v, ok := in["optional"]; ok { - obj.Optional = ptrToBool(v.(bool)) + obj.Optional = pointerOf(v.(bool)) } return obj, nil @@ -964,7 +964,7 @@ func expandSecretRef(r []interface{}) (*v1.SecretEnvSource, error) { obj.Name = v } if v, ok := in["optional"]; ok { - obj.Optional = ptrToBool(v.(bool)) + obj.Optional = pointerOf(v.(bool)) } return obj, nil @@ -984,7 +984,7 @@ func expandSecretKeyRef(r []interface{}) (*v1.SecretKeySelector, error) { obj.Name = v } if v, ok := in["optional"]; ok { - obj.Optional = ptrToBool(v.(bool)) + obj.Optional = pointerOf(v.(bool)) } return obj, nil } @@ -1036,7 +1036,7 @@ func expandConfigMapRef(r []interface{}) (*v1.ConfigMapEnvSource, error) { obj.Name = v } if v, ok := in["optional"]; ok { - obj.Optional = ptrToBool(v.(bool)) + obj.Optional = pointerOf(v.(bool)) } return obj, nil diff --git a/kubernetes/structures_container_test.go b/kubernetes/structures_container_test.go index 12ccc76c8e..c5c1304085 100644 --- a/kubernetes/structures_container_test.go +++ b/kubernetes/structures_container_test.go @@ -21,7 +21,7 @@ func TestFlattenSecretKeyRef(t *testing.T) { Name: "Secret1", }, Key: "key1", - Optional: ptrToBool(true), + Optional: pointerOf(true), }, []interface{}{ map[string]interface{}{ @@ -78,7 +78,7 @@ func TestExpandSecretKeyRef(t *testing.T) { Name: "Secret1", }, Key: "key1", - Optional: ptrToBool(true), + Optional: pointerOf(true), }, }, { @@ -124,7 +124,7 @@ func TestFlattenConfigMapKeyRef(t *testing.T) { Name: "configmap1", }, Key: "key1", - Optional: ptrToBool(true), + Optional: pointerOf(true), }, []interface{}{ map[string]interface{}{ @@ -181,7 +181,7 @@ func TestExpandConfigMapKeyRef(t *testing.T) { Name: "configmap1", }, Key: "key1", - Optional: ptrToBool(true), + Optional: pointerOf(true), }, }, { diff --git a/kubernetes/structures_daemonset.go b/kubernetes/structures_daemonset.go index a65d6e42c7..0ed77ba470 100644 --- a/kubernetes/structures_daemonset.go +++ b/kubernetes/structures_daemonset.go @@ -64,7 +64,7 @@ func expandDaemonSetSpec(daemonset []interface{}) (appsv1.DaemonSetSpec, error) in := daemonset[0].(map[string]interface{}) obj.MinReadySeconds = int32(in["min_ready_seconds"].(int)) - obj.RevisionHistoryLimit = ptrToInt32(int32(in["revision_history_limit"].(int))) + obj.RevisionHistoryLimit = pointerOf(int32(in["revision_history_limit"].(int))) if v, ok := in["selector"].([]interface{}); ok && len(v) > 0 { obj.Selector = expandLabelSelector(v) diff --git a/kubernetes/structures_deployment.go b/kubernetes/structures_deployment.go index 648229e649..646fd4f720 100644 --- a/kubernetes/structures_deployment.go +++ b/kubernetes/structures_deployment.go @@ -79,15 +79,15 @@ func expandDeploymentSpec(deployment []interface{}) (*appsv1.DeploymentSpec, err obj.MinReadySeconds = int32(in["min_ready_seconds"].(int)) obj.Paused = in["paused"].(bool) - obj.ProgressDeadlineSeconds = ptrToInt32(int32(in["progress_deadline_seconds"].(int))) + obj.ProgressDeadlineSeconds = pointerOf(int32(in["progress_deadline_seconds"].(int))) if v, ok := in["replicas"].(string); ok && v != "" { i, err := strconv.ParseInt(v, 10, 32) if err != nil { return obj, err } - obj.Replicas = ptrToInt32(int32(i)) + obj.Replicas = pointerOf(int32(i)) } - obj.RevisionHistoryLimit = ptrToInt32(int32(in["revision_history_limit"].(int))) + obj.RevisionHistoryLimit = pointerOf(int32(in["revision_history_limit"].(int))) if v, ok := in["selector"].([]interface{}); ok && len(v) > 0 { obj.Selector = expandLabelSelector(v) diff --git a/kubernetes/structures_pod.go b/kubernetes/structures_pod.go index df3308d888..20ad9f511d 100644 --- a/kubernetes/structures_pod.go +++ b/kubernetes/structures_pod.go @@ -730,7 +730,7 @@ func expandPodSpec(p []interface{}) (*v1.PodSpec, error) { in := p[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["affinity"].([]interface{}); ok && len(v) > 0 { @@ -742,7 +742,7 @@ func expandPodSpec(p []interface{}) (*v1.PodSpec, error) { } if v, ok := in["automount_service_account_token"].(bool); ok { - obj.AutomountServiceAccountToken = ptrToBool(v) + obj.AutomountServiceAccountToken = pointerOf(v) } if v, ok := in["container"].([]interface{}); ok && len(v) > 0 { @@ -782,7 +782,7 @@ func expandPodSpec(p []interface{}) (*v1.PodSpec, error) { } if v, ok := in["enable_service_links"].(bool); ok { - obj.EnableServiceLinks = ptrToBool(v) + obj.EnableServiceLinks = pointerOf(v) } if v, ok := in["host_aliases"].([]interface{}); ok && len(v) > 0 { @@ -833,7 +833,7 @@ func expandPodSpec(p []interface{}) (*v1.PodSpec, error) { } if v, ok := in["runtime_class_name"].(string); ok && v != "" { - obj.RuntimeClassName = ptrToString(v) + obj.RuntimeClassName = pointerOf(v) } if v, ok := in["priority_class_name"].(string); ok { @@ -861,7 +861,7 @@ func expandPodSpec(p []interface{}) (*v1.PodSpec, error) { } if v, ok := in["share_process_namespace"]; ok { - obj.ShareProcessNamespace = ptrToBool(v.(bool)) + obj.ShareProcessNamespace = pointerOf(v.(bool)) } if v, ok := in["subdomain"].(string); ok { @@ -869,7 +869,7 @@ func expandPodSpec(p []interface{}) (*v1.PodSpec, error) { } if v, ok := in["termination_grace_period_seconds"].(int); ok { - obj.TerminationGracePeriodSeconds = ptrToInt64(int64(v)) + obj.TerminationGracePeriodSeconds = pointerOf(int64(v)) } if v, ok := in["toleration"].([]interface{}); ok && len(v) > 0 { @@ -924,19 +924,19 @@ func expandWindowsOptions(l []interface{}) *v1.WindowsSecurityContextOptions { obj := &v1.WindowsSecurityContextOptions{} if v, ok := in["gmsa_credential_spec"].(string); ok { - obj.GMSACredentialSpec = ptrToString(v) + obj.GMSACredentialSpec = pointerOf(v) } if v, ok := in["host_process"].(bool); ok { - obj.HostProcess = ptrToBool(v) + obj.HostProcess = pointerOf(v) } if v, ok := in["gmsa_credential_spec_name"].(string); ok { - obj.GMSACredentialSpecName = ptrToString(v) + obj.GMSACredentialSpecName = pointerOf(v) } if v, ok := in["run_as_username"].(string); ok { - obj.RunAsUserName = ptrToString(v) + obj.RunAsUserName = pointerOf(v) } return obj @@ -998,7 +998,7 @@ func expandDNSConfigOptions(options []interface{}) ([]v1.PodDNSConfigOption, err opt.Name = v } if v, ok := in["value"].(string); ok { - opt.Value = ptrToString(v) + opt.Value = pointerOf(v) } opts[i] = opt } @@ -1017,24 +1017,24 @@ func expandPodSecurityContext(l []interface{}) (*v1.PodSecurityContext, error) { if err != nil { return obj, err } - obj.FSGroup = ptrToInt64(int64(i)) + obj.FSGroup = pointerOf(int64(i)) } if v, ok := in["run_as_group"].(string); ok && v != "" { i, err := strconv.ParseInt(v, 10, 64) if err != nil { return obj, err } - obj.RunAsGroup = ptrToInt64(int64(i)) + obj.RunAsGroup = pointerOf(int64(i)) } if v, ok := in["run_as_non_root"].(bool); ok { - obj.RunAsNonRoot = ptrToBool(v) + obj.RunAsNonRoot = pointerOf(v) } if v, ok := in["run_as_user"].(string); ok && v != "" { i, err := strconv.ParseInt(v, 10, 64) if err != nil { return obj, err } - obj.RunAsUser = ptrToInt64(int64(i)) + obj.RunAsUser = pointerOf(int64(i)) } if v, ok := in["seccomp_profile"].([]interface{}); ok && len(v) > 0 { obj.SeccompProfile = expandSeccompProfile(v) @@ -1127,7 +1127,7 @@ func expandKeyPath(in []interface{}) []v1.KeyToPath { if v, ok := p["mode"].(string); ok { m, err := strconv.ParseInt(v, 8, 32) if err == nil { - keyPaths[i].Mode = ptrToInt32(int32(m)) + keyPaths[i].Mode = pointerOf(int32(m)) } } if v, ok := p["path"].(string); ok { @@ -1151,7 +1151,7 @@ func expandDownwardAPIVolumeFile(in []interface{}) ([]v1.DownwardAPIVolumeFile, if err != nil { return dapivf, fmt.Errorf("DownwardAPI volume file: failed to parse 'mode' value: %s", err) } - dapivf[i].Mode = ptrToInt32(int32(m)) + dapivf[i].Mode = pointerOf(int32(m)) } if v, ok := p["path"].(string); ok { dapivf[i].Path = v @@ -1184,7 +1184,7 @@ func expandConfigMapVolumeSource(l []interface{}) (*v1.ConfigMapVolumeSource, er if err != nil { return obj, fmt.Errorf("ConfigMap volume: failed to parse 'default_mode' value: %s", err) } - obj.DefaultMode = ptrToInt32(int32(v)) + obj.DefaultMode = pointerOf(int32(v)) } if v, ok := in["name"].(string); ok { @@ -1192,7 +1192,7 @@ func expandConfigMapVolumeSource(l []interface{}) (*v1.ConfigMapVolumeSource, er } if opt, ok := in["optional"].(bool); ok { - obj.Optional = ptrToBool(opt) + obj.Optional = pointerOf(opt) } if v, ok := in["items"].([]interface{}); ok && len(v) > 0 { obj.Items = expandKeyPath(v) @@ -1213,7 +1213,7 @@ func expandDownwardAPIVolumeSource(l []interface{}) (*v1.DownwardAPIVolumeSource if err != nil { return obj, fmt.Errorf("Downward API volume: failed to parse 'default_mode' value: %s", err) } - obj.DefaultMode = ptrToInt32(int32(v)) + obj.DefaultMode = pointerOf(int32(v)) } if v, ok := in["items"].([]interface{}); ok && len(v) > 0 { @@ -1290,7 +1290,7 @@ func expandSecretVolumeSource(l []interface{}) (*v1.SecretVolumeSource, error) { if err != nil { return obj, fmt.Errorf("Secret volume: failed to parse 'default_mode' value: %s", err) } - obj.DefaultMode = ptrToInt32(int32(v)) + obj.DefaultMode = pointerOf(int32(v)) } if secret, ok := in["secret_name"].(string); ok { @@ -1298,7 +1298,7 @@ func expandSecretVolumeSource(l []interface{}) (*v1.SecretVolumeSource, error) { } if opt, ok := in["optional"].(bool); ok { - obj.Optional = ptrToBool(opt) + obj.Optional = pointerOf(opt) } if v, ok := in["items"].([]interface{}); ok && len(v) > 0 { obj.Items = expandKeyPath(v) @@ -1319,7 +1319,7 @@ func expandProjectedVolumeSource(l []interface{}) (*v1.ProjectedVolumeSource, er if err != nil { return obj, fmt.Errorf("Projected volume: failed to parse 'default_mode' value: %s", err) } - obj.DefaultMode = ptrToInt32(int32(v)) + obj.DefaultMode = pointerOf(int32(v)) } if v, ok := in["sources"].([]interface{}); ok && len(v) > 0 { srcs, err := expandProjectedSources(v) @@ -1387,7 +1387,7 @@ func expandProjectedSecret(secret map[string]interface{}) *v1.SecretProjection { s.Items = expandKeyPath(values) } if value, ok := secret["optional"].(bool); ok { - s.Optional = ptrToBool(value) + s.Optional = pointerOf(value) } return s } @@ -1413,7 +1413,7 @@ func expandProjectedConfigMap(configMap map[string]interface{}) *v1.ConfigMapPro s.Items = expandKeyPath(values) } if value, ok := configMap["optional"].(bool); ok { - s.Optional = ptrToBool(value) + s.Optional = pointerOf(value) } return s } @@ -1468,7 +1468,7 @@ func expandProjectedServiceAccountToken(sat map[string]interface{}) (*v1.Service s.Audience = value } if value, ok := sat["expiration_seconds"].(int); ok { - s.ExpirationSeconds = ptrToInt64(int64(value)) + s.ExpirationSeconds = pointerOf(int64(value)) } if value, ok := sat["path"].(string); ok { s.Path = value @@ -1499,7 +1499,7 @@ func expandTolerations(tolerations []interface{}) ([]*v1.Toleration, error) { if err != nil { return nil, fmt.Errorf("invalid toleration_seconds must be int or \"\", got \"%s\"", value) } - ts[i].TolerationSeconds = ptrToInt64(seconds) + ts[i].TolerationSeconds = pointerOf(seconds) } if value, ok := m["value"]; ok { ts[i].Value = value.(string) diff --git a/kubernetes/structures_pod_test.go b/kubernetes/structures_pod_test.go index b627ba32c4..c1d9d84268 100644 --- a/kubernetes/structures_pod_test.go +++ b/kubernetes/structures_pod_test.go @@ -8,17 +8,17 @@ import ( "testing" "github.com/google/go-cmp/cmp" - v1 "k8s.io/api/core/v1" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" ) func TestFlattenTolerations(t *testing.T) { cases := []struct { - Input []v1.Toleration + Input []corev1.Toleration ExpectedOutput []interface{} }{ { - []v1.Toleration{ + []corev1.Toleration{ { Key: "node-role.kubernetes.io/spot-worker", Value: "true", @@ -32,7 +32,7 @@ func TestFlattenTolerations(t *testing.T) { }, }, { - []v1.Toleration{ + []corev1.Toleration{ { Key: "node-role.kubernetes.io/other-worker", Operator: "Exists", @@ -54,10 +54,10 @@ func TestFlattenTolerations(t *testing.T) { }, }, { - []v1.Toleration{ + []corev1.Toleration{ { Effect: "NoExecute", - TolerationSeconds: ptrToInt64(120), + TolerationSeconds: pointerOf(int64(120)), }, }, []interface{}{ @@ -68,7 +68,7 @@ func TestFlattenTolerations(t *testing.T) { }, }, { - []v1.Toleration{}, + []corev1.Toleration{}, []interface{}{}, }, } @@ -85,7 +85,7 @@ func TestFlattenTolerations(t *testing.T) { func TestExpandTolerations(t *testing.T) { cases := []struct { Input []interface{} - ExpectedOutput []*v1.Toleration + ExpectedOutput []*corev1.Toleration }{ { []interface{}{ @@ -94,7 +94,7 @@ func TestExpandTolerations(t *testing.T) { "value": "true", }, }, - []*v1.Toleration{ + []*corev1.Toleration{ { Key: "node-role.kubernetes.io/spot-worker", Value: "true", @@ -112,7 +112,7 @@ func TestExpandTolerations(t *testing.T) { "operator": "Exists", }, }, - []*v1.Toleration{ + []*corev1.Toleration{ { Key: "node-role.kubernetes.io/spot-worker", Value: "true", @@ -130,16 +130,16 @@ func TestExpandTolerations(t *testing.T) { "toleration_seconds": "120", }, }, - []*v1.Toleration{ + []*corev1.Toleration{ { Effect: "NoExecute", - TolerationSeconds: ptrToInt64(120), + TolerationSeconds: pointerOf(int64(120)), }, }, }, { []interface{}{}, - []*v1.Toleration{}, + []*corev1.Toleration{}, }, } @@ -157,18 +157,18 @@ func TestExpandTolerations(t *testing.T) { func TestFlattenSecretVolumeSource(t *testing.T) { cases := []struct { - Input *v1.SecretVolumeSource + Input *corev1.SecretVolumeSource ExpectedOutput []interface{} }{ { - &v1.SecretVolumeSource{ - DefaultMode: ptrToInt32(0644), + &corev1.SecretVolumeSource{ + DefaultMode: pointerOf(int32(0644)), SecretName: "secret1", - Optional: ptrToBool(true), - Items: []v1.KeyToPath{ + Optional: pointerOf(true), + Items: []corev1.KeyToPath{ { Key: "foo.txt", - Mode: ptrToInt32(0600), + Mode: pointerOf(int32(0600)), Path: "etc/foo.txt", }, }, @@ -189,10 +189,10 @@ func TestFlattenSecretVolumeSource(t *testing.T) { }, }, { - &v1.SecretVolumeSource{ - DefaultMode: ptrToInt32(0755), + &corev1.SecretVolumeSource{ + DefaultMode: pointerOf(int32(0755)), SecretName: "secret2", - Items: []v1.KeyToPath{ + Items: []corev1.KeyToPath{ { Key: "bar.txt", Path: "etc/bar.txt", @@ -213,7 +213,7 @@ func TestFlattenSecretVolumeSource(t *testing.T) { }, }, { - &v1.SecretVolumeSource{}, + &corev1.SecretVolumeSource{}, []interface{}{map[string]interface{}{}}, }, } @@ -230,7 +230,7 @@ func TestFlattenSecretVolumeSource(t *testing.T) { func TestExpandSecretVolumeSource(t *testing.T) { cases := []struct { Input []interface{} - ExpectedOutput *v1.SecretVolumeSource + ExpectedOutput *corev1.SecretVolumeSource }{ { []interface{}{ @@ -247,14 +247,14 @@ func TestExpandSecretVolumeSource(t *testing.T) { }, }, }, - &v1.SecretVolumeSource{ - DefaultMode: ptrToInt32(0644), + &corev1.SecretVolumeSource{ + DefaultMode: pointerOf(int32(0644)), SecretName: "secret1", - Optional: ptrToBool(true), - Items: []v1.KeyToPath{ + Optional: pointerOf(true), + Items: []corev1.KeyToPath{ { Key: "foo.txt", - Mode: ptrToInt32(0600), + Mode: pointerOf(int32(0600)), Path: "etc/foo.txt", }, }, @@ -273,10 +273,10 @@ func TestExpandSecretVolumeSource(t *testing.T) { }, }, }, - &v1.SecretVolumeSource{ - DefaultMode: ptrToInt32(0755), + &corev1.SecretVolumeSource{ + DefaultMode: pointerOf(int32(0755)), SecretName: "secret2", - Items: []v1.KeyToPath{ + Items: []corev1.KeyToPath{ { Key: "bar.txt", Path: "etc/bar.txt", @@ -286,7 +286,7 @@ func TestExpandSecretVolumeSource(t *testing.T) { }, { []interface{}{}, - &v1.SecretVolumeSource{}, + &corev1.SecretVolumeSource{}, }, } @@ -306,12 +306,12 @@ func TestFlattenEmptyDirVolumeSource(t *testing.T) { size, _ := resource.ParseQuantity("64Mi") cases := []struct { - Input *v1.EmptyDirVolumeSource + Input *corev1.EmptyDirVolumeSource ExpectedOutput []interface{} }{ { - &v1.EmptyDirVolumeSource{ - Medium: v1.StorageMediumMemory, + &corev1.EmptyDirVolumeSource{ + Medium: corev1.StorageMediumMemory, }, []interface{}{ map[string]interface{}{ @@ -320,8 +320,8 @@ func TestFlattenEmptyDirVolumeSource(t *testing.T) { }, }, { - &v1.EmptyDirVolumeSource{ - Medium: v1.StorageMediumMemory, + &corev1.EmptyDirVolumeSource{ + Medium: corev1.StorageMediumMemory, SizeLimit: &size, }, []interface{}{ @@ -332,7 +332,7 @@ func TestFlattenEmptyDirVolumeSource(t *testing.T) { }, }, { - &v1.EmptyDirVolumeSource{}, + &corev1.EmptyDirVolumeSource{}, []interface{}{ map[string]interface{}{ "medium": "", @@ -352,20 +352,20 @@ func TestFlattenEmptyDirVolumeSource(t *testing.T) { func TestFlattenConfigMapVolumeSource(t *testing.T) { cases := []struct { - Input *v1.ConfigMapVolumeSource + Input *corev1.ConfigMapVolumeSource ExpectedOutput []interface{} }{ { - &v1.ConfigMapVolumeSource{ - LocalObjectReference: v1.LocalObjectReference{ + &corev1.ConfigMapVolumeSource{ + LocalObjectReference: corev1.LocalObjectReference{ Name: "configmap1", }, - DefaultMode: ptrToInt32(0644), - Optional: ptrToBool(true), - Items: []v1.KeyToPath{ + DefaultMode: pointerOf(int32(0644)), + Optional: pointerOf(true), + Items: []corev1.KeyToPath{ { Key: "foo.txt", - Mode: ptrToInt32(0600), + Mode: pointerOf(int32(0600)), Path: "etc/foo.txt", }, }, @@ -386,12 +386,12 @@ func TestFlattenConfigMapVolumeSource(t *testing.T) { }, }, { - &v1.ConfigMapVolumeSource{ - LocalObjectReference: v1.LocalObjectReference{ + &corev1.ConfigMapVolumeSource{ + LocalObjectReference: corev1.LocalObjectReference{ Name: "configmap2", }, - DefaultMode: ptrToInt32(0755), - Items: []v1.KeyToPath{ + DefaultMode: pointerOf(int32(0755)), + Items: []corev1.KeyToPath{ { Key: "bar.txt", Path: "etc/bar.txt", @@ -412,7 +412,7 @@ func TestFlattenConfigMapVolumeSource(t *testing.T) { }, }, { - &v1.ConfigMapVolumeSource{}, + &corev1.ConfigMapVolumeSource{}, []interface{}{map[string]interface{}{"name": ""}}, }, } @@ -429,7 +429,7 @@ func TestFlattenConfigMapVolumeSource(t *testing.T) { func TestExpandConfigMapVolumeSource(t *testing.T) { cases := []struct { Input []interface{} - ExpectedOutput *v1.ConfigMapVolumeSource + ExpectedOutput *corev1.ConfigMapVolumeSource }{ { []interface{}{ @@ -446,16 +446,16 @@ func TestExpandConfigMapVolumeSource(t *testing.T) { }, }, }, - &v1.ConfigMapVolumeSource{ - LocalObjectReference: v1.LocalObjectReference{ + &corev1.ConfigMapVolumeSource{ + LocalObjectReference: corev1.LocalObjectReference{ Name: "configmap1", }, - DefaultMode: ptrToInt32(0644), - Optional: ptrToBool(true), - Items: []v1.KeyToPath{ + DefaultMode: pointerOf(int32(0644)), + Optional: pointerOf(true), + Items: []corev1.KeyToPath{ { Key: "foo.txt", - Mode: ptrToInt32(0600), + Mode: pointerOf(int32(0600)), Path: "etc/foo.txt", }, }, @@ -474,12 +474,12 @@ func TestExpandConfigMapVolumeSource(t *testing.T) { }, }, }, - &v1.ConfigMapVolumeSource{ - LocalObjectReference: v1.LocalObjectReference{ + &corev1.ConfigMapVolumeSource{ + LocalObjectReference: corev1.LocalObjectReference{ Name: "configmap2", }, - DefaultMode: ptrToInt32(0755), - Items: []v1.KeyToPath{ + DefaultMode: pointerOf(int32(0755)), + Items: []corev1.KeyToPath{ { Key: "bar.txt", Path: "etc/bar.txt", @@ -489,7 +489,7 @@ func TestExpandConfigMapVolumeSource(t *testing.T) { }, { []interface{}{}, - &v1.ConfigMapVolumeSource{}, + &corev1.ConfigMapVolumeSource{}, }, } @@ -507,35 +507,35 @@ func TestExpandConfigMapVolumeSource(t *testing.T) { func TestExpandThenFlatten_projected_volume(t *testing.T) { cases := []struct { - Input *v1.ProjectedVolumeSource + Input *corev1.ProjectedVolumeSource }{ { - Input: &v1.ProjectedVolumeSource{ - Sources: []v1.VolumeProjection{ + Input: &corev1.ProjectedVolumeSource{ + Sources: []corev1.VolumeProjection{ { - Secret: &v1.SecretProjection{ - LocalObjectReference: v1.LocalObjectReference{Name: "secret-1"}, + Secret: &corev1.SecretProjection{ + LocalObjectReference: corev1.LocalObjectReference{Name: "secret-1"}, }, }, { - ConfigMap: &v1.ConfigMapProjection{ - LocalObjectReference: v1.LocalObjectReference{Name: "config-1"}, + ConfigMap: &corev1.ConfigMapProjection{ + LocalObjectReference: corev1.LocalObjectReference{Name: "config-1"}, }, }, { - ConfigMap: &v1.ConfigMapProjection{ - LocalObjectReference: v1.LocalObjectReference{Name: "config-2"}, + ConfigMap: &corev1.ConfigMapProjection{ + LocalObjectReference: corev1.LocalObjectReference{Name: "config-2"}, }, }, { - DownwardAPI: &v1.DownwardAPIProjection{ - Items: []v1.DownwardAPIVolumeFile{ + DownwardAPI: &corev1.DownwardAPIProjection{ + Items: []corev1.DownwardAPIVolumeFile{ {Path: "path-1"}, }, }, }, { - ServiceAccountToken: &v1.ServiceAccountTokenProjection{ + ServiceAccountToken: &corev1.ServiceAccountTokenProjection{ Audience: "audience-1", }, }, @@ -565,7 +565,7 @@ func TestExpandThenFlatten_projected_volume(t *testing.T) { func TestExpandCSIVolumeSource(t *testing.T) { cases := []struct { Input []interface{} - ExpectedOutput *v1.CSIVolumeSource + ExpectedOutput *corev1.CSIVolumeSource }{ { Input: []interface{}{ @@ -583,14 +583,14 @@ func TestExpandCSIVolumeSource(t *testing.T) { }, }, }, - ExpectedOutput: &v1.CSIVolumeSource{ + ExpectedOutput: &corev1.CSIVolumeSource{ Driver: "secrets-store.csi.k8s.io", - ReadOnly: ptrToBool(true), - FSType: ptrToString("nfs"), + ReadOnly: pointerOf(true), + FSType: pointerOf("nfs"), VolumeAttributes: map[string]string{ "secretProviderClass": "azure-keyvault", }, - NodePublishSecretRef: &v1.LocalObjectReference{ + NodePublishSecretRef: &corev1.LocalObjectReference{ Name: "secrets-store", }, }, @@ -607,7 +607,7 @@ func TestExpandCSIVolumeSource(t *testing.T) { }, }, }, - ExpectedOutput: &v1.CSIVolumeSource{ + ExpectedOutput: &corev1.CSIVolumeSource{ Driver: "other-csi-driver.k8s.io", ReadOnly: nil, FSType: nil, @@ -632,18 +632,18 @@ func TestExpandCSIVolumeSource(t *testing.T) { func TestFlattenCSIVolumeSource(t *testing.T) { cases := []struct { - Input *v1.CSIVolumeSource + Input *corev1.CSIVolumeSource ExpectedOutput []interface{} }{ { - Input: &v1.CSIVolumeSource{ + Input: &corev1.CSIVolumeSource{ Driver: "secrets-store.csi.k8s.io", - ReadOnly: ptrToBool(true), - FSType: ptrToString("nfs"), + ReadOnly: pointerOf(true), + FSType: pointerOf("nfs"), VolumeAttributes: map[string]string{ "secretProviderClass": "azure-keyvault", }, - NodePublishSecretRef: &v1.LocalObjectReference{ + NodePublishSecretRef: &corev1.LocalObjectReference{ Name: "secrets-store", }, }, @@ -664,7 +664,7 @@ func TestFlattenCSIVolumeSource(t *testing.T) { }, }, { - Input: &v1.CSIVolumeSource{ + Input: &corev1.CSIVolumeSource{ Driver: "other-csi-driver.k8s.io", ReadOnly: nil, FSType: nil, diff --git a/kubernetes/structures_replication_controller.go b/kubernetes/structures_replication_controller.go index 08f25382da..180e8051a0 100644 --- a/kubernetes/structures_replication_controller.go +++ b/kubernetes/structures_replication_controller.go @@ -41,7 +41,7 @@ func expandReplicationControllerSpec(rc []interface{}) (*corev1.ReplicationContr } in := rc[0].(map[string]interface{}) obj.MinReadySeconds = int32(in["min_ready_seconds"].(int)) - obj.Replicas = ptrToInt32(int32(in["replicas"].(int))) + obj.Replicas = pointerOf(int32(in["replicas"].(int))) obj.Selector = expandStringMap(in["selector"].(map[string]interface{})) template, err := expandReplicationControllerTemplate(in["template"].([]interface{})) diff --git a/kubernetes/structures_stateful_set.go b/kubernetes/structures_stateful_set.go index af72e7dafc..5c5b4f64c1 100644 --- a/kubernetes/structures_stateful_set.go +++ b/kubernetes/structures_stateful_set.go @@ -32,11 +32,11 @@ func expandStatefulSetSpec(s []interface{}) (*v1.StatefulSetSpec, error) { if err != nil { return obj, err } - obj.Replicas = ptrToInt32(int32(i)) + obj.Replicas = pointerOf(int32(i)) } if v, ok := in["revision_history_limit"].(int); ok { - obj.RevisionHistoryLimit = ptrToInt32(int32(v)) + obj.RevisionHistoryLimit = pointerOf(int32(v)) } if v, ok := in["selector"].([]interface{}); ok && len(v) > 0 { @@ -104,7 +104,7 @@ func expandStatefulSetSpecUpdateStrategy(s []interface{}) (*v1.StatefulSetUpdate if !ok { return ust, errors.New("failed to expand 'spec.update_strategy.rolling_update.partition'") } - u.Partition = ptrToInt32(int32(p)) + u.Partition = pointerOf(int32(p)) ust.RollingUpdate = &u } log.Printf("[DEBUG] Expanded StatefulSet.Spec.UpdateStrategy: %#v", ust) diff --git a/kubernetes/structures_test.go b/kubernetes/structures_test.go index c551489bed..e65efa6016 100644 --- a/kubernetes/structures_test.go +++ b/kubernetes/structures_test.go @@ -4,7 +4,6 @@ package kubernetes import ( - "fmt" "testing" ) @@ -24,7 +23,7 @@ func TestIsInternalKey(t *testing.T) { {"pv.kubernetes.io/any/path", true}, } for _, tc := range testCases { - t.Run(fmt.Sprintf("%s", tc.Key), func(t *testing.T) { + t.Run(tc.Key, func(t *testing.T) { isInternal := isInternalKey(tc.Key) if tc.Expected && isInternal != tc.Expected { t.Fatalf("Expected %q to be internal", tc.Key) @@ -35,3 +34,29 @@ func TestIsInternalKey(t *testing.T) { }) } } + +func TestPointerOf(t *testing.T) { + b := false + bp := pointerOf(b) + if b != *bp { + t.Error("Failed to get bool pointer") + } + + s := "this" + sp := pointerOf(s) + if s != *sp { + t.Error("Failed to get string pointer") + } + + i := int(1984) + ip := pointerOf(i) + if i != *ip { + t.Error("Failed to get int pointer") + } + + i64 := int64(1984) + i64p := pointerOf(i64) + if i64 != *i64p { + t.Error("Failed to get int64 pointer") + } +} diff --git a/kubernetes/structures_tokenrequest.go b/kubernetes/structures_tokenrequest.go index aee6d9733f..6fd4d178bf 100644 --- a/kubernetes/structures_tokenrequest.go +++ b/kubernetes/structures_tokenrequest.go @@ -65,7 +65,7 @@ func expandTokenRequestV1Spec(p []interface{}) *authv1.TokenRequestSpec { obj.BoundObjectRef = bdObjRef if v, ok := in["expiration_seconds"].(int); v != 0 && ok { - obj.ExpirationSeconds = ptrToInt64(int64(v)) + obj.ExpirationSeconds = pointerOf(int64(v)) } return obj