diff --git a/CHANGELOG.md b/CHANGELOG.md index 28e81b7..0a8b4aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/hook/handler.go b/hook/handler.go index 0d51b21..2edbef7 100644 --- a/hook/handler.go +++ b/hook/handler.go @@ -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: diff --git a/k8s/file/file_provider.go b/k8s/file/file_provider.go index 6279474..6a7ba19 100644 --- a/k8s/file/file_provider.go +++ b/k8s/file/file_provider.go @@ -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) }