Skip to content

Commit

Permalink
kube fs source support .gz file
Browse files Browse the repository at this point in the history
  • Loading branch information
YonkaFang committed Dec 12, 2023
1 parent 22f5add commit 2d5d6b6
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions galley/pkg/config/source/kube/fs/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
package fs

import (
"bytes"
"compress/gzip"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"sync"
Expand All @@ -30,10 +32,17 @@ import (
"istio.io/libistio/pkg/config/schema/collection"
)

const (
extYaml = ".yaml"
extYml = ".yml"
extGz = ".gz"
)

var (
supportedExtensions = map[string]bool{
".yaml": true,
".yml": true,
extYaml: true,
extYml: true,
extGz: true,
}
)

Expand Down Expand Up @@ -137,17 +146,30 @@ func (s *source) reload() {
return err
}

if mode := info.Mode() & os.ModeType; !supportedExtensions[filepath.Ext(path)] || (mode != 0 && mode != os.ModeSymlink) {
ext := filepath.Ext(path)
if mode := info.Mode() & os.ModeType; !supportedExtensions[ext] || (mode != 0 && mode != os.ModeSymlink) {
return nil
}

scope.Source.Infof("[%s] Discovered file: %q", s.name, path)

data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
scope.Source.Infof("[%s] Error reading file %q: %v", s.name, path, err)
return err
}
if ext == extGz {
reader, err := gzip.NewReader(bytes.NewBuffer(data))
if err != nil {
scope.Source.Infof("[%s] Error reading file %q: %v", s.name, path, err)
return err
}
data, err = io.ReadAll(reader)
if err != nil {
scope.Source.Infof("[%s] Error reading file %q: %v", s.name, path, err)
return err
}
}

if err := s.s.ApplyContent(path, string(data)); err != nil {
scope.Source.Errorf("[%s] Error applying file contents(%q): %v", s.name, path, err)
Expand Down

0 comments on commit 2d5d6b6

Please sign in to comment.