Skip to content
Open
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
56 changes: 51 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,48 @@ 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.ActorMetadata != nil:
actorMetadata := &ateletpb.ActorMetadataDataSource{}
for _, item := range dataSource.ActorMetadata.Items {
actorMetadata.Items = append(actorMetadata.Items, &ateletpb.ActorMetadataItem{
Field: toAteletActorMetadataField(item.Field),
Path: item.Path,
})
}
ateletSystemInfo.DataSources = append(ateletSystemInfo.DataSources, &ateletpb.SystemInfoDataSource{
DataSource: &ateletpb.SystemInfoDataSource_ActorMetadata{
ActorMetadata: actorMetadata,
},
})
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 +173,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 Expand Up @@ -170,6 +200,22 @@ func isVolumeMounted(volumeName string, template *atev1alpha1.ActorTemplate) boo
// toAteletReadyz projects the CRD readyz field onto the ateletpb wire type.
// Returns nil when the source is nil so containers without a probe stay
// unchanged on the wire.
// toAteletActorMetadataField projects the CRD field selector onto the atelet
// wire enum. Unknown values map to UNSPECIFIED, which atelet skips; CRD enum
// validation makes that unreachable for stored templates.
func toAteletActorMetadataField(in atev1alpha1.ActorMetadataField) ateletpb.ActorMetadataField {
switch in {
case atev1alpha1.ActorMetadataFieldName:
return ateletpb.ActorMetadataField_ACTOR_METADATA_FIELD_NAME
case atev1alpha1.ActorMetadataFieldAtespace:
return ateletpb.ActorMetadataField_ACTOR_METADATA_FIELD_ATESPACE
case atev1alpha1.ActorMetadataFieldUID:
return ateletpb.ActorMetadataField_ACTOR_METADATA_FIELD_UID
default:
return ateletpb.ActorMetadataField_ACTOR_METADATA_FIELD_UNSPECIFIED
}
}

func toAteletReadyz(in *atev1alpha1.ContainerReadyz) *ateletpb.Readyz {
if in == nil {
return nil
Expand Down
72 changes: 68 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,74 @@ func TestWorkloadSpecFromActorTemplate(t *testing.T) {
},
},
},
{
name: "converts SystemInfo volume with actorMetadata items",
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{
{ActorMetadata: &atev1alpha1.ActorMetadataDataSource{
Items: []atev1alpha1.ActorMetadataItem{
{Field: atev1alpha1.ActorMetadataFieldName, Path: "actor-name"},
{Field: atev1alpha1.ActorMetadataFieldAtespace, Path: "atespace"},
{Field: atev1alpha1.ActorMetadataFieldUID, Path: "identity/actor-uid"},
},
}},
},
},
},
},
},
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_ActorMetadata{
ActorMetadata: &ateletpb.ActorMetadataDataSource{
Items: []*ateletpb.ActorMetadataItem{
{Field: ateletpb.ActorMetadataField_ACTOR_METADATA_FIELD_NAME, Path: "actor-name"},
{Field: ateletpb.ActorMetadataField_ACTOR_METADATA_FIELD_ATESPACE, Path: "atespace"},
{Field: ateletpb.ActorMetadataField_ACTOR_METADATA_FIELD_UID, Path: "identity/actor-uid"},
},
},
}},
},
},
},
},
},
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 +171,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 +202,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 +600,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