Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions cmd/ateapi/internal/controlapi/workload_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,43 @@ func workloadSpecFromActorTemplate(actorTemplate *atev1alpha1.ActorTemplate, act
PauseImage: actorTemplate.Spec.PauseImage,
}

// add volumes
// Convert volumes to atelet's representation. ActorTemplate validation has
// already ensured that only one source is set.
for _, vol := range actorTemplate.Spec.Volumes {
// volume is durable-dir type
if vol.VolumeSource.DurableDir != nil {
switch {
case vol.VolumeSource.DurableDir != nil:
workloadSpec.Volumes = append(workloadSpec.Volumes, &ateletpb.Volume{
Name: vol.Name,
Type: ateletpb.VolumeType_VOLUME_TYPE_DURABLE_DIR,
Source: &ateletpb.Volume_DurableDir{
DurableDir: &ateletpb.DurableDirVolume{},
},
})

case vol.VolumeSource.SystemInfo != nil:
ateletSystemInfo := &ateletpb.SystemInfoVolume{}
for _, dataSource := range vol.VolumeSource.SystemInfo.DataSources {
switch {
case dataSource.ActorIdentity != nil:
ateletSystemInfo.DataSources = append(ateletSystemInfo.DataSources, &ateletpb.SystemInfoDataSource{
DataSource: &ateletpb.SystemInfoDataSource_ActorIdentity{
ActorIdentity: &ateletpb.ActorIdentityDataSource{
Path: dataSource.ActorIdentity.Path,
},
},
})
default:
continue // Drop unrecognized data sources
}
}
workloadSpec.Volumes = append(workloadSpec.Volumes, &ateletpb.Volume{
Name: vol.Name,
Source: &ateletpb.Volume_SystemInfo{
SystemInfo: ateletSystemInfo,
},
})

default:
continue // Drop unrecognized volumes.
}
}

Expand Down Expand Up @@ -142,7 +168,6 @@ func appendExternalVolumes(workloadSpec *ateletpb.WorkloadSpec, template *atev1a
}
workloadSpec.Volumes = append(workloadSpec.Volumes, &ateletpb.Volume{
Name: vol.Name,
Type: ateletpb.VolumeType_VOLUME_TYPE_EXTERNAL,
Source: &ateletpb.Volume_External{
External: &ateletpb.ExternalVolumeSource{
StorageVolumeId: storageVolID,
Expand Down
64 changes: 60 additions & 4 deletions cmd/ateapi/internal/controlapi/workload_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func TestWorkloadSpecFromActorTemplate(t *testing.T) {
Volumes: []*ateletpb.Volume{
{
Name: "home",
Type: ateletpb.VolumeType_VOLUME_TYPE_DURABLE_DIR,
Source: &ateletpb.Volume_DurableDir{DurableDir: &ateletpb.DurableDirVolume{}},
},
},
Expand All @@ -80,6 +79,66 @@ func TestWorkloadSpecFromActorTemplate(t *testing.T) {
},
},
},
{
name: "converts SystemInfo volume with ActorIdentity data sources",
template: &atev1alpha1.ActorTemplate{
ObjectMeta: metav1.ObjectMeta{Name: "tmpl1", Namespace: "agent-ns"},
Spec: atev1alpha1.ActorTemplateSpec{
PauseImage: "pause",
Volumes: []atev1alpha1.Volume{
{
Name: "system-info",
VolumeSource: atev1alpha1.VolumeSource{
SystemInfo: &atev1alpha1.SystemInfoVolumeSource{
DataSources: []atev1alpha1.SystemInfoDataSource{
{ActorIdentity: &atev1alpha1.ActorIdentityDataSource{Path: "actor-id"}},
{ActorIdentity: &atev1alpha1.ActorIdentityDataSource{Path: "identity/name"}},
},
},
},
},
},
Containers: []atev1alpha1.Container{
{
Name: "main",
Image: "main",
VolumeMounts: []atev1alpha1.VolumeMount{
{Name: "system-info", MountPath: "/run/ate"},
},
},
},
},
},
want: &ateletpb.WorkloadSpec{
PauseImage: "pause",
Volumes: []*ateletpb.Volume{
{
Name: "system-info",
Source: &ateletpb.Volume_SystemInfo{
SystemInfo: &ateletpb.SystemInfoVolume{
DataSources: []*ateletpb.SystemInfoDataSource{
{DataSource: &ateletpb.SystemInfoDataSource_ActorIdentity{
ActorIdentity: &ateletpb.ActorIdentityDataSource{Path: "actor-id"},
}},
{DataSource: &ateletpb.SystemInfoDataSource_ActorIdentity{
ActorIdentity: &ateletpb.ActorIdentityDataSource{Path: "identity/name"},
}},
},
},
},
},
},
Containers: []*ateletpb.Container{
{
Name: "main",
Image: "main",
VolumeMounts: []*ateletpb.VolumeMount{
{Name: "system-info", MountPath: "/run/ate"},
},
},
},
},
},
{
name: "skips non-DurableDir volumes",
template: &atev1alpha1.ActorTemplate{
Expand All @@ -104,7 +163,6 @@ func TestWorkloadSpecFromActorTemplate(t *testing.T) {
Volumes: []*ateletpb.Volume{
{
Name: "home",
Type: ateletpb.VolumeType_VOLUME_TYPE_DURABLE_DIR,
Source: &ateletpb.Volume_DurableDir{DurableDir: &ateletpb.DurableDirVolume{}},
},
},
Expand Down Expand Up @@ -136,7 +194,6 @@ func TestWorkloadSpecFromActorTemplate(t *testing.T) {
Volumes: []*ateletpb.Volume{
{
Name: "home",
Type: ateletpb.VolumeType_VOLUME_TYPE_DURABLE_DIR,
Source: &ateletpb.Volume_DurableDir{DurableDir: &ateletpb.DurableDirVolume{}},
},
},
Expand Down Expand Up @@ -535,7 +592,6 @@ func TestAppendExternalVolumes(t *testing.T) {
Volumes: []*ateletpb.Volume{
{
Name: "vol-1",
Type: ateletpb.VolumeType_VOLUME_TYPE_EXTERNAL,
Source: &ateletpb.Volume_External{
External: &ateletpb.ExternalVolumeSource{
StorageVolumeId: "vol-gce-pd-123",
Expand Down
Loading
Loading