Compare commits

..

2 Commits

Author SHA1 Message Date
Ilir Bekteshi
fd0396173f Add to docs and use more variables 2020-03-11 22:37:27 +01:00
Ilir Bekteshi
315a26227b qliksense install script (*nix) #132 2020-03-11 21:52:26 +01:00
12 changed files with 139 additions and 82 deletions

5
.gitattributes vendored
View File

@@ -1,5 +0,0 @@
# Ignore all files and folders that start with .; .circleci, .github, .git, etc.
# Warning! This will ignore files in subfolders as well.
# If you needs files starting with . then change condition below to be specific
# for each file and folder that needs to be ignored
.* export-ignore

View File

@@ -42,7 +42,10 @@ func initAndExecute() error {
// create dirs and appropriate files for setting up contexts // create dirs and appropriate files for setting up contexts
api.LogDebugMessage("QliksenseHomeDir: %s", qlikSenseHome) api.LogDebugMessage("QliksenseHomeDir: %s", qlikSenseHome)
qliksenseClient := qliksense.New(qlikSenseHome) qliksenseClient, err := qliksense.New(qlikSenseHome)
if err != nil {
return err
}
qliksenseClient.SetUpQliksenseDefaultContext() qliksenseClient.SetUpQliksenseDefaultContext()
cmd := rootCmd(qliksenseClient) cmd := rootCmd(qliksenseClient)
//levenstein checks //levenstein checks
@@ -148,12 +151,14 @@ func rootCmd(p *qliksense.Qliksense) *cobra.Command {
// add the list config command as a sub-command to the app config sub-command // add the list config command as a sub-command to the app config sub-command
configCmd.AddCommand(listContextConfigCmd(p)) configCmd.AddCommand(listContextConfigCmd(p))
// add the delete-context config command as a sub-command to the app config command // add the delete-context config command as a sub-command to the app config command
configCmd.AddCommand(deleteContextConfigCmd(p)) configCmd.AddCommand(deleteContextConfigCmd(p))
// add set-image-registry command as a sub-command to the app config sub-command // add set-image-registry command as a sub-command to the app config sub-command
configCmd.AddCommand(setImageRegistryCmd(p)) configCmd.AddCommand(setImageRegistryCmd(p))
// add clean-config-repo-patches command as a sub-command to the app config sub-command // add clean-config-repo-patches command as a sub-command to the app config sub-command
configCmd.AddCommand(cleanConfigRepoPatchesCmd(p)) configCmd.AddCommand(cleanConfigRepoPatchesCmd(p))

View File

@@ -7,7 +7,14 @@
## Download ## Download
- Download the appropriate executable for your platform from the [releases page](https://github.com/qlik-oss/sense-installer/releases) and rename it to `qliksense`. All the examplease down below uses `qliksense`. - Download the appropriate executable for your platform from the [releases page](https://github.com/qlik-oss/sense-installer/releases) and rename it to `qliksense`. All the examples below uses `qliksense`.
### Linux
```console
curl -fsSL https://raw.githubusercontent.com/qlik-oss/sense-installer/ibiqlik/installscript/scripts/install.sh -o install-sense-cli.sh
sh install-sense-cli.sh
```
## Quick start ## Quick start

2
go.mod
View File

@@ -39,7 +39,7 @@ require (
github.com/mattn/go-colorable v0.1.4 github.com/mattn/go-colorable v0.1.4
github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/go-homedir v1.1.0
github.com/morikuni/aec v1.0.0 // indirect github.com/morikuni/aec v1.0.0 // indirect
github.com/qlik-oss/k-apis v0.0.19 github.com/qlik-oss/k-apis v0.0.17
github.com/rogpeppe/go-internal v1.5.2 // indirect github.com/rogpeppe/go-internal v1.5.2 // indirect
github.com/spf13/cobra v0.0.6 github.com/spf13/cobra v0.0.6
github.com/spf13/viper v1.6.1 github.com/spf13/viper v1.6.1

3
go.sum
View File

@@ -843,11 +843,8 @@ github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDa
github.com/prometheus/procfs v0.0.5 h1:3+auTFlqw+ZaQYJARz6ArODtkaIwtvBTx3N2NehQlL8= github.com/prometheus/procfs v0.0.5 h1:3+auTFlqw+ZaQYJARz6ArODtkaIwtvBTx3N2NehQlL8=
github.com/prometheus/procfs v0.0.5/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= github.com/prometheus/procfs v0.0.5/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/qlik-oss/k-apis v0.0.16/go.mod h1:KOFzKVIdRqp47ytnHg3+9zb8fTlnrQjO6aKiwcrCJUE=
github.com/qlik-oss/k-apis v0.0.17 h1:tOdrEe9gfb9CXq0+uowFnXIsI781qz/zgeN8xqupXYw= github.com/qlik-oss/k-apis v0.0.17 h1:tOdrEe9gfb9CXq0+uowFnXIsI781qz/zgeN8xqupXYw=
github.com/qlik-oss/k-apis v0.0.17/go.mod h1:KOFzKVIdRqp47ytnHg3+9zb8fTlnrQjO6aKiwcrCJUE= github.com/qlik-oss/k-apis v0.0.17/go.mod h1:KOFzKVIdRqp47ytnHg3+9zb8fTlnrQjO6aKiwcrCJUE=
github.com/qlik-oss/k-apis v0.0.19 h1:yrMgALQ08vMDi5hN6fnvIfyNsEaXA5fZjB1YhyIdTfg=
github.com/qlik-oss/k-apis v0.0.19/go.mod h1:DNiWYqCqPIN216l7+1rccArNIYPb1Le7kYDcPSyNp+Q=
github.com/qlik-oss/kustomize/api v0.3.3-0.20200206224201-2e697eccbad9 h1:iqeqTS4zjp6rPEaxmFB7pemA2CMjOEN5dYSXZaQ82uw= github.com/qlik-oss/kustomize/api v0.3.3-0.20200206224201-2e697eccbad9 h1:iqeqTS4zjp6rPEaxmFB7pemA2CMjOEN5dYSXZaQ82uw=
github.com/qlik-oss/kustomize/api v0.3.3-0.20200206224201-2e697eccbad9/go.mod h1:OCt7FTrRVHj4kmR2xLJJUIqu00BTr6GeF09hSmM17Kw= github.com/qlik-oss/kustomize/api v0.3.3-0.20200206224201-2e697eccbad9/go.mod h1:OCt7FTrRVHj4kmR2xLJJUIqu00BTr6GeF09hSmM17Kw=
github.com/quasilyte/go-consistent v0.0.0-20190521200055-c6f3937de18c/go.mod h1:5STLWrekHfjyYwxBRVRXNOSewLJ3PWfDJd1VyTS21fI= github.com/quasilyte/go-consistent v0.0.0-20190521200055-c6f3937de18c/go.mod h1:5STLWrekHfjyYwxBRVRXNOSewLJ3PWfDJd1VyTS21fI=

View File

@@ -22,7 +22,6 @@ const (
pullSecretFileName = "image-registry-pull-secret.yaml" pullSecretFileName = "image-registry-pull-secret.yaml"
qliksenseContextsDirName = "contexts" qliksenseContextsDirName = "contexts"
qliksenseSecretsDirName = "secrets" qliksenseSecretsDirName = "secrets"
qliksenseEjsonDirName = "ejson"
) )
// NewQConfig create QliksenseConfig object from file ~/.qliksense/config.yaml // NewQConfig create QliksenseConfig object from file ~/.qliksense/config.yaml
@@ -240,18 +239,6 @@ func (qc *QliksenseConfig) getCurrentContextEncryptionKeyPairLocation() (string,
return secretKeyPairLocation, nil return secretKeyPairLocation, nil
} }
func (qc *QliksenseConfig) GetCurrentContextEjsonKeyDir() (string, error) {
if qcr, err := qc.GetCurrentCR(); err != nil {
return "", err
} else {
ejsonKeyDir := filepath.Join(qc.QliksenseHomePath, qliksenseSecretsDirName, qliksenseContextsDirName, qcr.GetObjectMeta().GetName(), qliksenseEjsonDirName)
if err := os.MkdirAll(ejsonKeyDir, os.ModePerm); err != nil {
return "", err
}
return ejsonKeyDir, nil
}
}
func (qc *QliksenseConfig) GetCurrentContextEncryptionKeyPair() (*rsa.PublicKey, *rsa.PrivateKey, error) { func (qc *QliksenseConfig) GetCurrentContextEncryptionKeyPair() (*rsa.PublicKey, *rsa.PrivateKey, error) {
secretKeyPairLocation, err := qc.getCurrentContextEncryptionKeyPairLocation() secretKeyPairLocation, err := qc.getCurrentContextEncryptionKeyPairLocation()
if err != nil { if err != nil {

View File

@@ -59,21 +59,14 @@ func (q *Qliksense) ConfigApplyQK8s() error {
} }
} }
func (q *Qliksense) configEjson() error {
qConfig := qapi.NewQConfig(q.QliksenseHome)
if ejsonKeyDir, err := qConfig.GetCurrentContextEjsonKeyDir(); err != nil {
return err
} else if err := os.Unsetenv("EJSON_KEY"); err != nil {
return err
} else if err := os.Setenv("EJSON_KEYDIR", ejsonKeyDir); err != nil {
return err
}
return nil
}
func (q *Qliksense) applyConfigToK8s(qcr *qapi.QliksenseCR) error { func (q *Qliksense) applyConfigToK8s(qcr *qapi.QliksenseCR) error {
if qcr.Spec.RotateKeys != "None" { if qcr.Spec.RotateKeys != "None" {
if err := q.configEjson(); err != nil { if err := os.Unsetenv("EJSON_KEY"); err != nil {
fmt.Printf("error unsetting EJSON_KEY environment variable: %v\n", err)
return err
}
if err := os.Setenv("EJSON_KEYDIR", q.QliksenseEjsonKeyDir); err != nil {
fmt.Printf("error setting EJSON_KEYDIR environment variable: %v\n", err)
return err return err
} }
} }

View File

@@ -225,38 +225,6 @@ func (q *Qliksense) SetOtherConfigs(args []string) error {
} }
qliksenseCR.Spec.RotateKeys = rotateKeys qliksenseCR.Spec.RotateKeys = rotateKeys
api.LogDebugMessage("Current rotateKeys after modification: %s ", qliksenseCR.Spec.RotateKeys) api.LogDebugMessage("Current rotateKeys after modification: %s ", qliksenseCR.Spec.RotateKeys)
case "gitops.enabled":
if qliksenseCR.Spec.GitOps == nil {
qliksenseCR.Spec.GitOps = &config.GitOps{}
}
if strings.EqualFold(argsString[1], "false") {
qliksenseCR.Spec.GitOps.Enabled = false
} else if strings.EqualFold(argsString[1], "true") {
qliksenseCR.Spec.GitOps.Enabled = true
} else {
err := fmt.Errorf("Please use a boolean value")
log.Println(err)
return err
}
api.LogDebugMessage("Current gitOps enabled status : %s ", qliksenseCR.Spec.GitOps.Enabled)
case "gitops.schedule":
if qliksenseCR.Spec.GitOps == nil {
qliksenseCR.Spec.GitOps = &config.GitOps{}
}
qliksenseCR.Spec.GitOps.Schedule = argsString[1]
api.LogDebugMessage("Current gitOps schedule is : %s ", qliksenseCR.Spec.GitOps.Schedule)
case "gitops.watchbranch":
if qliksenseCR.Spec.GitOps == nil {
qliksenseCR.Spec.GitOps = &config.GitOps{}
}
qliksenseCR.Spec.GitOps.WatchBranch = argsString[1]
api.LogDebugMessage("Current gitOps watchbranch is : %s ", qliksenseCR.Spec.GitOps.WatchBranch)
case "gitops.image":
if qliksenseCR.Spec.GitOps == nil {
qliksenseCR.Spec.GitOps = &config.GitOps{}
}
qliksenseCR.Spec.GitOps.Image = argsString[1]
api.LogDebugMessage("Current gitOps watchbranch is : %s ", qliksenseCR.Spec.GitOps.Image)
default: default:
err := fmt.Errorf("Please enter one of: profile, storageClassName,rotateKeys, manifestRoot or git.repository arguments to configure the current context") err := fmt.Errorf("Please enter one of: profile, storageClassName,rotateKeys, manifestRoot or git.repository arguments to configure the current context")
log.Println(err) log.Println(err)

View File

@@ -273,7 +273,11 @@ func TestSetUpQliksenseContext(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
q := New(tt.args.qlikSenseHome) q, err := New(tt.args.qlikSenseHome)
if err != nil {
t.Errorf("unable to create a qliksense instance")
return
}
if err := q.SetUpQliksenseContext(tt.args.contextName, tt.args.isDefaultContext); (err != nil) != tt.wantErr { if err := q.SetUpQliksenseContext(tt.args.contextName, tt.args.isDefaultContext); (err != nil) != tt.wantErr {
t.Errorf("SetUpQliksenseContext() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("SetUpQliksenseContext() error = %v, wantErr %v", err, tt.wantErr)
} }
@@ -302,7 +306,11 @@ func TestSetUpQliksenseDefaultContext(t *testing.T) {
defer tearDown() defer tearDown()
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
q := New(tt.args.qlikSenseHome) q, err := New(tt.args.qlikSenseHome)
if err != nil {
t.Errorf("unable to create a qliksense instance")
return
}
if err := q.SetUpQliksenseDefaultContext(); (err != nil) != tt.wantErr { if err := q.SetUpQliksenseDefaultContext(); (err != nil) != tt.wantErr {
t.Errorf("SetUpQliksenseDefaultContext() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("SetUpQliksenseDefaultContext() error = %v, wantErr %v", err, tt.wantErr)
} }
@@ -828,7 +836,7 @@ spec:
log.Fatal(err) log.Fatal(err)
} }
contextYaml1 := contextYaml1 :=
` `
apiVersion: qlik.com/v1 apiVersion: qlik.com/v1
kind: Qliksense kind: Qliksense
metadata: metadata:
@@ -838,8 +846,8 @@ spec:
rotateKeys: "yes" rotateKeys: "yes"
releaseName: qlik1` releaseName: qlik1`
contextYaml2 := contextYaml2 :=
` `
apiVersion: qlik.com/v1 apiVersion: qlik.com/v1
kind: Qliksense kind: Qliksense
metadata: metadata:
@@ -924,7 +932,11 @@ func TestDeleteContexts(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
q := New(tt.args.qlikSenseHome) q, err := New(tt.args.qlikSenseHome)
if err != nil {
t.Errorf("unable to create a qliksense instance")
return
}
var arg []string var arg []string
arg = append(arg, tt.args.contextName) arg = append(arg, tt.args.contextName)
if err := q.DeleteContextConfig(arg); (err != nil) != tt.wantErr { if err := q.DeleteContextConfig(arg); (err != nil) != tt.wantErr {

View File

@@ -2,21 +2,29 @@
package qliksense package qliksense
import ( import (
"os"
"path"
"github.com/gobuffalo/packr/v2" "github.com/gobuffalo/packr/v2"
) )
// Qliksense is the logic behind the qliksense client // Qliksense is the logic behind the qliksense client
type Qliksense struct { type Qliksense struct {
QliksenseHome string QliksenseHome string
CrdBox *packr.Box `` QliksenseEjsonKeyDir string
CrdBox *packr.Box ``
} }
// New qliksense client, initialized with useful defaults. // New qliksense client, initialized with useful defaults.
func New(qliksenseHome string) *Qliksense { func New(qliksenseHome string) (*Qliksense, error) {
qliksenseClient := &Qliksense{ qliksenseClient := &Qliksense{
QliksenseHome: qliksenseHome, QliksenseHome: qliksenseHome,
CrdBox: packr.New("crds", "./crds"), CrdBox: packr.New("crds", "./crds"),
} }
return qliksenseClient qliksenseClient.QliksenseEjsonKeyDir = path.Join(qliksenseHome, "ejson", "keys")
if err := os.MkdirAll(qliksenseClient.QliksenseEjsonKeyDir, os.ModePerm); err != nil {
return nil, err
}
return qliksenseClient, nil
} }

View File

@@ -28,9 +28,7 @@ func (q *Qliksense) UpgradeQK8s(keepPatchFiles bool) error {
return err return err
} }
qcr.Spec.RotateKeys = "no" qcr.Spec.RotateKeys = "no"
if dcr, err := qConfig.GetDecryptedCr(qcr); err != nil { if err := q.applyConfigToK8s(qcr); err != nil {
return err
} else if err := q.applyConfigToK8s(dcr); err != nil {
fmt.Println("cannot do kubectl apply on manifests") fmt.Println("cannot do kubectl apply on manifests")
return err return err
} }

87
scripts/install.sh Executable file
View File

@@ -0,0 +1,87 @@
#!/bin/sh
set -e
# Sense installer for Linux/MacOS script
#
# See https://github.com/qlik-oss/sense-installer for the installation steps.
#
# This script is meant for quick & easy install via:
# $ curl -fsSL https://raw.githubusercontent.com/qlik-oss/sense-installer/scripts/install.sh | sh -
RELEASES_URI="https://api.github.com/repos/qlik-oss/sense-installer/releases/latest"
REPO_URL="https://github.com/qlik-oss/sense-installer"
BIN_DIR="/usr/local/bin"
FILE_NAME="kubectl-qliksense"
command_exists() {
command -v "$@" > /dev/null 2>&1
}
do_install() {
echo "\n==> Executing qliksense install script\n"
if ! command_exists kubectl; then
echo "\n==> ERROR: kubectl is required for $FILE_NAME to work"
echo "See https://github.com/qlik-oss/sense-installer#requirements for more information\n"
exit 1
fi
if ! command_exists curl; then
echo "==> ERROR: curl is missing"
exit 1
fi
user="$(id -un 2>/dev/null || true)"
SUDO='sh -c'
if [ "$(id -u)" != "0" ]; then
root_msg="\tNext operation might ask for root password to place\n\t$FILE_NAME in $BIN_DIR and set executable permission\n"
if command_exists sudo; then
echo $root_msg
SUDO='sudo -E sh -c'
elif command_exists su; then
echo $root_msg
SUDO='su -c'
else
cat >&2 <<-'EOF'
Error: this installer needs the ability to run commands as root.
We are unable to find either "sudo" or "su" available to make this happen.
EOF
exit 1
fi
fi
if command_exists curl; then
releases=$(mktemp)
if [ -n "$GITHUB_TOKEN" ]; then
curl -v -H "Authorization: token $GITHUB_TOKEN" $RELEASES_URI > $releases 2>&1
else
curl -v $RELEASES_URI > $releases 2>&1
fi
if ! grep -q "Status: 200" $releases; then
echo "==> ERROR: cannot get qliksense-installer"
echo "GitHub:" $(grep "message" $releases | cut -d '"' -f 4) "\n"
echo "Use: GITHUB_TOKEN=token install-sense-cli.sh"
exit 1
fi
download_url=$(grep -E "browser_download_url.*linux" $releases | grep -v "tar.gz" | cut -d '"' -f 4)
echo "==> Installing to $BIN_DIR/$FILE_NAME\n"
if [ -n "$GITHUB_TOKEN" ]; then
$SUDO "curl -fSL -H \"Authorization: token $GITHUB_TOKEN\" $download_url -o $BIN_DIR/$FILE_NAME"
else
$SUDO "curl -fSL $download_url -o $BIN_DIR/$FILE_NAME"
fi
$SUDO "chmod +x $BIN_DIR/$FILE_NAME"
fi
if command_exists $FILE_NAME; then
echo "\n==> Success: You can now start using $FILE_NAME\n"
else
echo "\n==> ERROR: Something went wrong, try again"
fi
}
do_install