Skip to content

Commit

Permalink
feat(cmd/run): file size limitation
Browse files Browse the repository at this point in the history
Won't accept any resource/config file larger than 1MB, due to the limitation on K8S CustomResources

Ref apache#2003
  • Loading branch information
squakez committed Jun 16, 2021
1 parent 2dc638d commit 9064de3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/cmd/run_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ func applyOption(config *RunConfigOption, integrationSpec *v1.IntegrationSpec,
}
integrationSpec.AddConfigurationAsResource(string(config.ConfigType), config.Value, string(resourceType), config.DestinationPath())
case ConfigOptionTypeFile:
// Don't allow a file size longer than 1 MiB
fileSize, err := fileSize(config.Value)
printSize := fmt.Sprintf("%.2f", float64(fileSize)/Megabyte)
if err != nil {
return err
} else if fileSize > Megabyte {
return fmt.Errorf("you cannot provide a file larger than 1 MB (it was %s MB), check configmap option or --volume instead", printSize)
}
// Don't allow a binary non compressed resource
rawData, contentType, err := loadRawContent(config.Value)
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions pkg/cmd/util_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,24 @@ import (
"io/ioutil"
"net/http"
"net/url"
"os"
"regexp"
"strings"
)

const (
Megabyte = 1 << 20
Kilobyte = 1 << 10
)

func fileSize(source string) (int64, error) {
fi, err := os.Stat(source)
if err != nil {
return -1, err
}
return fi.Size(), nil
}

func loadRawContent(source string) ([]byte, string, error) {
var content []byte
var err error
Expand Down

0 comments on commit 9064de3

Please sign in to comment.