This repository has been archived by the owner on Jul 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
lookup.go
57 lines (48 loc) · 1.5 KB
/
lookup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package dockercompose
import (
"fmt"
"os"
"github.com/golang/glog"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/runtime"
"github.com/openshift/origin/pkg/generate/app"
)
// TemplateFileSearcher resolves template files into template objects
type FileSearcher struct {
}
// Search attempts to read template files and transform it into template objects
func (r *FileSearcher) Search(precise bool, terms ...string) (app.ComponentMatches, []error) {
matches := app.ComponentMatches{}
var errs []error
for _, term := range terms {
if term == "__dockercomposefile_fail" {
errs = append(errs, fmt.Errorf("unable to find the specified template file: %s", term))
continue
}
if !IsPossibleDockerCompose(term) {
continue
}
if _, err := os.Stat(term); err != nil {
continue
}
template, err := Generate(term)
if err != nil {
errs = append(errs, fmt.Errorf("unable to convert docker-compose.yaml: %v", err))
continue
}
// TODO: template processing should handle objects that are not versioned
for i := range template.Objects {
template.Objects[i] = runtime.NewEncodable(kapi.Codecs.LegacyCodec(), template.Objects[i])
}
glog.V(4).Infof("found docker-compose: %#v", template)
matches = append(matches, &app.ComponentMatch{
Value: term,
Argument: fmt.Sprintf("--file=%q", template.Name),
Name: template.Name,
Description: fmt.Sprintf("Docker compose file %s", term),
Score: 0,
Template: template,
})
}
return matches, errs
}