From 44b936a9aa8ad772ed566e88a8d57ced787e5a6e Mon Sep 17 00:00:00 2001 From: Foysal Iqbal Date: Sat, 4 Apr 2020 01:16:13 -0400 Subject: [PATCH] add custom crds (#277) Signed-off-by: Foysal Iqbal --- pkg/api/apis.go | 12 ++++++++++++ pkg/qliksense/crds.go | 43 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/pkg/api/apis.go b/pkg/api/apis.go index 23cdb652..af7873d4 100644 --- a/pkg/api/apis.go +++ b/pkg/api/apis.go @@ -453,6 +453,18 @@ func (cr *QliksenseCR) SetEULA(value string) { cr.Spec.AddToConfigs("qliksense", "acceptEULA", value) } +// GetCustomCrdsPath get crds path if exist in the profile dir +func (cr *QliksenseCR) GetCustomCrdsPath() string { + if cr.Spec.ManifestsRoot == "" || cr.Spec.Profile == "" { + return "" + } + crdsPath := filepath.Join(cr.Spec.GetManifestsRoot(), "manifests", cr.Spec.Profile, "crds") + if _, err := os.Lstat(crdsPath); err != nil { + return "" + } + return crdsPath +} + // GetDecryptedCr it decrypts all the encrypted value and return a new CR func (qc *QliksenseConfig) GetDecryptedCr(cr *QliksenseCR) (*QliksenseCR, error) { newCr := &QliksenseCR{} diff --git a/pkg/qliksense/crds.go b/pkg/qliksense/crds.go index 73555f28..d0e4d051 100644 --- a/pkg/qliksense/crds.go +++ b/pkg/qliksense/crds.go @@ -19,12 +19,24 @@ func (q *Qliksense) ViewCrds(opts *CrdCommandOptions) error { fmt.Println("cannot get the current-context cr", err) return err } - if engineCRD, err := getQliksenseInitCrd(qcr); err != nil { + engineCRD, err := getQliksenseInitCrd(qcr) + if err != nil { return err - } else if opts.All { - fmt.Printf("%s\n%s", q.GetOperatorCRDString(), engineCRD) - } else { - fmt.Printf("%s", engineCRD) + } + customCrd, err := getCustomCrd(qcr) + if err != nil { + return nil + } + + fmt.Println(engineCRD) + if customCrd != "" { + fmt.Println("---") + fmt.Println(customCrd) + } + + if opts.All { + fmt.Println("---") + fmt.Printf("%s", q.GetOperatorCRDString()) } return nil } @@ -43,6 +55,14 @@ func (q *Qliksense) InstallCrds(opts *CrdCommandOptions) error { } else if err = qapi.KubectlApply(engineCRD, ""); err != nil { return err } + if customCrd, err := getCustomCrd(qcr); err != nil { + return err + } else if customCrd != "" { + if err = qapi.KubectlApply(customCrd, ""); err != nil { + return err + } + } + if opts.All { // install opeartor crd if err := qapi.KubectlApply(q.GetOperatorCRDString(), ""); err != nil { fmt.Println("cannot do kubectl apply on opeartor CRD", err) @@ -72,3 +92,16 @@ func getQliksenseInitCrd(qcr *qapi.QliksenseCR) (string, error) { } return string(qInitByte), nil } + +func getCustomCrd(qcr *qapi.QliksenseCR) (string, error) { + crdPath := qcr.GetCustomCrdsPath() + if crdPath == "" { + return "", nil + } + qInitByte, err := ExecuteKustomizeBuild(crdPath) + if err != nil { + fmt.Println("cannot generate custom crds", err) + return "", err + } + return string(qInitByte), nil +}