Update `make manifests` to emit CRD files in "nested" output format

Fix CRDs files expansion
This commit is contained in:
ichekrygin 2018-10-12 14:49:14 -07:00
parent 1db75c3e73
commit f85b5b28ab
5 changed files with 45 additions and 11 deletions

4
Gopkg.lock generated
View File

@ -847,7 +847,7 @@
version = "v0.1.2"
[[projects]]
digest = "1:4b9e106ec4da06d6d5787a5d5ac1c2f08a38fc5aff287375b98b95dbd42e7181"
digest = "1:ddebdab9c149e675ed4b4a054ede657d228854bc7c95b33caa08c11c07863004"
name = "sigs.k8s.io/controller-tools"
packages = [
"cmd/controller-gen",
@ -859,7 +859,7 @@
"pkg/util",
]
pruneopts = "T"
revision = "fe397b1c87ef4524abf55a7de80f223194146b5e"
revision = "41f36afa0662ee408687cfe70c13420ff2523b74"
source = "https://github.com/ichekrygin/controller-tools.git"
[[projects]]

View File

@ -30,7 +30,7 @@ required = [
[[override]]
name="sigs.k8s.io/controller-tools"
source = "https://github.com/ichekrygin/controller-tools.git"
revision = "fe397b1c87ef4524abf55a7de80f223194146b5e"
revision = "41f36afa0662ee408687cfe70c13420ff2523b74"
# For dependency below: Refer to issue https://github.com/golang/dep/issues/1799
[[override]]

2
Jenkinsfile vendored
View File

@ -58,7 +58,7 @@ pipeline {
always {
script {
sh 'make -j\$(nproc) clean'
sh 'make -j$(nproc) prune PRUNE_HOURS=48 PRUNE_KEEP=48'
sh 'make -j\$(nproc) prune PRUNE_HOURS=48 PRUNE_KEEP=48'
sh 'docker images'
}
}

View File

@ -53,4 +53,4 @@ include build/makelib/image.mk
# Generate manifests e.g. CRD, RBAC etc.
manifests:
go run vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go crd --output-dir cluster/charts/conductor/crds
go run vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go crd --output-dir cluster/charts/conductor/crds --nested

View File

@ -39,10 +39,11 @@ func NewTestEnv(namespace string, crds ...string) *TestEnv {
UseExistingCluster: UseExistingCluster(),
}
if !t.UseExistingCluster {
if err := CheckCRDFiles(crds); err != nil {
if crds, err := CheckCRDFiles(crds); err != nil {
log.Panic(err)
} else {
t.CRDDirectoryPaths = crds
}
t.CRDDirectoryPaths = crds
}
if len(namespace) == 0 {
namespace = "default"
@ -105,13 +106,46 @@ func UseExistingCluster() bool {
}
// CheckCRDFiles - validates that all crds files are found.
func CheckCRDFiles(crds []string) error {
func CheckCRDFiles(crds []string) ([]string, error) {
var rs []string
for _, path := range crds {
if _, err := os.Stat(path); os.IsNotExist(err) {
return err
_, err := os.Stat(path)
if os.IsNotExist(err) {
return nil, err
}
files, err := Expand(path)
if err != nil {
return nil, err
}
rs = append(rs, files...)
}
return nil
return rs, nil
}
// Expand recursively and returns list of all sub-directories (if any)
func Expand(path string) ([]string, error) {
var rs []string
fi, err := os.Stat(path)
if os.IsNotExist(err) {
return nil, err
}
if fi.Mode().IsDir() {
files, err := filepath.Glob(filepath.Join(path, "*"))
if err != nil {
return nil, err
}
for _, f := range files {
exp, err := Expand(f)
if err != nil {
return nil, err
}
rs = append(rs, exp...)
}
rs = append(rs, path)
}
return rs, nil
}
// CRDs path to project crds location