Compare commits

...

2 Commits

Author SHA1 Message Date
Ashwathi Shiva
eed4d49665 Removing namespaces from role, rolebinding and sa checks (#280)
* remove namespace from role, rolebinding and SA checks
2020-04-06 00:23:40 -04:00
Foysal Iqbal
34d35909a4 remove regex again (#279)
Signed-off-by: Foysal Iqbal <mqb@qlik.com>
2020-04-05 22:13:32 -04:00
7 changed files with 52 additions and 29 deletions

View File

@@ -37,6 +37,9 @@ 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")
@@ -94,6 +97,9 @@ 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
@@ -121,6 +127,9 @@ 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")
@@ -149,6 +158,9 @@ 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")
@@ -177,6 +189,9 @@ 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")
@@ -272,8 +287,8 @@ func pfCreateServiceAccountCheckCmd(q *qliksense.Qliksense) *cobra.Command {
return preflightServiceAccountCmd
}
func pfCreateRBCheckCmd(q *qliksense.Qliksense) *cobra.Command {
var preflightCreateRBCmd = &cobra.Command{
func pfCreateAuthCheckCmd(q *qliksense.Qliksense) *cobra.Command {
var preflightCreateAuthCmd = &cobra.Command{
Use: "authcheck",
Short: "preflight authcheck",
Long: `perform preflight authcheck that combines the role, rolebinding and serviceaccount checks`,
@@ -297,7 +312,7 @@ func pfCreateRBCheckCmd(q *qliksense.Qliksense) *cobra.Command {
return nil
},
}
return preflightCreateRBCmd
return preflightCreateAuthCmd
}
func pfMongoCheckCmd(q *qliksense.Qliksense) *cobra.Command {
@@ -318,6 +333,9 @@ 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")

View File

@@ -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(pfCreateRBCheckCmd(p))
preflightCmd.AddCommand(pfCreateAuthCheckCmd(p))
cmd.AddCommand(preflightCmd)
cmd.AddCommand(loadCrFile(p))

View File

@@ -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

View File

@@ -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)

View File

@@ -73,8 +73,8 @@ func mongoConnCheck(kubeConfigContents []byte, namespace, mongodbUrl string) err
return err
}
fmt.Println("stdout:", stdout)
fmt.Println("stderr:", stderr)
api.LogDebugMessage("stdout:%v\n", stdout)
api.LogDebugMessage("stderr:%v\n", stderr)
stringToCheck := "Implicit session"
if strings.Contains(stdout, stringToCheck) || strings.Contains(stderr, stringToCheck) {
fmt.Println("Preflight mongo check: PASSED")

View File

@@ -3,7 +3,6 @@ package preflight
import (
"fmt"
"path/filepath"
"strings"
"github.com/qlik-oss/sense-installer/pkg/api"
qapi "github.com/qlik-oss/sense-installer/pkg/api"
@@ -75,27 +74,30 @@ 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")
err := fmt.Errorf("Failed to create entity on the cluster: %v", err)
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
}

View File

@@ -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 strings.TrimSpace(scanner.Text()) == "kind: "+kind {
if scanner.Text() == "kind: "+kind {
resultDocs = resultDocs + "\n---\n" + doc
break
}