536 dir are read recursivly now
@@ -58,15 +58,9 @@ func Command() *cobra.Command {
return cmd
}
-func getPolicies(paths []string) ([]*v1.ClusterPolicy, error) {
- var policies = make([]*v1.ClusterPolicy, 0, len(paths))
- for _, path := range paths {
- fileDesc, err := os.Stat(path)
- if err != nil {
- return nil, err
- }
+func getPoliciesInDir(path string) ([]*v1.ClusterPolicy, error) {
+ var policies []*v1.ClusterPolicy
- if fileDesc.IsDir() {
files, err := ioutil.ReadDir(path)
if err != nil {
return nil, err
@@ -74,9 +68,13 @@ func getPolicies(paths []string) ([]*v1.ClusterPolicy, error) {
for _, file := range files {
if file.IsDir() {
- continue
+ policiesFromDir, err := getPoliciesInDir(filepath.Join(path, file.Name()))
+ if err != nil {
+ return nil, err
}
+ policies = append(policies, policiesFromDir...)
+ } else {
policy, err := getPolicy(filepath.Join(path, file.Name()))
if err != nil {
return nil, err
@@ -84,7 +82,28 @@ func getPolicies(paths []string) ([]*v1.ClusterPolicy, error) {
policies = append(policies, policy)
}
+ }
+
+ return policies, nil
+}
+
+func getPolicies(paths []string) ([]*v1.ClusterPolicy, error) {
+ var policies = make([]*v1.ClusterPolicy, 0, len(paths))
+ for _, path := range paths {
+ path = filepath.Clean(path)
+
+ fileDesc, err := os.Stat(path)
+ if err != nil {
+ return nil, err
+ }
+
+ if fileDesc.IsDir() {
+ policiesFromDir, err := getPoliciesInDir(path)
+ if err != nil {
+ return nil, err
+ }
+ policies = append(policies, policiesFromDir...)
} else {
policy, err := getPolicy(path)
if err != nil {
