Skip to content

Commit

Permalink
Merge pull request #31 from seibert-media/fix-parse-multi-line-teamvault
Browse files Browse the repository at this point in the history
add logging
  • Loading branch information
kwiesmueller committed May 3, 2018
2 parents 48a9a26 + 9c7fdc4 commit d666a8d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Please choose versions by [Semantic Versioning](http://semver.org/).
* MINOR version when you add functionality in a backwards-compatible manner, and
* PATCH version when you make backwards-compatible bug fixes.

## 1.1.6

- Log Yaml and Json content if parse failure

## 1.1.5

- Prevent parallel sync
Expand Down
1 change: 0 additions & 1 deletion hook/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func (h *handler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
glog.Warningf("sync changes failed: %v", err)
}
glog.V(1).Info("sync changes completed successful")

}()
fmt.Fprintln(resp, "sync triggerd")
default:
Expand Down
26 changes: 19 additions & 7 deletions k8s/file/file_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,46 @@ func (p *provider) GetObjects(namespace k8s.Namespace) ([]k8s_runtime.Object, er
glog.V(3).Infof("skip directory: %s", path)
return nil
}
content, err := ioutil.ReadFile(path)
yamlTemplate, err := ioutil.ReadFile(path)
if err != nil {
return fmt.Errorf("read file %s failed: %v", path, err)
}
if glog.V(6) {
glog.Infof("yaml: %s", yamlTemplate)
}

content, err = p.parser.Parse(content)
yamlContent, err := p.parser.Parse(yamlTemplate)
if err != nil {
if glog.V(4) {
glog.Infof("content: %s", string(yamlTemplate))
}
return fmt.Errorf("parse content of file %s failed: %v", path, err)
}
if glog.V(6) {
glog.Infof("yaml %s", content)
glog.Infof("parsed: %s", yamlContent)
}

content, err = yaml.YAMLToJSON(content)
jsonContent, err := yaml.YAMLToJSON(yamlContent)
if err != nil {
if glog.V(4) {
glog.Infof("content: %s", string(yamlContent))
}
return fmt.Errorf("convert yaml to json for file %s failed: %v", path, err)
}
if glog.V(6) {
glog.Infof("json %s", content)
glog.Infof("json: %s", jsonContent)
}

obj, err := kind(content)
obj, err := kind(jsonContent)
if err != nil {
if glog.V(4) {
glog.Infof("content: %s", string(jsonContent))
}
return fmt.Errorf("create object by content for file %s failed: %v", path, err)
}

glog.V(4).Infof("found kind %v", obj.GetObjectKind())
if obj, _, err = k8s_unstructured.UnstructuredJSONScheme.Decode(content, nil, obj); err != nil {
if obj, _, err = k8s_unstructured.UnstructuredJSONScheme.Decode(jsonContent, nil, obj); err != nil {
return fmt.Errorf("unmarshal to object for file %s failed: %v", path, err)
}

Expand Down

0 comments on commit d666a8d

Please sign in to comment.