Skip to content

Commit

Permalink
fix: pvc mapping
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin committed Dec 17, 2024
1 parent c47ff99 commit f2dd57b
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 12 deletions.
61 changes: 55 additions & 6 deletions pkg/mapper/testworkflows/kube_openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -1213,13 +1213,62 @@ func MapTestWorkflowTagSchemaKubeToAPI(v testworkflowsv1.TestWorkflowTagSchema)
}
}

func MapTypeLocalObjectReferenceKubeToAPI(v corev1.TypedLocalObjectReference) testkube.TypedLocalObjectReference {
return testkube.TypedLocalObjectReference{
ApiGroup: MapStringToBoxedString(v.APIGroup),
Kind: v.Kind,
Name: v.Name,
}
}

func MapTypeObjectReferenceKubeToAPI(v corev1.TypedObjectReference) testkube.TypedObjectReference {
return testkube.TypedObjectReference{
ApiGroup: MapStringToBoxedString(v.APIGroup),
Kind: v.Kind,
Name: v.Name,
Namespace: MapStringToBoxedString(v.Namespace),
}
}

func MapVolumeResourceRequirementsKubeToAPI(v corev1.VolumeResourceRequirements) *testkube.TestWorkflowResources {
return &testkube.TestWorkflowResources{
Limits: MapResourcesListKubeCoreToAPI(v.Limits),
Requests: MapResourcesListKubeCoreToAPI(v.Requests),
}
}

func MapResourcesListKubeCoreToAPI(v corev1.ResourceList) *testkube.TestWorkflowResourcesList {
if len(v) == 0 {
return nil
}

res := &testkube.TestWorkflowResourcesList{}
if q, ok := v[corev1.ResourceCPU]; !ok {
res.Cpu = q.String()
}
if q, ok := v[corev1.ResourceMemory]; !ok {
res.Memory = q.String()
}
if q, ok := v[corev1.ResourceStorage]; !ok {
res.Storage = q.String()
}
if q, ok := v[corev1.ResourceEphemeralStorage]; !ok {
res.EphemeralStorage = q.String()
}
return res
}

func MapPvcConfigKubeToAPI(v corev1.PersistentVolumeClaimSpec) testkube.TestWorkflowPvcConfig {
return testkube.TestWorkflowPvcConfig{
// AccessModes: v.AccessModes,
// VolumeMode: MapStringToBoxedString(v.VolumeMode),
// Resources: common.MapPtr(v.Resources, MapResourcesKubeToAPI),
StorageClassName: MapStringToBoxedString(v.StorageClassName),
VolumeName: v.VolumeName,
Selector: common.MapPtr(v.Selector, MapSelectorToAPI),
AccessModes: common.MapSlice(v.AccessModes,
func(v corev1.PersistentVolumeAccessMode) string { return (string)(v) }),
VolumeMode: MapStringToBoxedString((*string)(v.VolumeMode)),
Resources: MapVolumeResourceRequirementsKubeToAPI(v.Resources),
StorageClassName: MapStringToBoxedString(v.StorageClassName),
VolumeName: v.VolumeName,
Selector: common.MapPtr(v.Selector, MapSelectorToAPI),
DataSource: common.MapPtr(v.DataSource, MapTypeLocalObjectReferenceKubeToAPI),
DataSourceRef: common.MapPtr(v.DataSourceRef, MapTypeObjectReferenceKubeToAPI),
VolumeAttributesClassName: MapStringToBoxedString(v.VolumeAttributesClassName),
}
}
64 changes: 58 additions & 6 deletions pkg/mapper/testworkflows/openapi_kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -1492,13 +1492,65 @@ func MapTestWorkflowTagSchemaAPIToKube(v testkube.TestWorkflowTagSchema) testwor
}
}

func MapTypeLocalObjectReferenceAPIToKube(v testkube.TypedLocalObjectReference) corev1.TypedLocalObjectReference {
return corev1.TypedLocalObjectReference{
APIGroup: MapBoxedStringToString(v.ApiGroup),
Kind: v.Kind,
Name: v.Name,
}
}

func MapTypeObjectReferenceAPIToKube(v testkube.TypedObjectReference) corev1.TypedObjectReference {
return corev1.TypedObjectReference{
APIGroup: MapBoxedStringToString(v.ApiGroup),
Kind: v.Kind,
Name: v.Name,
Namespace: MapBoxedStringToString(v.Namespace),
}
}

func MapVolumeResourceRequirementsAPIToKube(v *testkube.TestWorkflowResources) corev1.VolumeResourceRequirements {
if v == nil {
return corev1.VolumeResourceRequirements{}
}

return corev1.VolumeResourceRequirements{
Limits: MapResourcesListAPIToKubeCore(v.Limits),
Requests: MapResourcesListAPIToKubeCore(v.Requests),
}
}

func MapResourcesListAPIToKubeCore(v *testkube.TestWorkflowResourcesList) corev1.ResourceList {
if v == nil {
return nil
}
res := make(map[corev1.ResourceName]resource.Quantity)
if v.Cpu != "" {
res[corev1.ResourceCPU], _ = resource.ParseQuantity(v.Cpu)
}
if v.Memory != "" {
res[corev1.ResourceMemory], _ = resource.ParseQuantity(v.Memory)
}
if v.Storage != "" {
res[corev1.ResourceStorage], _ = resource.ParseQuantity(v.Storage)
}
if v.EphemeralStorage != "" {
res[corev1.ResourceEphemeralStorage], _ = resource.ParseQuantity(v.EphemeralStorage)
}
return res
}

func MapPvcConfigAPIToKube(v testkube.TestWorkflowPvcConfig) corev1.PersistentVolumeClaimSpec {
return corev1.PersistentVolumeClaimSpec{
// AccessModes: v.AccessModes,
// VolumeMode: MapBoxedStringToString(v.VolumeMode),
// Resources: common.MapPtr(v.Resources, MapResourcesAPIToKube),
StorageClassName: MapBoxedStringToString(v.StorageClassName),
VolumeName: v.VolumeName,
Selector: common.MapPtr(v.Selector, MapLabelSelectorAPIToKube),
AccessModes: common.MapSlice(v.AccessModes,
func(v string) corev1.PersistentVolumeAccessMode { return (corev1.PersistentVolumeAccessMode)(v) }),
VolumeMode: (*corev1.PersistentVolumeMode)(MapBoxedStringToString(v.VolumeMode)),
Resources: MapVolumeResourceRequirementsAPIToKube(v.Resources),
StorageClassName: MapBoxedStringToString(v.StorageClassName),
VolumeName: v.VolumeName,
Selector: common.MapPtr(v.Selector, MapLabelSelectorAPIToKube),
DataSource: common.MapPtr(v.DataSource, MapTypeLocalObjectReferenceAPIToKube),
DataSourceRef: common.MapPtr(v.DataSourceRef, MapTypeObjectReferenceAPIToKube),
VolumeAttributesClassName: MapBoxedStringToString(v.VolumeAttributesClassName),
}
}

0 comments on commit f2dd57b

Please sign in to comment.