Compare commits
1 Commits
random-fix
...
v0.9.19
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34d35909a4 |
@@ -37,9 +37,6 @@ func pfDnsCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
fmt.Printf("Preflight DNS check FAILED\n")
|
||||
log.Fatal(err)
|
||||
}
|
||||
if namespace == "" {
|
||||
namespace = "default"
|
||||
}
|
||||
if err = qp.CheckDns(namespace, kubeConfigContents); err != nil {
|
||||
fmt.Println(err)
|
||||
fmt.Print("Preflight DNS check FAILED\n")
|
||||
@@ -97,9 +94,6 @@ func pfAllChecksCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
fmt.Printf("Running preflight check suite has FAILED...\n")
|
||||
log.Fatal()
|
||||
}
|
||||
if namespace == "" {
|
||||
namespace = "default"
|
||||
}
|
||||
qp.RunAllPreflightChecks(namespace, kubeConfigContents, mongodbUrl)
|
||||
return nil
|
||||
|
||||
@@ -127,9 +121,6 @@ func pfDeploymentCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
fmt.Printf("Preflight deployment check FAILED\n")
|
||||
log.Fatal(err)
|
||||
}
|
||||
if namespace == "" {
|
||||
namespace = "default"
|
||||
}
|
||||
if err = qp.CheckDeployment(namespace, kubeConfigContents); err != nil {
|
||||
fmt.Println(err)
|
||||
fmt.Print("Preflight deploy check FAILED\n")
|
||||
@@ -158,9 +149,6 @@ func pfServiceCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
fmt.Printf("Preflight service check FAILED\n")
|
||||
log.Fatal(err)
|
||||
}
|
||||
if namespace == "" {
|
||||
namespace = "default"
|
||||
}
|
||||
if err = qp.CheckService(namespace, kubeConfigContents); err != nil {
|
||||
fmt.Println(err)
|
||||
fmt.Print("Preflight service check FAILED\n")
|
||||
@@ -189,9 +177,6 @@ func pfPodCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
fmt.Printf("Preflight pod check FAILED\n")
|
||||
log.Fatal(err)
|
||||
}
|
||||
if namespace == "" {
|
||||
namespace = "default"
|
||||
}
|
||||
if err = qp.CheckPod(namespace, kubeConfigContents); err != nil {
|
||||
fmt.Println(err)
|
||||
fmt.Print("Preflight pod check FAILED\n")
|
||||
@@ -287,8 +272,8 @@ func pfCreateServiceAccountCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
return preflightServiceAccountCmd
|
||||
}
|
||||
|
||||
func pfCreateAuthCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
var preflightCreateAuthCmd = &cobra.Command{
|
||||
func pfCreateRBCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
var preflightCreateRBCmd = &cobra.Command{
|
||||
Use: "authcheck",
|
||||
Short: "preflight authcheck",
|
||||
Long: `perform preflight authcheck that combines the role, rolebinding and serviceaccount checks`,
|
||||
@@ -312,7 +297,7 @@ func pfCreateAuthCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
return nil
|
||||
},
|
||||
}
|
||||
return preflightCreateAuthCmd
|
||||
return preflightCreateRBCmd
|
||||
}
|
||||
|
||||
func pfMongoCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
@@ -333,9 +318,6 @@ func pfMongoCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
fmt.Printf("Preflight mongo check FAILED\n")
|
||||
log.Fatal(err)
|
||||
}
|
||||
if namespace == "" {
|
||||
namespace = "default"
|
||||
}
|
||||
if err = qp.CheckMongo(kubeConfigContents, namespace, mongodbUrl); err != nil {
|
||||
fmt.Println(err)
|
||||
fmt.Print("Preflight mongo check FAILED\n")
|
||||
|
||||
@@ -212,7 +212,7 @@ func rootCmd(p *qliksense.Qliksense) *cobra.Command {
|
||||
preflightCmd.AddCommand(pfCreateRoleCheckCmd(p))
|
||||
preflightCmd.AddCommand(pfCreateRoleBindingCheckCmd(p))
|
||||
preflightCmd.AddCommand(pfCreateServiceAccountCheckCmd(p))
|
||||
preflightCmd.AddCommand(pfCreateAuthCheckCmd(p))
|
||||
preflightCmd.AddCommand(pfCreateRBCheckCmd(p))
|
||||
|
||||
cmd.AddCommand(preflightCmd)
|
||||
cmd.AddCommand(loadCrFile(p))
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -69,20 +68,23 @@ func ProcessConfigArgs(args []string) ([]*ServiceKeyValue, error) {
|
||||
err := fmt.Errorf("No args were provided. Please provide args to configure the current context")
|
||||
return nil, err
|
||||
}
|
||||
notValidErr := fmt.Errorf("Please provide valid args for this command")
|
||||
resultSvcKV := make([]*ServiceKeyValue, len(args))
|
||||
re1 := regexp.MustCompile(`([\w\-]{1,}).([\w\-]{1,})=("*[\w\-?=_/:0-9\.]+"*)`)
|
||||
// qliksense.mongodb=somethig
|
||||
for i, arg := range args {
|
||||
LogDebugMessage("Arg received: %s", arg)
|
||||
result := re1.FindStringSubmatch(arg)
|
||||
// check if result array's length is == 4 (index 0 - is the full match & indices 1,2,3- are the fields we need)
|
||||
if len(result) != 4 {
|
||||
err := fmt.Errorf("Please provide valid args for this command")
|
||||
return nil, err
|
||||
first := strings.SplitN(arg, "=", 2)
|
||||
if len(first) != 2 {
|
||||
return nil, notValidErr
|
||||
}
|
||||
second := strings.SplitN(first[0], ".", 2)
|
||||
if len(second) != 2 {
|
||||
return nil, notValidErr
|
||||
}
|
||||
resultSvcKV[i] = &ServiceKeyValue{
|
||||
SvcName: result[1],
|
||||
Key: result[2],
|
||||
Value: strings.ReplaceAll(result[3], `"`, ""),
|
||||
SvcName: second[0],
|
||||
Key: second[1],
|
||||
Value: strings.ReplaceAll(first[1], `"`, ""),
|
||||
}
|
||||
}
|
||||
return resultSvcKV, nil
|
||||
|
||||
@@ -11,10 +11,11 @@ func TestProcessConfigArgs(t *testing.T) {
|
||||
"test-dash.dash-key=value-dash",
|
||||
"test-dot.dot-key=127.0.0.1",
|
||||
"test123.key123=value123",
|
||||
"test-equal.keyequal=newvalue=@hj",
|
||||
}
|
||||
expectedKeys := []string{"mongodb", "test", "dash-key", "dot-key", "key123"}
|
||||
expectedValue := []string{"mongouri://something?ffall", "value_under", "value-dash", "127.0.0.1", "value123"}
|
||||
exppectedSvc := []string{"qliksense", "test_under", "test-dash", "test-dot", "test123"}
|
||||
expectedKeys := []string{"mongodb", "test", "dash-key", "dot-key", "key123", "keyequal"}
|
||||
expectedValue := []string{"mongouri://something?ffall", "value_under", "value-dash", "127.0.0.1", "value123", "newvalue=@hj"}
|
||||
exppectedSvc := []string{"qliksense", "test_under", "test-dash", "test-dot", "test123", "test-equal"}
|
||||
sv, err := ProcessConfigArgs(args)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
|
||||
@@ -73,8 +73,8 @@ func mongoConnCheck(kubeConfigContents []byte, namespace, mongodbUrl string) err
|
||||
return err
|
||||
}
|
||||
|
||||
api.LogDebugMessage("stdout:", stdout)
|
||||
api.LogDebugMessage("stderr:", stderr)
|
||||
fmt.Println("stdout:", stdout)
|
||||
fmt.Println("stderr:", stderr)
|
||||
stringToCheck := "Implicit session"
|
||||
if strings.Contains(stdout, stringToCheck) || strings.Contains(stderr, stringToCheck) {
|
||||
fmt.Println("Preflight mongo check: PASSED")
|
||||
|
||||
@@ -2,11 +2,9 @@ package preflight
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/mitchellh/go-homedir"
|
||||
"github.com/qlik-oss/k-apis/pkg/cr"
|
||||
"github.com/qlik-oss/sense-installer/pkg/api"
|
||||
qapi "github.com/qlik-oss/sense-installer/pkg/api"
|
||||
"github.com/qlik-oss/sense-installer/pkg/qliksense"
|
||||
@@ -69,18 +67,6 @@ func (qp *QliksensePreflight) checkCreateEntity(namespace, entityToTest string)
|
||||
} else {
|
||||
kusDir = filepath.Join(mfroot, "manifests", currentCR.Spec.Profile)
|
||||
}
|
||||
|
||||
currentCR.SetName("random")
|
||||
currentCR.Spec.RotateKeys = "None"
|
||||
currentCR.Spec.ManifestsRoot = mfroot
|
||||
userHomeDir, err := homedir.Dir()
|
||||
if err != nil {
|
||||
fmt.Printf(`error fetching user's home directory: %v\n`, err)
|
||||
return err
|
||||
}
|
||||
|
||||
cr.GeneratePatches(¤tCR.KApiCr, path.Join(userHomeDir, ".kube", "config"))
|
||||
|
||||
resultYamlString, err := qliksense.ExecuteKustomizeBuild(kusDir)
|
||||
if err != nil {
|
||||
fmt.Printf("Unable to retrieve manifests from executing kustomize: %v\n", err)
|
||||
@@ -89,30 +75,27 @@ func (qp *QliksensePreflight) checkCreateEntity(namespace, entityToTest string)
|
||||
|
||||
sa := qliksense.GetYamlsFromMultiDoc(string(resultYamlString), entityToTest)
|
||||
if sa != "" {
|
||||
// sa = strings.ReplaceAll(sa, "namespace: default\n", fmt.Sprintf("namespace: %s\n", namespace))
|
||||
sa = strings.ReplaceAll(sa, "namespace: default\n", fmt.Sprintf("namespace: %s\n", namespace))
|
||||
} else {
|
||||
err := fmt.Errorf("Unable to retrieve yamls to apply on cluster")
|
||||
fmt.Println(err)
|
||||
return err
|
||||
}
|
||||
namespace = "" // namespace is handled when generating the manifests
|
||||
|
||||
defer func() {
|
||||
fmt.Println("Cleaning up resources")
|
||||
api.KubectlDelete(sa, namespace)
|
||||
if err != nil {
|
||||
fmt.Println("Preflight cleanup failed!")
|
||||
}
|
||||
}()
|
||||
|
||||
err = api.KubectlApply(sa, namespace)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Failed to create entity on the cluster: %v", err)
|
||||
err := fmt.Errorf("Failed to create entity on the cluster")
|
||||
fmt.Println(err)
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Preflight %s check: PASSED\n", entityToTest)
|
||||
fmt.Println("Cleaning up resources")
|
||||
err = api.KubectlDelete(sa, namespace)
|
||||
if err != nil {
|
||||
fmt.Println("Preflight cleanup failed!")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ func GetYamlsFromMultiDoc(multiYaml string, kind string) string {
|
||||
for _, doc := range yamlDocs {
|
||||
scanner := bufio.NewScanner(strings.NewReader(doc))
|
||||
for scanner.Scan() {
|
||||
if scanner.Text() == "kind: "+kind {
|
||||
if strings.TrimSpace(scanner.Text()) == "kind: "+kind {
|
||||
resultDocs = resultDocs + "\n---\n" + doc
|
||||
break
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user