Compare commits
10 Commits
postflight
...
pf_checks_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8343f0f424 | ||
|
|
2ed59321e4 | ||
|
|
9dabdafe6e | ||
|
|
fb6ab89809 | ||
|
|
af71b0ca0c | ||
|
|
8f30a92a85 | ||
|
|
98198a3c8b | ||
|
|
afab3e2939 | ||
|
|
5f3e6d1ffb | ||
|
|
62fda8f2c6 |
@@ -14,7 +14,7 @@ import (
|
||||
func applyCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
opts := &qliksense.InstallCommandOptions{}
|
||||
filePath := ""
|
||||
keepPatchFiles, pull, push := false, false, false
|
||||
cleanPatchFiles, pull, push := true, false, false
|
||||
c := &cobra.Command{
|
||||
Use: "apply",
|
||||
Short: "install qliksense based on provided cr file",
|
||||
@@ -27,7 +27,7 @@ func applyCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
} else if err := validatePullPushFlagsOnApply(cr, pull, push); err != nil {
|
||||
return err
|
||||
} else {
|
||||
return q.ApplyCRFromReader(bytes.NewReader(crBytesWithEula), opts, keepPatchFiles, true, pull, push)
|
||||
return q.ApplyCRFromReader(bytes.NewReader(crBytesWithEula), opts, cleanPatchFiles, true, pull, push)
|
||||
}
|
||||
})
|
||||
},
|
||||
@@ -39,7 +39,7 @@ func applyCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
f.StringVarP(&opts.StorageClass, "storageClass", "s", "", "Storage class for qliksense")
|
||||
f.StringVarP(&opts.MongodbUri, "mongodbUri", "m", "", "mongodbUri for qliksense (i.e. mongodb://qlik-default-mongodb:27017/qliksense?ssl=false)")
|
||||
f.StringVarP(&opts.RotateKeys, "rotateKeys", "r", "", "Rotate JWT keys for qliksense (yes:rotate keys/ no:use exising keys from cluster/ None: use default EJSON_KEY from env")
|
||||
f.BoolVar(&keepPatchFiles, keepPatchFilesFlagName, keepPatchFiles, keepPatchFilesFlagUsage)
|
||||
f.BoolVar(&cleanPatchFiles, cleanPatchFilesFlagName, cleanPatchFiles, cleanPatchFilesFlagUsage)
|
||||
f.BoolVarP(&pull, pullFlagName, pullFlagShorthand, pull, pullFlagUsage)
|
||||
f.BoolVarP(&push, pushFlagName, pushFlagShorthand, push, pushFlagUsage)
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
func installCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
opts := &qliksense.InstallCommandOptions{}
|
||||
filePath := ""
|
||||
keepPatchFiles, pull, push := false, false, false
|
||||
cleanPatchFiles, pull, push := true, false, false
|
||||
c := &cobra.Command{
|
||||
Use: "install",
|
||||
Short: "install a qliksense release",
|
||||
@@ -29,7 +29,7 @@ func installCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
} else if err := validatePullPushFlagsOnApply(cr, pull, push); err != nil {
|
||||
return err
|
||||
} else {
|
||||
return q.ApplyCRFromReader(bytes.NewReader(crBytesWithEula), opts, keepPatchFiles, true, pull, push)
|
||||
return q.ApplyCRFromReader(bytes.NewReader(crBytesWithEula), opts, cleanPatchFiles, true, pull, push)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
@@ -52,7 +52,7 @@ func installCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return q.InstallQK8s(version, opts, keepPatchFiles)
|
||||
return q.InstallQK8s(version, opts, cleanPatchFiles)
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -73,7 +73,7 @@ func installCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
f.StringVarP(&opts.StorageClass, "storageClass", "s", "", "Storage class for qliksense")
|
||||
f.StringVarP(&opts.MongodbUri, "mongodbUri", "m", "", "mongodbUri for qliksense (i.e. mongodb://qlik-default-mongodb:27017/qliksense?ssl=false)")
|
||||
f.StringVarP(&opts.RotateKeys, "rotateKeys", "r", "", "Rotate JWT keys for qliksense (yes:rotate keys/ no:use exising keys from cluster/ None: use default EJSON_KEY from env")
|
||||
f.BoolVar(&keepPatchFiles, keepPatchFilesFlagName, keepPatchFiles, keepPatchFilesFlagUsage)
|
||||
f.BoolVar(&cleanPatchFiles, cleanPatchFilesFlagName, cleanPatchFiles, cleanPatchFilesFlagUsage)
|
||||
f.StringVarP(&filePath, "file", "f", "", "Install from a CR file")
|
||||
|
||||
f.BoolVarP(&opts.DryRun, "dry-run", "", false, "Dry run will generate the patches without rotating keys")
|
||||
|
||||
@@ -43,7 +43,7 @@ func pfDnsCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
// Preflight DNS check
|
||||
namespace, kubeConfigContents, err := qp.CG.LoadKubeConfigAndNamespace()
|
||||
if err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight DNS check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
@@ -51,11 +51,11 @@ func pfDnsCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
namespace = "default"
|
||||
}
|
||||
if err = qp.CheckDns(namespace, kubeConfigContents, false); err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight DNS check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
fmt.Fprintf(out, "%s\n", Green("Preflight DNS check PASSED"))
|
||||
fmt.Fprintf(out, "%s\n", Green("PASSED"))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@@ -81,16 +81,16 @@ func pfK8sVersionCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
// Preflight Kubernetes minimum version check
|
||||
namespace, kubeConfigContents, err := qp.CG.LoadKubeConfigAndNamespace()
|
||||
if err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight kubernetes minimum version check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
if err = qp.CheckK8sVersion(namespace, kubeConfigContents); err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight kubernetes minimum version check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
fmt.Fprintf(out, "%s\n", Green("Preflight kubernetes minimum version check PASSED"))
|
||||
fmt.Fprintf(out, "%s\n", Green("PASSED"))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@@ -157,7 +157,7 @@ func pfDeploymentCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
// Preflight deployments check
|
||||
namespace, kubeConfigContents, err := qp.CG.LoadKubeConfigAndNamespace()
|
||||
if err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight deployment check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
@@ -165,11 +165,11 @@ func pfDeploymentCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
namespace = "default"
|
||||
}
|
||||
if err = qp.CheckDeployment(namespace, kubeConfigContents, false); err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight deployment check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
fmt.Fprintf(out, "%s\n", Green("Preflight deployment check PASSED"))
|
||||
fmt.Fprintf(out, "%s\n", Green("PASSED"))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@@ -195,7 +195,7 @@ func pfServiceCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
// Preflight service check
|
||||
namespace, kubeConfigContents, err := qp.CG.LoadKubeConfigAndNamespace()
|
||||
if err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight service check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
@@ -204,11 +204,11 @@ func pfServiceCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
namespace = "default"
|
||||
}
|
||||
if err = qp.CheckService(namespace, kubeConfigContents, false); err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight service check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
fmt.Fprintf(out, "%s\n", Green("Preflight service check PASSED"))
|
||||
fmt.Fprintf(out, "%s\n", Green("PASSED"))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@@ -234,7 +234,7 @@ func pfPodCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
// Preflight pod check
|
||||
namespace, kubeConfigContents, err := qp.CG.LoadKubeConfigAndNamespace()
|
||||
if err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight pod check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
@@ -242,11 +242,11 @@ func pfPodCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
namespace = "default"
|
||||
}
|
||||
if err = qp.CheckPod(namespace, kubeConfigContents, false); err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight pod check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
fmt.Fprintf(out, "%s\n", Green("Preflight pod check PASSED"))
|
||||
fmt.Fprintf(out, "%s\n", Green("PASSED"))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@@ -272,16 +272,16 @@ func pfCreateRoleCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
// Preflight role check
|
||||
namespace, _, err := qp.CG.LoadKubeConfigAndNamespace()
|
||||
if err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight role check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
if err = qp.CheckCreateRole(namespace, false); err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight role check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
fmt.Fprintf(out, "%s\n", Green("Preflight role check PASSED"))
|
||||
fmt.Fprintf(out, "%s\n", Green("PASSED"))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@@ -307,16 +307,16 @@ func pfCreateRoleBindingCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
// Preflight createRoleBinding check
|
||||
namespace, _, err := qp.CG.LoadKubeConfigAndNamespace()
|
||||
if err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight rolebinding check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
if err = qp.CheckCreateRoleBinding(namespace, false); err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight rolebinding check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
fmt.Fprintf(out, "%s\n", Green("Preflight rolebinding check PASSED"))
|
||||
fmt.Fprintf(out, "%s\n", Green("PASSED"))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@@ -342,16 +342,16 @@ func pfCreateServiceAccountCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
// Preflight createServiceAccount check
|
||||
namespace, _, err := qp.CG.LoadKubeConfigAndNamespace()
|
||||
if err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight ServiceAccount check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
if err = qp.CheckCreateServiceAccount(namespace, false); err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight ServiceAccount check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
fmt.Fprintf(out, "%s\n", Green("Preflight ServiceAccount check PASSED"))
|
||||
fmt.Fprintf(out, "%s\n", Green("PASSED"))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@@ -376,16 +376,16 @@ func pfCreateAuthCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
// Preflight authcheck
|
||||
namespace, kubeConfigContents, err := qp.CG.LoadKubeConfigAndNamespace()
|
||||
if err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight authcheck FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
if err = qp.CheckCreateRB(namespace, kubeConfigContents); err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight authcheck FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
fmt.Fprintf(out, "%s\n", Green("Preflight authcheck PASSED"))
|
||||
fmt.Fprintf(out, "%s\n", Green("PASSED"))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@@ -411,7 +411,7 @@ func pfMongoCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
// Preflight mongo check
|
||||
namespace, kubeConfigContents, err := qp.CG.LoadKubeConfigAndNamespace()
|
||||
if err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight mongo check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
@@ -419,11 +419,11 @@ func pfMongoCheckCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
namespace = "default"
|
||||
}
|
||||
if err = qp.CheckMongo(kubeConfigContents, namespace, preflightOpts, false); err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight mongo check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
fmt.Fprintf(out, "%s\n", Green("Preflight mongo check PASSED"))
|
||||
fmt.Fprintf(out, "%s\n", Green("PASSED"))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
@@ -23,17 +23,17 @@ import (
|
||||
// qliksense <command>
|
||||
|
||||
const (
|
||||
qlikSenseHomeVar = "QLIKSENSE_HOME"
|
||||
qlikSenseDirVar = ".qliksense"
|
||||
keepPatchFilesFlagName = "keep-config-repo-patches"
|
||||
keepPatchFilesFlagUsage = "Keep config repo patch files (for debugging)"
|
||||
pullFlagName = "pull"
|
||||
pullFlagShorthand = "d"
|
||||
pullFlagUsage = "If using private docker registry, pull (download) all required Qliksense images before install"
|
||||
pushFlagName = "push"
|
||||
pushFlagShorthand = "u"
|
||||
pushFlagUsage = "If using private docker registry, push (upload) all downloaded Qliksense images to that registry before install"
|
||||
rootCommandName = "qliksense"
|
||||
qlikSenseHomeVar = "QLIKSENSE_HOME"
|
||||
qlikSenseDirVar = ".qliksense"
|
||||
cleanPatchFilesFlagName = "clean"
|
||||
cleanPatchFilesFlagUsage = "Set --clean=false to keep any prior config repo file changes on install (for debugging)"
|
||||
pullFlagName = "pull"
|
||||
pullFlagShorthand = "d"
|
||||
pullFlagUsage = "If using private docker registry, pull (download) all required Qliksense images before install"
|
||||
pushFlagName = "push"
|
||||
pushFlagShorthand = "u"
|
||||
pushFlagUsage = "If using private docker registry, push (upload) all downloaded Qliksense images to that registry before install"
|
||||
rootCommandName = "qliksense"
|
||||
)
|
||||
|
||||
func initAndExecute() error {
|
||||
|
||||
2
go.mod
2
go.mod
@@ -10,7 +10,7 @@ replace (
|
||||
k8s.io/client-go => k8s.io/client-go v0.17.0
|
||||
k8s.io/kubectl => k8s.io/kubectl v0.0.0-20191219154910-1528d4eea6dd
|
||||
|
||||
sigs.k8s.io/kustomize/api => github.com/qlik-oss/kustomize/api v0.3.3-0.20200604075616-c46582ece468
|
||||
sigs.k8s.io/kustomize/api => github.com/qlik-oss/kustomize/api v0.3.3-0.20200604192606-17370c1af57b
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
4
go.sum
4
go.sum
@@ -887,8 +887,8 @@ github.com/prometheus/procfs v0.0.5/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDa
|
||||
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
|
||||
github.com/qlik-oss/k-apis v0.1.5 h1:IeqHuF1IIQCsuSmsUhL7GjdfkOFsNgh3z2UyX59GTsk=
|
||||
github.com/qlik-oss/k-apis v0.1.5/go.mod h1:yoYGgPJ/H0t9H3NSq64dWfyQY6QWi2L9c+hCJoVO03U=
|
||||
github.com/qlik-oss/kustomize/api v0.3.3-0.20200604075616-c46582ece468 h1:fAo9wsK2zNiKkOAo0OPCrrrtt/X1Y5W5YEx0t/Y4jwg=
|
||||
github.com/qlik-oss/kustomize/api v0.3.3-0.20200604075616-c46582ece468/go.mod h1:zh3yFgE5zFk1kreqzVyyj1eXyIxQJT53l4zSg8Wt4SA=
|
||||
github.com/qlik-oss/kustomize/api v0.3.3-0.20200604192606-17370c1af57b h1:UqyMR9WA/MbUxCOaaDFk8D2VwM3fG98foDU5nG2HPoM=
|
||||
github.com/qlik-oss/kustomize/api v0.3.3-0.20200604192606-17370c1af57b/go.mod h1:zh3yFgE5zFk1kreqzVyyj1eXyIxQJT53l4zSg8Wt4SA=
|
||||
github.com/quasilyte/go-consistent v0.0.0-20190521200055-c6f3937de18c/go.mod h1:5STLWrekHfjyYwxBRVRXNOSewLJ3PWfDJd1VyTS21fI=
|
||||
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be h1:ta7tUOvsPHVHGom5hKW5VXNc2xZIkfCKP8iaqOyYtUQ=
|
||||
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be/go.mod h1:MIDFMn7db1kT65GmV94GzpX9Qdi7N/pQlwb+AN8wh+Q=
|
||||
|
||||
@@ -371,7 +371,6 @@ func (p *ClientGoUtils) GetPodContainerLogs(clientset kubernetes.Interface, pod
|
||||
return "", err
|
||||
}
|
||||
defer podLogs.Close()
|
||||
// time.Sleep(15 * time.Second)
|
||||
buf := new(bytes.Buffer)
|
||||
_, err = io.Copy(buf, podLogs)
|
||||
if err != nil {
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
)
|
||||
|
||||
func TestClientGoUtils_getDeployment(t *testing.T) {
|
||||
t.Parallel()
|
||||
type fields struct {
|
||||
Verbose bool
|
||||
}
|
||||
@@ -85,6 +86,7 @@ func TestClientGoUtils_getDeployment(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClientGoUtils_DeleteDeployment(t *testing.T) {
|
||||
t.Parallel()
|
||||
type fields struct {
|
||||
Verbose bool
|
||||
}
|
||||
@@ -138,6 +140,7 @@ func TestClientGoUtils_DeleteDeployment(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClientGoUtils_GetService(t *testing.T) {
|
||||
t.Parallel()
|
||||
type fields struct {
|
||||
Verbose bool
|
||||
}
|
||||
@@ -204,6 +207,7 @@ func TestClientGoUtils_GetService(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClientGoUtils_CreatePreflightTestDeployment(t *testing.T) {
|
||||
t.Parallel()
|
||||
fk := fake.NewSimpleClientset()
|
||||
fk.Fake.PrependReactor("create", "deployments", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
|
||||
return true, &appsv1.Deployment{}, errors.New("Error creating deployment")
|
||||
@@ -303,6 +307,7 @@ func TestClientGoUtils_CreatePreflightTestDeployment(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClientGoUtils_DeleteService(t *testing.T) {
|
||||
t.Parallel()
|
||||
type fields struct {
|
||||
Verbose bool
|
||||
}
|
||||
@@ -360,6 +365,7 @@ func TestClientGoUtils_DeleteService(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClientGoUtils_DeletePod(t *testing.T) {
|
||||
t.Parallel()
|
||||
type fields struct {
|
||||
Verbose bool
|
||||
}
|
||||
@@ -417,6 +423,7 @@ func TestClientGoUtils_DeletePod(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClientGoUtils_CreatePreflightTestPod(t *testing.T) {
|
||||
t.Parallel()
|
||||
fk := fake.NewSimpleClientset()
|
||||
fk.Fake.PrependReactor("create", "pods", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
|
||||
return true, &apiv1.Pod{}, errors.New("Error creating pod")
|
||||
@@ -560,6 +567,7 @@ func TestClientGoUtils_CreatePreflightTestPod(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClientGoUtils_getPod(t *testing.T) {
|
||||
t.Parallel()
|
||||
type fields struct {
|
||||
Verbose bool
|
||||
}
|
||||
@@ -632,6 +640,7 @@ func TestClientGoUtils_getPod(t *testing.T) {
|
||||
// There is an issue with mocking logs: https://github.com/kubernetes/kubernetes/issues/84203
|
||||
// We are waiting for this PR: https://github.com/kubernetes/kubernetes/pull/91485/files to be merged to be able to test this feature
|
||||
func TestClientGoUtils_GetPodContainerLogs(t *testing.T) {
|
||||
t.SkipNow()
|
||||
type fields struct {
|
||||
Verbose bool
|
||||
}
|
||||
@@ -645,6 +654,7 @@ func TestClientGoUtils_GetPodContainerLogs(t *testing.T) {
|
||||
fields fields
|
||||
args args
|
||||
want string
|
||||
mockLog string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
@@ -666,6 +676,7 @@ func TestClientGoUtils_GetPodContainerLogs(t *testing.T) {
|
||||
container: "",
|
||||
},
|
||||
want: "blah",
|
||||
mockLog: "blah",
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
@@ -687,7 +698,8 @@ func TestClientGoUtils_GetPodContainerLogs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClientGoUtils_WaitForDeployment(t *testing.T) {
|
||||
waitTimeout = 30 * time.Second
|
||||
t.Parallel()
|
||||
waitTimeout = 10 * time.Second
|
||||
dep := &appsv1.Deployment{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-dep",
|
||||
@@ -725,7 +737,7 @@ func TestClientGoUtils_WaitForDeployment(t *testing.T) {
|
||||
pfDeployment: dep,
|
||||
},
|
||||
wantErr: false,
|
||||
timeoutForChangingReplicaCount: 10 * time.Second,
|
||||
timeoutForChangingReplicaCount: 6 * time.Second,
|
||||
mockErr: false,
|
||||
},
|
||||
{
|
||||
@@ -823,7 +835,8 @@ func TestClientGoUtils_WaitForDeployment(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClientGoUtils_WaitForPod(t *testing.T) {
|
||||
waitTimeout = 30 * time.Second
|
||||
t.Parallel()
|
||||
waitTimeout = 10 * time.Second
|
||||
po := &apiv1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-dep",
|
||||
@@ -866,7 +879,7 @@ func TestClientGoUtils_WaitForPod(t *testing.T) {
|
||||
pod: po,
|
||||
},
|
||||
wantErr: false,
|
||||
timeoutForChangingReplicaCount: 10 * time.Second,
|
||||
timeoutForChangingReplicaCount: 6 * time.Second,
|
||||
mockErr: false,
|
||||
},
|
||||
{
|
||||
@@ -1037,7 +1050,8 @@ func TestClientGoUtils_WaitForPod(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClientGoUtils_WaitForPodToDie(t *testing.T) {
|
||||
waitTimeout = 30 * time.Second
|
||||
t.Parallel()
|
||||
waitTimeout = 10 * time.Second
|
||||
po := &apiv1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-dep",
|
||||
@@ -1080,7 +1094,7 @@ func TestClientGoUtils_WaitForPodToDie(t *testing.T) {
|
||||
pod: po,
|
||||
},
|
||||
wantErr: false,
|
||||
timeoutForChangingReplicaCount: 10 * time.Second,
|
||||
timeoutForChangingReplicaCount: 6 * time.Second,
|
||||
mockErr: false,
|
||||
},
|
||||
{
|
||||
@@ -1191,7 +1205,8 @@ func TestClientGoUtils_WaitForPodToDie(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClientGoUtils_waitForPodToDelete(t *testing.T) {
|
||||
waitTimeout = 30 * time.Second
|
||||
t.Parallel()
|
||||
waitTimeout = 10 * time.Second
|
||||
po := &apiv1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-pod",
|
||||
@@ -1225,7 +1240,7 @@ func TestClientGoUtils_waitForPodToDelete(t *testing.T) {
|
||||
pod: "test-pod",
|
||||
},
|
||||
wantErr: false,
|
||||
timeoutForChangingReplicaCount: 10 * time.Second,
|
||||
timeoutForChangingReplicaCount: 6 * time.Second,
|
||||
},
|
||||
{
|
||||
name: "valid case instant",
|
||||
@@ -1273,7 +1288,8 @@ func TestClientGoUtils_waitForPodToDelete(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClientGoUtils_WaitForDeploymentToDelete(t *testing.T) {
|
||||
waitTimeout = 30 * time.Second
|
||||
t.Parallel()
|
||||
waitTimeout = 10 * time.Second
|
||||
dep := &appsv1.Deployment{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-dep",
|
||||
@@ -1309,7 +1325,7 @@ func TestClientGoUtils_WaitForDeploymentToDelete(t *testing.T) {
|
||||
deploymentName: dep.Name,
|
||||
},
|
||||
wantErr: false,
|
||||
timeoutForChangingReplicaCount: 10 * time.Second,
|
||||
timeoutForChangingReplicaCount: 6 * time.Second,
|
||||
},
|
||||
{
|
||||
name: "valid case instant",
|
||||
@@ -1357,6 +1373,7 @@ func TestClientGoUtils_WaitForDeploymentToDelete(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClientGoUtils_CreatePreflightTestSecret(t *testing.T) {
|
||||
t.Parallel()
|
||||
fk := fake.NewSimpleClientset()
|
||||
fk.Fake.PrependReactor("create", "secrets", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
|
||||
return true, &apiv1.Secret{}, errors.New("Error creating deployment")
|
||||
@@ -1431,6 +1448,7 @@ func TestClientGoUtils_CreatePreflightTestSecret(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClientGoUtils_DeleteK8sSecret(t *testing.T) {
|
||||
t.Parallel()
|
||||
type fields struct {
|
||||
Verbose bool
|
||||
}
|
||||
@@ -1484,6 +1502,7 @@ func TestClientGoUtils_DeleteK8sSecret(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClientGoUtils_CreateStatefulSet(t *testing.T) {
|
||||
t.Parallel()
|
||||
fk := fake.NewSimpleClientset()
|
||||
fk.Fake.PrependReactor("create", "statefulsets", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
|
||||
return true, &appsv1.StatefulSet{}, errors.New("Error")
|
||||
@@ -1586,3 +1605,346 @@ func TestClientGoUtils_CreateStatefulSet(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientGoUtils_waitForStatefulSet(t *testing.T) {
|
||||
t.Parallel()
|
||||
waitTimeout = 10 * time.Second
|
||||
ss := &appsv1.StatefulSet{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-ss",
|
||||
Namespace: "test-ns",
|
||||
},
|
||||
Status: appsv1.StatefulSetStatus{
|
||||
ReadyReplicas: 0,
|
||||
},
|
||||
}
|
||||
|
||||
type fields struct {
|
||||
Verbose bool
|
||||
}
|
||||
type args struct {
|
||||
clientset kubernetes.Interface
|
||||
namespace string
|
||||
pfStatefulset *appsv1.StatefulSet
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantErr bool
|
||||
timeoutForChangingReplicaCount time.Duration
|
||||
mockErr bool
|
||||
}{
|
||||
{
|
||||
name: "valid case",
|
||||
fields: fields{
|
||||
Verbose: true,
|
||||
},
|
||||
args: args{
|
||||
clientset: fake.NewSimpleClientset(ss),
|
||||
namespace: "test-ns",
|
||||
pfStatefulset: ss,
|
||||
},
|
||||
wantErr: false,
|
||||
timeoutForChangingReplicaCount: 6 * time.Second,
|
||||
mockErr: false,
|
||||
},
|
||||
{
|
||||
name: "valid case instantly ready",
|
||||
fields: fields{
|
||||
Verbose: true,
|
||||
},
|
||||
args: args{
|
||||
clientset: fake.NewSimpleClientset(&appsv1.StatefulSet{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-ss",
|
||||
Namespace: "test-ns",
|
||||
},
|
||||
Status: appsv1.StatefulSetStatus{
|
||||
ReadyReplicas: 1,
|
||||
},
|
||||
}),
|
||||
namespace: "test-ns",
|
||||
pfStatefulset: ss,
|
||||
},
|
||||
wantErr: false,
|
||||
mockErr: false,
|
||||
},
|
||||
{
|
||||
name: "k8s returning error case",
|
||||
fields: fields{
|
||||
Verbose: true,
|
||||
},
|
||||
args: args{
|
||||
clientset: fake.NewSimpleClientset(ss),
|
||||
namespace: "test-ns",
|
||||
pfStatefulset: ss,
|
||||
},
|
||||
wantErr: true,
|
||||
mockErr: true,
|
||||
},
|
||||
{
|
||||
name: "timeout",
|
||||
fields: fields{
|
||||
Verbose: true,
|
||||
},
|
||||
args: args{
|
||||
clientset: fake.NewSimpleClientset(ss),
|
||||
namespace: "test-ns",
|
||||
pfStatefulset: ss,
|
||||
},
|
||||
wantErr: true,
|
||||
mockErr: false,
|
||||
},
|
||||
{
|
||||
name: "statefulset goes missing",
|
||||
fields: fields{
|
||||
Verbose: true,
|
||||
},
|
||||
args: args{
|
||||
clientset: fake.NewSimpleClientset(),
|
||||
namespace: "test-ns",
|
||||
pfStatefulset: ss,
|
||||
},
|
||||
wantErr: true,
|
||||
mockErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.timeoutForChangingReplicaCount.Seconds() > 0 {
|
||||
go func() {
|
||||
time.Sleep(tt.timeoutForChangingReplicaCount)
|
||||
tt.args.clientset.(*fake.Clientset).Fake.PrependReactor("get", "statefulsets", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
|
||||
return true, &appsv1.StatefulSet{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-ss",
|
||||
Namespace: "test-ns",
|
||||
},
|
||||
Status: appsv1.StatefulSetStatus{
|
||||
ReadyReplicas: 1,
|
||||
},
|
||||
}, nil
|
||||
})
|
||||
}()
|
||||
}
|
||||
if tt.mockErr {
|
||||
tt.args.clientset.(*fake.Clientset).Fake.PrependReactor("get", "statefulsets", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
|
||||
return true, &appsv1.StatefulSet{}, fmt.Errorf("error")
|
||||
})
|
||||
}
|
||||
p := &ClientGoUtils{
|
||||
Verbose: tt.fields.Verbose,
|
||||
}
|
||||
if err := p.waitForStatefulSet(tt.args.clientset, tt.args.namespace, tt.args.pfStatefulset); (err != nil) != tt.wantErr {
|
||||
t.Errorf("ClientGoUtils.waitForStatefulSet() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientGoUtils_getStatefulset(t *testing.T) {
|
||||
t.Parallel()
|
||||
type fields struct {
|
||||
Verbose bool
|
||||
}
|
||||
type args struct {
|
||||
clientset kubernetes.Interface
|
||||
namespace string
|
||||
statefulsetName string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
want *appsv1.StatefulSet
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "valid case",
|
||||
fields: fields{Verbose: true},
|
||||
args: args{
|
||||
clientset: fake.NewSimpleClientset(&appsv1.StatefulSet{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
Name: "test-ss",
|
||||
Namespace: "test-ns",
|
||||
},
|
||||
}),
|
||||
namespace: "test-ns",
|
||||
statefulsetName: "test-ss",
|
||||
},
|
||||
want: &appsv1.StatefulSet{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
Name: "test-ss",
|
||||
Namespace: "test-ns",
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "retrieve non-existent ss",
|
||||
fields: fields{Verbose: true},
|
||||
args: args{
|
||||
clientset: fake.NewSimpleClientset(),
|
||||
namespace: "test-ns",
|
||||
statefulsetName: "test-ss",
|
||||
},
|
||||
want: nil,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
p := &ClientGoUtils{
|
||||
Verbose: tt.fields.Verbose,
|
||||
}
|
||||
got, err := p.getStatefulset(tt.args.clientset, tt.args.namespace, tt.args.statefulsetName)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("ClientGoUtils.getStatefulset() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("ClientGoUtils.getStatefulset() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientGoUtils_deleteStatefulSet(t *testing.T) {
|
||||
t.Parallel()
|
||||
type fields struct {
|
||||
Verbose bool
|
||||
}
|
||||
type args struct {
|
||||
clientset kubernetes.Interface
|
||||
namespace string
|
||||
name string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "valid case",
|
||||
fields: fields{Verbose: true},
|
||||
args: args{
|
||||
clientset: fake.NewSimpleClientset(&appsv1.StatefulSet{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
Name: "test-ss",
|
||||
Namespace: "test-ns",
|
||||
},
|
||||
}),
|
||||
name: "test-ss",
|
||||
namespace: "test-ns",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "delete non-existent ss case",
|
||||
fields: fields{Verbose: true},
|
||||
args: args{
|
||||
clientset: fake.NewSimpleClientset(),
|
||||
name: "test-ss",
|
||||
namespace: "test-ns",
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
p := &ClientGoUtils{
|
||||
Verbose: tt.fields.Verbose,
|
||||
}
|
||||
if err := p.deleteStatefulSet(tt.args.clientset, tt.args.namespace, tt.args.name); (err != nil) != tt.wantErr {
|
||||
t.Errorf("ClientGoUtils.deleteStatefulSet() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientGoUtils_waitForStatefulsetToDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
waitTimeout = 10 * time.Second
|
||||
ss := &appsv1.StatefulSet{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-ss",
|
||||
Namespace: "test-ns",
|
||||
},
|
||||
Status: appsv1.StatefulSetStatus{
|
||||
ReadyReplicas: 0,
|
||||
},
|
||||
}
|
||||
type fields struct {
|
||||
Verbose bool
|
||||
}
|
||||
type args struct {
|
||||
clientset kubernetes.Interface
|
||||
namespace string
|
||||
statefulsetName string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantErr bool
|
||||
timeoutForChangingReplicaCount time.Duration
|
||||
}{
|
||||
{
|
||||
name: "valid case",
|
||||
fields: fields{
|
||||
Verbose: true,
|
||||
},
|
||||
args: args{
|
||||
clientset: fake.NewSimpleClientset(ss),
|
||||
namespace: "test-ns",
|
||||
statefulsetName: ss.Name,
|
||||
},
|
||||
wantErr: false,
|
||||
timeoutForChangingReplicaCount: 6 * time.Second,
|
||||
},
|
||||
{
|
||||
name: "valid case instant",
|
||||
fields: fields{
|
||||
Verbose: true,
|
||||
},
|
||||
args: args{
|
||||
clientset: fake.NewSimpleClientset(),
|
||||
namespace: "test-ns",
|
||||
statefulsetName: ss.Name,
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "timeout",
|
||||
fields: fields{
|
||||
Verbose: true,
|
||||
},
|
||||
args: args{
|
||||
clientset: fake.NewSimpleClientset(ss),
|
||||
namespace: "test-ns",
|
||||
statefulsetName: ss.Name,
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.timeoutForChangingReplicaCount.Seconds() > 0 {
|
||||
go func() {
|
||||
time.Sleep(tt.timeoutForChangingReplicaCount)
|
||||
tt.args.clientset.(*fake.Clientset).Fake.PrependReactor("get", "statefulsets", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) {
|
||||
return true, &appsv1.StatefulSet{}, fmt.Errorf("error")
|
||||
})
|
||||
}()
|
||||
}
|
||||
p := &ClientGoUtils{
|
||||
Verbose: tt.fields.Verbose,
|
||||
}
|
||||
if err := p.waitForStatefulsetToDelete(tt.args.clientset, tt.args.namespace, tt.args.statefulsetName); (err != nil) != tt.wantErr {
|
||||
t.Errorf("ClientGoUtils.waitForStatefulsetToDelete() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,90 +15,90 @@ func (qp *QliksensePreflight) RunAllPreflightChecks(kubeConfigContents []byte, n
|
||||
out := ansi.NewColorableStdout()
|
||||
// Preflight minimum kuberenetes version check
|
||||
if err := qp.CheckK8sVersion(namespace, kubeConfigContents); err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight kubernetes minimum version check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n\n", err)
|
||||
} else {
|
||||
fmt.Fprintf(out, "%s\n\n", Green("Preflight kubernetes minimum version check PASSED"))
|
||||
fmt.Fprintf(out, "%s\n\n", Green("PASSED"))
|
||||
checkCount++
|
||||
}
|
||||
totalCount++
|
||||
|
||||
// Preflight deployment check
|
||||
if err := qp.CheckDeployment(namespace, kubeConfigContents, false); err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight deployment check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n\n", err)
|
||||
} else {
|
||||
fmt.Fprintf(out, "%s\n\n", Green("Preflight deployment check PASSED"))
|
||||
fmt.Fprintf(out, "%s\n\n", Green("PASSED"))
|
||||
checkCount++
|
||||
}
|
||||
totalCount++
|
||||
|
||||
// Preflight service check
|
||||
if err := qp.CheckService(namespace, kubeConfigContents, false); err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight service check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n\n", err)
|
||||
} else {
|
||||
fmt.Fprintf(out, "%s\n\n", Green("Preflight service check PASSED"))
|
||||
fmt.Fprintf(out, "%s\n\n", Green("PASSED"))
|
||||
checkCount++
|
||||
}
|
||||
totalCount++
|
||||
|
||||
// Preflight pod check
|
||||
if err := qp.CheckPod(namespace, kubeConfigContents, false); err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight pod check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n\n", err)
|
||||
} else {
|
||||
fmt.Fprintf(out, "%s\n\n", Green("Preflight pod check PASSED"))
|
||||
fmt.Fprintf(out, "%s\n\n", Green("PASSED"))
|
||||
checkCount++
|
||||
}
|
||||
totalCount++
|
||||
|
||||
// Preflight role check
|
||||
if err := qp.CheckCreateRole(namespace, false); err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red("Preflight role check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n\n", err)
|
||||
} else {
|
||||
fmt.Fprintf(out, "%s\n\n", Green("Preflight role check PASSED"))
|
||||
fmt.Fprintf(out, "%s\n\n", Green("PASSED"))
|
||||
checkCount++
|
||||
}
|
||||
totalCount++
|
||||
|
||||
// Preflight rolebinding check
|
||||
if err := qp.CheckCreateRoleBinding(namespace, false); err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red(" Preflight rolebinding check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n\n", err)
|
||||
} else {
|
||||
fmt.Fprintf(out, "%s\n\n", Green("Preflight rolebinding check PASSED"))
|
||||
fmt.Fprintf(out, "%s\n\n", Green("PASSED"))
|
||||
checkCount++
|
||||
}
|
||||
totalCount++
|
||||
|
||||
// Preflight serviceaccount check
|
||||
if err := qp.CheckCreateServiceAccount(namespace, false); err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red(" Preflight serviceaccount check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n\n", err)
|
||||
} else {
|
||||
fmt.Fprintf(out, "%s\n\n", Green("Preflight serviceaccount check PASSED"))
|
||||
fmt.Fprintf(out, "%s\n\n", Green("PASSED"))
|
||||
checkCount++
|
||||
}
|
||||
totalCount++
|
||||
|
||||
// Preflight mongo check
|
||||
if err := qp.CheckMongo(kubeConfigContents, namespace, preflightOpts, false); err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red(" Preflight mongo check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n\n", err)
|
||||
} else {
|
||||
fmt.Fprintf(out, "%s\n\n", Green("Preflight mongo check PASSED"))
|
||||
fmt.Fprintf(out, "%s\n\n", Green("PASSED"))
|
||||
checkCount++
|
||||
}
|
||||
totalCount++
|
||||
|
||||
// Preflight DNS check
|
||||
if err := qp.CheckDns(namespace, kubeConfigContents, false); err != nil {
|
||||
fmt.Fprintf(out, "%s\n", Red(" Preflight DNS check FAILED"))
|
||||
fmt.Fprintf(out, "%s\n", Red("FAILED"))
|
||||
fmt.Printf("Error: %v\n\n", err)
|
||||
} else {
|
||||
fmt.Fprintf(out, "%s\n\n", Green("Preflight DNS check PASSED"))
|
||||
fmt.Fprintf(out, "%s\n\n", Green("PASSED"))
|
||||
checkCount++
|
||||
}
|
||||
totalCount++
|
||||
|
||||
@@ -15,8 +15,8 @@ func (p *QliksensePreflight) CheckDeployment(namespace string, kubeConfigContent
|
||||
|
||||
// Deployment check
|
||||
if !cleanup {
|
||||
p.CG.LogVerboseMessage("Preflight deployment check: \n")
|
||||
p.CG.LogVerboseMessage("--------------------------- \n")
|
||||
fmt.Print("Preflight deployment check... ")
|
||||
p.CG.LogVerboseMessage("\n--------------------------- \n")
|
||||
}
|
||||
err = p.checkPfDeployment(clientset, namespace, cleanup)
|
||||
if err != nil {
|
||||
@@ -38,8 +38,8 @@ func (p *QliksensePreflight) CheckService(namespace string, kubeConfigContents [
|
||||
}
|
||||
// Service check
|
||||
if !cleanup {
|
||||
p.CG.LogVerboseMessage("Preflight service check: \n")
|
||||
p.CG.LogVerboseMessage("------------------------ \n")
|
||||
fmt.Print("Preflight service check... ")
|
||||
p.CG.LogVerboseMessage("\n------------------------ \n")
|
||||
}
|
||||
err = p.checkPfService(clientset, namespace, cleanup)
|
||||
if err != nil {
|
||||
@@ -61,8 +61,8 @@ func (p *QliksensePreflight) CheckPod(namespace string, kubeConfigContents []byt
|
||||
}
|
||||
// Pod check
|
||||
if !cleanup {
|
||||
p.CG.LogVerboseMessage("Preflight pod check: \n")
|
||||
p.CG.LogVerboseMessage("-------------------- \n")
|
||||
fmt.Print("Preflight pod check... ")
|
||||
p.CG.LogVerboseMessage("\n-------------------- \n")
|
||||
}
|
||||
err = p.checkPfPod(clientset, namespace, cleanup)
|
||||
if err != nil {
|
||||
|
||||
@@ -18,8 +18,8 @@ func (p *QliksensePreflight) CheckDns(namespace string, kubeConfigContents []byt
|
||||
podName := "pf-pod-1"
|
||||
|
||||
if !cleanup {
|
||||
p.CG.LogVerboseMessage("Preflight DNS check: \n")
|
||||
p.CG.LogVerboseMessage("------------------- \n")
|
||||
fmt.Print("Preflight DNS check... ")
|
||||
p.CG.LogVerboseMessage("\n------------------- \n")
|
||||
}
|
||||
clientset, _, err := p.CG.GetK8SClientSet(kubeConfigContents, "")
|
||||
if err != nil {
|
||||
|
||||
@@ -22,8 +22,8 @@ const (
|
||||
|
||||
func (qp *QliksensePreflight) CheckMongo(kubeConfigContents []byte, namespace string, preflightOpts *PreflightOptions, cleanup bool) error {
|
||||
if !cleanup {
|
||||
qp.CG.LogVerboseMessage("Preflight mongodb check: \n")
|
||||
qp.CG.LogVerboseMessage("------------------------ \n")
|
||||
fmt.Print("Preflight mongodb check... ")
|
||||
qp.CG.LogVerboseMessage("\n------------------------ \n")
|
||||
}
|
||||
var currentCR *qapi.QliksenseCR
|
||||
var err error
|
||||
|
||||
@@ -10,13 +10,6 @@ type PreflightOptions struct {
|
||||
MongoOptions *MongoOptions
|
||||
}
|
||||
|
||||
// // LogVerboseMessage logs a verbose message
|
||||
// func (p *PreflightOptions) LogVerboseMessage(strMessage string, args ...interface{}) {
|
||||
// if p.Verbose || os.Getenv("QLIKSENSE_DEBUG") == "true" {
|
||||
// fmt.Printf(strMessage, args...)
|
||||
// }
|
||||
// }
|
||||
|
||||
type MongoOptions struct {
|
||||
MongodbUrl string
|
||||
CaCertFile string
|
||||
|
||||
@@ -14,8 +14,8 @@ import (
|
||||
func (qp *QliksensePreflight) CheckCreateRole(namespace string, cleanup bool) error {
|
||||
// create a Role
|
||||
if !cleanup {
|
||||
qp.CG.LogVerboseMessage("Preflight role check: \n")
|
||||
qp.CG.LogVerboseMessage("--------------------- \n")
|
||||
fmt.Print("Preflight role check... ")
|
||||
qp.CG.LogVerboseMessage("\n--------------------- \n")
|
||||
}
|
||||
err := qp.checkCreateEntity(namespace, "Role", cleanup)
|
||||
if err != nil {
|
||||
@@ -30,8 +30,8 @@ func (qp *QliksensePreflight) CheckCreateRole(namespace string, cleanup bool) er
|
||||
func (qp *QliksensePreflight) CheckCreateRoleBinding(namespace string, cleanup bool) error {
|
||||
// create a RoleBinding
|
||||
if !cleanup {
|
||||
qp.CG.LogVerboseMessage("Preflight rolebinding check: \n")
|
||||
qp.CG.LogVerboseMessage("---------------------------- \n")
|
||||
fmt.Print("Preflight rolebinding check... ")
|
||||
qp.CG.LogVerboseMessage("\n---------------------------- \n")
|
||||
}
|
||||
err := qp.checkCreateEntity(namespace, "RoleBinding", cleanup)
|
||||
if err != nil {
|
||||
@@ -46,8 +46,8 @@ func (qp *QliksensePreflight) CheckCreateRoleBinding(namespace string, cleanup b
|
||||
func (qp *QliksensePreflight) CheckCreateServiceAccount(namespace string, cleanup bool) error {
|
||||
// create a service account
|
||||
if !cleanup {
|
||||
qp.CG.LogVerboseMessage("Preflight serviceaccount check: \n")
|
||||
qp.CG.LogVerboseMessage("------------------------------- \n")
|
||||
fmt.Print("Preflight serviceaccount check... ")
|
||||
qp.CG.LogVerboseMessage("\n------------------------------- \n")
|
||||
}
|
||||
err := qp.checkCreateEntity(namespace, "ServiceAccount", cleanup)
|
||||
if err != nil {
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
)
|
||||
|
||||
func (p *QliksensePreflight) CheckK8sVersion(namespace string, kubeConfigContents []byte) error {
|
||||
p.CG.LogVerboseMessage("Preflight kubernetes version check: \n")
|
||||
p.CG.LogVerboseMessage("----------------------------------- \n")
|
||||
fmt.Print("Preflight kubernetes version check... ")
|
||||
p.CG.LogVerboseMessage("\n----------------------------------- \n")
|
||||
var currentVersion *semver.Version
|
||||
|
||||
clientset, _, err := p.CG.GetK8SClientSet(kubeConfigContents, "")
|
||||
|
||||
@@ -23,13 +23,12 @@ type patch struct {
|
||||
Patch string `yaml:"patch"`
|
||||
}
|
||||
|
||||
type selectivePatch struct {
|
||||
type annotationTransformer struct {
|
||||
APIVersion string `yaml:"apiVersion"`
|
||||
Metadata struct {
|
||||
Name string `yaml:"name"`
|
||||
} `yaml:"metadata"`
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Patches []patch `yaml:"patches"`
|
||||
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
|
||||
}
|
||||
|
||||
type helmChart struct {
|
||||
@@ -73,7 +72,7 @@ func (q *Qliksense) About(gitRef, profile string) (*VersionOutput, error) {
|
||||
}
|
||||
|
||||
func (q *Qliksense) AboutDir(configDirectory, profile string) (*VersionOutput, error) {
|
||||
if chartVersion, err := getChartVersion(filepath.Join(configDirectory, "transformers", "qseokversion.yaml"), "qliksense"); err != nil {
|
||||
if chartVersion, err := getChartVersion(filepath.Join(configDirectory, "manifests", "base", "transformers", "release", "annotations.yaml"), "app.kubernetes.io/version"); err != nil {
|
||||
return nil, err
|
||||
} else if kuzManifest, err := executeKustomizeBuildWithStdoutProgress(filepath.Join(configDirectory, "manifests", profile)); err != nil {
|
||||
return nil, err
|
||||
@@ -223,22 +222,16 @@ func traverseYamlDecodedMapRecursively(val reflect.Value, path []string, visitor
|
||||
}
|
||||
}
|
||||
|
||||
func getChartVersion(versionFile, chartName string) (string, error) {
|
||||
var patchInst patch
|
||||
var selPatch selectivePatch
|
||||
var chart helmChart
|
||||
func getChartVersion(versionFile, versionAnnotation string) (string, error) {
|
||||
var annTransformer annotationTransformer
|
||||
|
||||
if bytes, err := ioutil.ReadFile(versionFile); err != nil {
|
||||
return "", err
|
||||
} else if err = yaml.Unmarshal(bytes, &selPatch); err != nil {
|
||||
} else if err = yaml.Unmarshal(bytes, &annTransformer); err != nil {
|
||||
return "", err
|
||||
}
|
||||
for _, patchInst = range selPatch.Patches {
|
||||
if err := yaml.Unmarshal([]byte(patchInst.Patch), &chart); err == nil {
|
||||
if chart.ChartName == chartName {
|
||||
return chart.ChartVersion, nil
|
||||
}
|
||||
}
|
||||
if version, ok := annTransformer.Annotations[versionAnnotation]; ok {
|
||||
return version, nil
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
qapi "github.com/qlik-oss/sense-installer/pkg/api"
|
||||
)
|
||||
|
||||
func (q *Qliksense) ApplyCRFromReader(r io.Reader, opts *InstallCommandOptions, keepPatchFiles, overwriteExistingContext, pull, push bool) error {
|
||||
func (q *Qliksense) ApplyCRFromReader(r io.Reader, opts *InstallCommandOptions, cleanPatchFiles, overwriteExistingContext, pull, push bool) error {
|
||||
if err := q.LoadCr(r, overwriteExistingContext); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -40,9 +40,9 @@ func (q *Qliksense) ApplyCRFromReader(r io.Reader, opts *InstallCommandOptions,
|
||||
}
|
||||
}
|
||||
}
|
||||
return q.UpgradeQK8s(keepPatchFiles)
|
||||
return q.UpgradeQK8s(cleanPatchFiles)
|
||||
}
|
||||
return q.InstallQK8s(version, opts, keepPatchFiles)
|
||||
return q.InstallQK8s(version, opts, cleanPatchFiles)
|
||||
}
|
||||
|
||||
func IsQliksenseInstalled(crName string) bool {
|
||||
|
||||
@@ -315,23 +315,23 @@ spec:
|
||||
return err
|
||||
}
|
||||
|
||||
transformersDir := path.Join(manifestsRootDir, "transformers")
|
||||
transformersDir := path.Join(manifestsRootDir, "manifests", "base", "transformers", "release")
|
||||
if err := os.MkdirAll(transformersDir, os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ioutil.WriteFile(path.Join(transformersDir, "qseokversion.yaml"), []byte(`
|
||||
apiVersion: qlik.com/v1
|
||||
kind: SelectivePatch
|
||||
if err := ioutil.WriteFile(path.Join(transformersDir, "annotations.yaml"), []byte(`
|
||||
apiVersion: builtin
|
||||
kind: AnnotationsTransformer
|
||||
metadata:
|
||||
name: qseokversion
|
||||
enabled: true
|
||||
patches:
|
||||
- target:
|
||||
kind: HelmChart
|
||||
labelSelector: name!=qliksense-init
|
||||
patch: |-
|
||||
chartName: qliksense
|
||||
chartVersion: 1.21.23
|
||||
name: common-annotations
|
||||
annotations:
|
||||
app.kubernetes.io/name: qliksense
|
||||
app.kubernetes.io/instance: $(PREFIX)
|
||||
app.kubernetes.io/version: 1.21.23
|
||||
app.kubernetes.io/managed-by: qliksense-operator
|
||||
fieldSpecs:
|
||||
- path: metadata/annotations
|
||||
create: true
|
||||
`), os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ func getVersion(opts *FetchCommandOptions, qcr *qapi.QliksenseCR) string {
|
||||
|
||||
func getVerionsOverwriteConfirmation(version string) string {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
fmt.Println("The version [" + version + "] already exist")
|
||||
fmt.Println("The version [" + version + "] already exists")
|
||||
cfm := "n"
|
||||
for {
|
||||
fmt.Print("Do you want to delete and fetch again [y/N]: ")
|
||||
|
||||
@@ -23,7 +23,7 @@ type InstallCommandOptions struct {
|
||||
DryRun bool
|
||||
}
|
||||
|
||||
func (q *Qliksense) InstallQK8s(version string, opts *InstallCommandOptions, keepPatchFiles bool) error {
|
||||
func (q *Qliksense) InstallQK8s(version string, opts *InstallCommandOptions, cleanPatchFiles bool) error {
|
||||
|
||||
// step1: fetch 1.0.0 # pull down qliksense-k8s@1.0.0
|
||||
// step2: operator view | kubectl apply -f # operator manifest (CRD)
|
||||
@@ -32,7 +32,7 @@ func (q *Qliksense) InstallQK8s(version string, opts *InstallCommandOptions, kee
|
||||
|
||||
// fetch the version
|
||||
qConfig := qapi.NewQConfig(q.QliksenseHome)
|
||||
if !keepPatchFiles {
|
||||
if cleanPatchFiles {
|
||||
if err := q.DiscardAllUnstagedChangesFromGitRepo(qConfig); err != nil {
|
||||
fmt.Printf("error removing temporary changes to the config: %v\n", err)
|
||||
}
|
||||
@@ -123,7 +123,7 @@ func (q *Qliksense) InstallQK8s(version string, opts *InstallCommandOptions, kee
|
||||
return err
|
||||
} else {
|
||||
if IsQliksenseInstalled(dcr.GetName()) {
|
||||
return q.UpgradeQK8s(keepPatchFiles)
|
||||
return q.UpgradeQK8s(cleanPatchFiles)
|
||||
}
|
||||
if err := q.applyConfigToK8s(dcr); err != nil {
|
||||
fmt.Println("cannot do kubectl apply on manifests")
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
qapi "github.com/qlik-oss/sense-installer/pkg/api"
|
||||
)
|
||||
|
||||
func (q *Qliksense) UpgradeQK8s(keepPatchFiles bool) error {
|
||||
func (q *Qliksense) UpgradeQK8s(cleanPatchFiles bool) error {
|
||||
|
||||
// step1: get CR
|
||||
// step2: run kustomize
|
||||
@@ -14,12 +14,10 @@ func (q *Qliksense) UpgradeQK8s(keepPatchFiles bool) error {
|
||||
|
||||
// fetch the version
|
||||
qConfig := qapi.NewQConfig(q.QliksenseHome)
|
||||
if !keepPatchFiles {
|
||||
defer func() {
|
||||
if err := q.DiscardAllUnstagedChangesFromGitRepo(qConfig); err != nil {
|
||||
fmt.Printf("error removing temporary changes to the config: %v\n", err)
|
||||
}
|
||||
}()
|
||||
if cleanPatchFiles {
|
||||
if err := q.DiscardAllUnstagedChangesFromGitRepo(qConfig); err != nil {
|
||||
fmt.Printf("error removing temporary changes to the config: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
qcr, err := qConfig.GetCurrentCR()
|
||||
|
||||
Reference in New Issue
Block a user