Skip to content

Commit

Permalink
add custom crds (#277)
Browse files Browse the repository at this point in the history
Signed-off-by: Foysal Iqbal <[email protected]>
  • Loading branch information
Foysal Iqbal authored Apr 4, 2020
1 parent 0e6a1ab commit 44b936a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
12 changes: 12 additions & 0 deletions pkg/api/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
43 changes: 38 additions & 5 deletions pkg/qliksense/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -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
}

0 comments on commit 44b936a

Please sign in to comment.