Skip to content

Commit

Permalink
fix: add support for CSI volume source (#6009)
Browse files Browse the repository at this point in the history
  • Loading branch information
rangoo94 authored Nov 6, 2024
1 parent c2a75ac commit 1f99e13
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
22 changes: 22 additions & 0 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10394,6 +10394,26 @@ components:
- diskURI
type: object

CSIVolumeSource:
type: object
description: Represents a source location of a volume to mount, managed by an external CSI driver
properties:
driver:
type: string
description: driver is the name of the CSI driver that handles this volume.
readOnly:
$ref: "#/components/schemas/BoxedBoolean"
fsType:
$ref: "#/components/schemas/BoxedString"
volumeAttributes:
type: object
description: volumeAttributes stores driver-specific properties that are passed to the CSI driver.
Consult your driver's documentation for supported values.
additionalProperties:
type: string
nodePublishSecretRef:
$ref: "#/components/schemas/LocalObjectReference"

Volume:
type: object
description: Volume represents a named volume in a pod that
Expand Down Expand Up @@ -10423,6 +10443,8 @@ components:
$ref: "#/components/schemas/AzureDiskVolumeSource"
configMap:
$ref: "#/components/schemas/ConfigMapVolumeSource"
csi:
$ref: "#/components/schemas/CSIVolumeSource"
required:
- name

Expand Down
21 changes: 21 additions & 0 deletions pkg/api/v1/testkube/model_csi_volume_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Testkube API
*
* Testkube provides a Kubernetes-native framework for test definition, execution and results
*
* API version: 1.0.0
* Contact: [email protected]
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package testkube

// Represents a source location of a volume to mount, managed by an external CSI driver
type CsiVolumeSource struct {
// driver is the name of the CSI driver that handles this volume.
Driver string `json:"driver,omitempty"`
ReadOnly *BoxedBoolean `json:"readOnly,omitempty"`
FsType *BoxedString `json:"fsType,omitempty"`
// volumeAttributes stores driver-specific properties that are passed to the CSI driver. Consult your driver's documentation for supported values.
VolumeAttributes map[string]string `json:"volumeAttributes,omitempty"`
NodePublishSecretRef *LocalObjectReference `json:"nodePublishSecretRef,omitempty"`
}
1 change: 1 addition & 0 deletions pkg/api/v1/testkube/model_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ type Volume struct {
AzureFile *AzureFileVolumeSource `json:"azureFile,omitempty"`
AzureDisk *AzureDiskVolumeSource `json:"azureDisk,omitempty"`
ConfigMap *ConfigMapVolumeSource `json:"configMap,omitempty"`
Csi *CsiVolumeSource `json:"csi,omitempty"`
}
10 changes: 10 additions & 0 deletions pkg/mapper/testworkflows/kube_openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ func MapAzureDiskVolumeSourceKubeToAPI(v corev1.AzureDiskVolumeSource) testkube.
}
}

func MapCSIVolumeSourceKubeToAPI(v corev1.CSIVolumeSource) testkube.CsiVolumeSource {
return testkube.CsiVolumeSource{
Driver: v.Driver,
ReadOnly: MapBoolToBoxedBoolean(v.ReadOnly),
FsType: MapStringToBoxedString(v.FSType),
VolumeAttributes: v.VolumeAttributes,
NodePublishSecretRef: common.MapPtr(v.NodePublishSecretRef, MapLocalObjectReferenceKubeToAPI),
}
}
func MapVolumeKubeToAPI(v corev1.Volume) testkube.Volume {
// TODO: Add rest of VolumeSource types in future,
// so they will be recognized by JSON API and persisted with Execution.
Expand All @@ -216,6 +225,7 @@ func MapVolumeKubeToAPI(v corev1.Volume) testkube.Volume {
AzureFile: common.MapPtr(v.AzureFile, MapAzureFileVolumeSourceKubeToAPI),
ConfigMap: common.MapPtr(v.ConfigMap, MapConfigMapVolumeSourceKubeToAPI),
AzureDisk: common.MapPtr(v.AzureDisk, MapAzureDiskVolumeSourceKubeToAPI),
Csi: common.MapPtr(v.CSI, MapCSIVolumeSourceKubeToAPI),
}
}

Expand Down
11 changes: 11 additions & 0 deletions pkg/mapper/testworkflows/openapi_kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,16 @@ func MapAzureDiskVolumeSourceAPIToKube(v testkube.AzureDiskVolumeSource) corev1.
}
}

func MapCSIVolumeSourceAPIToKube(v testkube.CsiVolumeSource) corev1.CSIVolumeSource {
return corev1.CSIVolumeSource{
Driver: v.Driver,
ReadOnly: MapBoxedBooleanToBool(v.ReadOnly),
FSType: MapBoxedStringToString(v.FsType),
VolumeAttributes: v.VolumeAttributes,
NodePublishSecretRef: common.MapPtr(v.NodePublishSecretRef, MapLocalObjectReferenceAPIToKube),
}
}

func MapVolumeAPIToKube(v testkube.Volume) corev1.Volume {
// TODO: Add rest of VolumeSource types in future,
// so they will be recognized by JSON API and persisted with Execution.
Expand All @@ -493,6 +503,7 @@ func MapVolumeAPIToKube(v testkube.Volume) corev1.Volume {
AzureFile: common.MapPtr(v.AzureFile, MapAzureFileVolumeSourceAPIToKube),
ConfigMap: common.MapPtr(v.ConfigMap, MapConfigMapVolumeSourceAPIToKube),
AzureDisk: common.MapPtr(v.AzureDisk, MapAzureDiskVolumeSourceAPIToKube),
CSI: common.MapPtr(v.Csi, MapCSIVolumeSourceAPIToKube),
},
}
}
Expand Down

0 comments on commit 1f99e13

Please sign in to comment.