Skip to content

Commit

Permalink
feat(web): return extra files on /info endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
nettoclaudio committed Jul 25, 2022
1 parent 484d828 commit a595f4c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
20 changes: 20 additions & 0 deletions internal/pkg/rpaas/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,20 +850,27 @@ func (m *k8sRpaasManager) GetExtraFiles(ctx context.Context, instanceName string
if err != nil {
return nil, err
}

extraFiles, err := m.getExtraFiles(ctx, *instance)
if err != nil && IsNotFoundError(err) {
return []File{}, nil
}
if err != nil {
return nil, err
}

files := []File{}
for key, path := range instance.Spec.ExtraFiles.Files {
files = append(files, File{
Name: path,
Content: extraFiles.BinaryData[key],
})
}

sort.Slice(files, func(i, j int) bool {
return files[i].Name < files[j].Name
})

return files, nil
}

Expand Down Expand Up @@ -1184,6 +1191,7 @@ func (m *k8sRpaasManager) getExtraFiles(ctx context.Context, instance v1alpha1.R
if instance.Spec.ExtraFiles == nil {
return nil, &NotFoundError{Msg: "there are no extra files"}
}

configMapName := types.NamespacedName{
Name: instance.Spec.ExtraFiles.Name,
Namespace: instance.Namespace,
Expand Down Expand Up @@ -1672,6 +1680,18 @@ func (m *k8sRpaasManager) GetInstanceInfo(ctx context.Context, instanceName stri
}
}

extraFiles, err := m.GetExtraFiles(ctx, instanceName)
if err != nil {
return nil, err
}

for _, f := range extraFiles {
info.ExtraFiles = append(info.ExtraFiles, clientTypes.RpaasFile{
Name: f.Name,
Content: f.Content,
})
}

routes, err := m.GetRoutes(ctx, instanceName)
if err != nil {
return nil, err
Expand Down
32 changes: 32 additions & 0 deletions internal/pkg/rpaas/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4726,6 +4726,38 @@ func Test_k8sRpaasManager_GetInstanceInfo(t *testing.T) {
return info
},
},

"w/ extra files": {
resources: []runtime.Object{
&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "my-instance-extra-files",
Namespace: "rpaasv2",
},
BinaryData: map[string][]byte{
"waf.cfg": []byte("My WAF rules :P"),
"binary.exe": {66, 55, 10, 0},
},
},
},
instance: func(i v1alpha1.RpaasInstance) v1alpha1.RpaasInstance {
i.Spec.ExtraFiles = &nginxv1alpha1.FilesRef{
Name: "my-instance-extra-files",
Files: map[string]string{
"waf.cfg": "waf.cfg",
"binary.exe": "binary.exe",
},
}
return i
},
expected: func(info clientTypes.InstanceInfo) clientTypes.InstanceInfo {
info.ExtraFiles = []clientTypes.RpaasFile{
{Name: "binary.exe", Content: []byte{66, 55, 10, 0}},
{Name: "waf.cfg", Content: []byte("My WAF rules :P")},
}
return info
},
},
}

for name, tt := range tests {
Expand Down

0 comments on commit a595f4c

Please sign in to comment.