Skip to content

Commit

Permalink
fix logger package for compress
Browse files Browse the repository at this point in the history
Signed-off-by: Zemtsov Vladimir <vl.zemtsov@gmail.com>
  • Loading branch information
zvlb authored and ahma committed Nov 16, 2022
1 parent 1efdb1c commit 6b4edd1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions pkg/compression/compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ package compression
import (
"bytes"
"compress/gzip"
"log"

"github.com/go-logr/logr"
)

func CompressString(str string) []byte {
func CompressString(str string, log logr.Logger) []byte {
var b bytes.Buffer
gz := gzip.NewWriter(&b)
if _, err := gz.Write([]byte(str)); err != nil {
log.Fatal(err)
log.Error(err, "Failed to compress string")
}

if err := gz.Close(); err != nil {
log.Fatal(err)
log.Error(err, "Failed to close writer for compress string")
}

return b.Bytes()
Expand Down
6 changes: 3 additions & 3 deletions pkg/resources/fluentd/appconfigmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (r *Reconciler) appConfigSecret() (runtime.Object, reconciler.DesiredState,

if r.Logging.Spec.FluentdSpec.CompressConfigFile {
AppConfigKeyCompress := AppConfigKey + ".gz"
data[AppConfigKeyCompress] = compression.CompressString(*r.config)
data[AppConfigKeyCompress] = compression.CompressString(*r.config, r.Log)
} else {
data[AppConfigKey] = []byte(*r.config)
}
Expand Down Expand Up @@ -206,7 +206,7 @@ func (r *Reconciler) newCheckSecret(hashKey string) (*corev1.Secret, error) {
}
if r.Logging.Spec.FluentdSpec.CompressConfigFile {
ConfigCheckKeyCompress := ConfigCheckKey + ".gz"
data[ConfigCheckKeyCompress] = compression.CompressString(*r.config)
data[ConfigCheckKeyCompress] = compression.CompressString(*r.config, r.Log)
} else {
data[ConfigCheckKey] = []byte(*r.config)
}
Expand All @@ -222,7 +222,7 @@ func (r *Reconciler) newCheckSecretAppConfig(hashKey string) (*corev1.Secret, er

if r.Logging.Spec.FluentdSpec.CompressConfigFile {
ConfigCheckKeyCompress := ConfigCheckKey + ".gz"
data[ConfigCheckKeyCompress] = compression.CompressString(*r.config)
data[ConfigCheckKeyCompress] = compression.CompressString(*r.config, r.Log)
} else {
data[ConfigCheckKey] = []byte(*r.config)
}
Expand Down

0 comments on commit 6b4edd1

Please sign in to comment.