Compare commits

..

26 Commits

Author SHA1 Message Date
Foysal Iqbal
75ce6caa2b random prefix
Signed-off-by: Foysal Iqbal <mqb@qlik.com>
2020-04-06 00:17:54 -04:00
Ashwathi Shiva
d05b119a68 remove namespace from role, rolebinding and SA checks 2020-04-05 23:31:47 -04:00
Ashwathi Shiva
ed26e692c9 Merge branch 'master' into preflight_pretty_print
# Conflicts:
#	pkg/preflight/role_check.go
#	pkg/qliksense/kuz.go
2020-04-05 21:28:05 -04:00
Ashwathi Shiva
5909c728ab - possible fix for restricting role and role binding checks to only install their specific types
- moved kubectl delete to defer to force clean up
2020-04-05 21:25:19 -04:00
Ashwathi Shiva
d77654e763 Updated readme 2020-04-05 19:05:03 -04:00
Ashwathi Shiva
73c3ac1d58 Merge branch 'master' into preflight_roles 2020-04-05 17:30:59 -04:00
Ashwathi Shiva
083203128c passed mongo url to preflight all command, addressed some PR comments 2020-04-05 17:27:54 -04:00
Foysal Iqbal
ccc2997745 fix entity creation
Signed-off-by: Foysal Iqbal <mqb@qlik.com>
2020-04-04 13:44:18 -04:00
Ashwathi Shiva
1f5ee3d487 Merge branch 'master' into preflight_roles 2020-04-04 01:37:58 -04:00
Ashwathi Shiva
87ace81dee renamed some commands and cleaned up some messages 2020-04-04 01:33:20 -04:00
Ashwathi Shiva
2618e72a46 display the mongodb url 2020-04-03 11:18:13 -04:00
Ashwathi Shiva
1aac550f66 mongodbUrl inferred from CR 2020-04-03 08:04:29 -04:00
Ashwathi Shiva
bacaea1b92 Merge branch 'master' into preflight_roles
# Conflicts:
#	pkg/preflight/deployability.go
2020-04-03 01:23:09 -04:00
Ashwathi Shiva
acfa1f16a1 updated readme 2020-04-03 01:18:59 -04:00
Ashwathi Shiva
8b68a4d305 updated qliksense preflight all to update mongodb check 2020-04-03 01:08:06 -04:00
Ashwathi Shiva
114d0a13c8 preflight mongo --url=url working 2020-04-03 00:47:49 -04:00
Ashwathi Shiva
c733d2821e Merge branch 'preflight_roles' of github.com:qlik-oss/sense-installer into preflight_roles 2020-04-02 23:38:11 -04:00
Ashwathi Shiva
69306605a3 preflight createRole, createRoleBinding, createServiceAccount, createRB working 2020-04-02 23:34:55 -04:00
Foysal Iqbal
67ec3105f0 fix yaml trim
Signed-off-by: Foysal Iqbal <mqb@qlik.com>
2020-04-02 20:48:43 -04:00
Ashwathi Shiva
e69149ec64 finished initial functional role check 2020-04-02 19:44:13 -04:00
Ashwathi Shiva
cedb7f8fca WIP - intermediate commit 2020-04-02 19:09:34 -04:00
Ashwathi Shiva
fee81b25a6 WIP preflight createRole 2020-04-02 16:31:48 -04:00
Ashwathi Shiva
b5eea11050 Merge branch 'master' into preflight_roles 2020-04-02 14:44:23 -04:00
Ashwathi Shiva
dbf6f6debc preflight createRB working and updated readme 2020-04-02 00:00:48 -04:00
Ashwathi Shiva
002b0faaa1 Merge branch 'master' into preflight_roles 2020-04-01 23:33:47 -04:00
Ashwathi Shiva
a676d10ed0 preflight role, roleBinding, serviceAccount working 2020-04-01 23:31:28 -04:00
7 changed files with 64 additions and 32 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,6 +11,7 @@ import (
"net/http"
"os"
"path/filepath"
"regexp"
"strings"
"time"
@@ -68,23 +69,20 @@ 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))
// qliksense.mongodb=somethig
re1 := regexp.MustCompile(`([\w\-]{1,}).([\w\-]{1,})=("*[\w\-?=_/:0-9\.]+"*)`)
for i, arg := range args {
LogDebugMessage("Arg received: %s", arg)
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
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
}
resultSvcKV[i] = &ServiceKeyValue{
SvcName: second[0],
Key: second[1],
Value: strings.ReplaceAll(first[1], `"`, ""),
SvcName: result[1],
Key: result[2],
Value: strings.ReplaceAll(result[3], `"`, ""),
}
}
return resultSvcKV, nil

View File

@@ -11,11 +11,10 @@ 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", "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"}
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"}
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:", stdout)
api.LogDebugMessage("stderr:", stderr)
stringToCheck := "Implicit session"
if strings.Contains(stdout, stringToCheck) || strings.Contains(stderr, stringToCheck) {
fmt.Println("Preflight mongo check: PASSED")

View File

@@ -2,9 +2,11 @@ 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"
@@ -67,6 +69,18 @@ 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(&currentCR.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)
@@ -75,27 +89,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
}