containers creates entities from files with the ContainerExtension
(objects []deploy.KubeObject)
| 160 | |
| 161 | // containers creates entities from files with the ContainerExtension |
| 162 | func (fs FileSource) containers(objects []deploy.KubeObject) (containers []entity.Entity, err error) { |
| 163 | info, err := os.Stat(string(fs)) |
| 164 | if err != nil { |
| 165 | return |
| 166 | } |
| 167 | |
| 168 | // check if file |
| 169 | if !info.IsDir() { |
| 170 | kubeCtr, err := unmarshalContainer(string(fs)) |
| 171 | if err != nil { |
| 172 | return nil, err |
| 173 | } |
| 174 | |
| 175 | ctr, err := entity.NewContainer(kubeCtr, kube.ObjectMeta{}, string(fs), objects...) |
| 176 | if err != nil { |
| 177 | return nil, err |
| 178 | } |
| 179 | |
| 180 | return []entity.Entity{ctr}, nil |
| 181 | } |
| 182 | |
| 183 | dir, err := os.Open(string(fs)) |
| 184 | if err != nil { |
| 185 | return |
| 186 | } |
| 187 | defer dir.Close() |
| 188 | |
| 189 | files, err := dir.Readdir(-1) |
| 190 | if err != nil { |
| 191 | return |
| 192 | } |
| 193 | |
| 194 | for _, file := range files { |
| 195 | if file.Mode().IsRegular() { |
| 196 | if filepath.Ext(file.Name()) == ContainerExtension { |
| 197 | filename := path.Join(string(fs), file.Name()) |
| 198 | |
| 199 | kubeCtr, err := unmarshalContainer(filename) |
| 200 | if err != nil { |
| 201 | return nil, err |
| 202 | } |
| 203 | |
| 204 | ctr, err := entity.NewContainer(kubeCtr, kube.ObjectMeta{}, filename) |
| 205 | if err != nil { |
| 206 | return nil, err |
| 207 | } |
| 208 | |
| 209 | containers = append(containers, ctr) |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | return containers, nil |
| 214 | } |
| 215 | |
| 216 | func walkPathForObjects(path string, fn resource.VisitorFunc) error { |
| 217 | f := kubectl.NewFactory(nil) |
no test coverage detected