Skip to content

Commit

Permalink
Add api password for e2e-test (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mir Shahriar authored and tamalsaha committed May 25, 2018
1 parent c520036 commit abef69f
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 227 deletions.
4 changes: 4 additions & 0 deletions chart/searchlight/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ data:
ICINGA_WEB_UI_PASSWORD: {{ .Values.icinga2web.password | b64enc | quote }}
{{ else }}
ICINGA_WEB_UI_PASSWORD: {{ randAlphaNum 10 | b64enc | quote }}
{{- if .Values.icinga2.password }}
ICINGA_API_PASSWORD: {{ .Values.icinga2.password | b64enc | quote }}
{{ else }}
ICINGA_API_PASSWORD: {{ randAlphaNum 10 | b64enc | quote }}
{{ end -}}
{{- if .Values.notifier.hipchat.authToken }}
HIPCHAT_AUTH_TOKEN: {{ .Values.notifier.hipchat.authToken | b64enc | quote }}
Expand Down
3 changes: 3 additions & 0 deletions chart/searchlight/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ logLevel: 3
icinga2web:
password: changeit

icinga2:
password:

notifier:
hipchat:
authToken: ''
Expand Down
1 change: 1 addition & 0 deletions docs/setup/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ options:
--image-pull-secret name of secret used to pull searchlight operator images
--run-on-master run searchlight operator on master
--enable-validating-webhook enable/disable validating webhooks for Searchlight CRD
--icinga-api-password password used by icinga2 api (if unset, a random password will be generated and used)
--enable-analytics send usage events to Google Analytics (default: true)
--uninstall uninstall searchlight
--purge purges searchlight crd objects and crds
Expand Down
1 change: 1 addition & 0 deletions hack/deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ metadata:
app: searchlight
data:
ICINGA_WEB_UI_PASSWORD: Y2hhbmdlaXQ=
${SEARCHLIGHT_ICINGA_API_PASSWORD}
---
apiVersion: apps/v1beta1
kind: Deployment
Expand Down
8 changes: 8 additions & 0 deletions hack/deploy/searchlight.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export SEARCHLIGHT_NAMESPACE=kube-system
export SEARCHLIGHT_SERVICE_ACCOUNT=searchlight-operator
export SEARCHLIGHT_ENABLE_RBAC=true
export SEARCHLIGHT_RUN_ON_MASTER=0
export SEARCHLIGHT_ICINGA_API_PASSWORD=
export SEARCHLIGHT_ENABLE_VALIDATING_WEBHOOK=false
export SEARCHLIGHT_DOCKER_REGISTRY=appscode
export SEARCHLIGHT_OPERATOR_TAG=7.0.0-rc.0
Expand Down Expand Up @@ -127,6 +128,7 @@ show_help() {
echo " --image-pull-secret name of secret used to pull searchlight operator images"
echo " --run-on-master run searchlight operator on master"
echo " --enable-validating-webhook enable/disable validating webhooks for Searchlight CRDs"
echo " --icinga-api-password password used by icinga2 api (if unset, a random password will be generated and used)"
echo " --enable-analytics send usage events to Google Analytics (default: true)"
echo " --uninstall uninstall searchlight"
echo " --purge purges searchlight crd objects and crds"
Expand Down Expand Up @@ -187,6 +189,12 @@ while test $# -gt 0; do
export SEARCHLIGHT_RUN_ON_MASTER=1
shift
;;
--icinga-api-password*)
pass=`echo $1 | sed -e 's/^[^=]*=//g'`
pass_b64=`echo -n $pass | $ONESSL base64`
export SEARCHLIGHT_ICINGA_API_PASSWORD="ICINGA_API_PASSWORD: '$pass_b64'"
shift
;;
--uninstall)
export SEARCHLIGHT_UNINSTALL=1
shift
Expand Down
57 changes: 15 additions & 42 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/appscode/searchlight/pkg/icinga"
"github.com/appscode/searchlight/pkg/operator"
"github.com/appscode/searchlight/test/e2e/framework"
. "github.com/appscode/searchlight/test/e2e/matcher"
. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/reporters"
. "github.com/onsi/gomega"
Expand All @@ -26,15 +25,15 @@ import (
)

var (
provider string
storageClass string
providedIcinga string
provider string
storageClass string
searchlightService string
)

func init() {
flag.StringVar(&provider, "provider", "minikube", "Kubernetes cloud provider")
flag.StringVar(&storageClass, "storageclass", "", "Kubernetes StorageClass name")
flag.StringVar(&providedIcinga, "provided-icinga", "", "Running Icinga reference")
flag.StringVar(&searchlightService, "searchlight-service", "", "Running searchlight reference")
}

const (
Expand All @@ -56,6 +55,9 @@ func TestE2e(t *testing.T) {
}

var _ = BeforeSuite(func() {

Expect(searchlightService).ShouldNot(BeEmpty())

// Kubernetes config
kubeconfigPath := filepath.Join(homedir.HomeDir(), ".kube/config")
By("Using kubeconfig from " + kubeconfigPath)
Expand All @@ -75,28 +77,13 @@ var _ = BeforeSuite(func() {
err = root.CreateNamespace()
Expect(err).NotTo(HaveOccurred())

var slService *core.Service
if providedIcinga == "" {
// Create Searchlight deployment
slDeployment := root.Invoke().DeploymentSearchlight()
err = root.CreateDeployment(slDeployment)
Expect(err).NotTo(HaveOccurred())
By("Waiting for Running pods")
root.EventuallyDeployment(slDeployment.ObjectMeta).Should(HaveRunningPods(*slDeployment.Spec.Replicas))
// Create Searchlight service
slService = root.Invoke().ServiceSearchlight()
err = root.CreateService(slService)
Expect(err).NotTo(HaveOccurred())
root.EventuallyServiceLoadBalancer(slService.ObjectMeta, "icinga").Should(BeTrue())

} else {
parts := strings.Split(providedIcinga, "@")
om := metav1.ObjectMeta{
Name: parts[0],
Namespace: parts[1],
}
slService = &core.Service{ObjectMeta: om}
parts := strings.Split(searchlightService, "@")
Expect(len(parts)).Should(BeIdenticalTo(2))
om := metav1.ObjectMeta{
Name: parts[0],
Namespace: parts[1],
}
slService := &core.Service{ObjectMeta: om}

// Get Icinga Ingress Hostname
endpoint, err := root.GetServiceEndpoint(slService.ObjectMeta, "icinga")
Expand All @@ -109,7 +96,8 @@ var _ = BeforeSuite(func() {
}

cfg.BasicAuth.Username = ICINGA_API_USER
cfg.BasicAuth.Password = ICINGA_API_PASSWORD
cfg.BasicAuth.Password, err = root.Invoke().GetIcingaApiPassword(om)
Expect(err).NotTo(HaveOccurred())

// Icinga Client
icingaClient := icinga.NewClient(*cfg)
Expand All @@ -123,21 +111,6 @@ var _ = BeforeSuite(func() {
fmt.Println("Login password: ", ICINGA_WEB_UI_PASSWORD)
fmt.Println()

opc := &operator.OperatorConfig{
Config: operator.Config{
MaxNumRequeues: 3,
NumThreads: 3,
Verbosity: "6",
},
KubeClient: kubeClient,
CRDClient: apiExtKubeClient,
ExtClient: extClient,
IcingaClient: icingaClient,
}
// Controller
op, err = opc.New()
Expect(err).NotTo(HaveOccurred())
go op.RunWatchers(nil)
})

var _ = AfterSuite(func() {
Expand Down
9 changes: 2 additions & 7 deletions test/e2e/framework/httpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,9 @@ func (f *Framework) EventuallyHTTPServerResponse(serverURL string) GomegaAsyncAs
return Eventually(
func() string {
resp, err := http.Get(serverURL)
if err != nil {
return err.Error()
}

Expect(err).NotTo(HaveOccurred())
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err.Error()
}
Expect(err).NotTo(HaveOccurred())

return string(data)
},
Expand Down
46 changes: 38 additions & 8 deletions test/e2e/framework/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ package framework
import (
"encoding/json"
"fmt"
"time"

incident_api "github.com/appscode/searchlight/apis/incidents/v1alpha1"
api "github.com/appscode/searchlight/apis/monitoring/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
)

func (f *Framework) ForceCheckClusterAlert(meta metav1.ObjectMeta, hostname string, times int) error {
Expand Down Expand Up @@ -37,15 +41,41 @@ func (f *Framework) SendClusterAlertCustomNotification(meta metav1.ObjectMeta, h
}

func (f *Framework) AcknowledgeClusterAlertNotification(meta metav1.ObjectMeta, hostname string) error {
mp := make(map[string]interface{})
mp["type"] = "Service"
mp["filter"] = fmt.Sprintf(`service.name == "%s" && host.name == "%s"`, meta.Name, hostname)
mp["author"] = "e2e"
mp["comment"] = "test"
mp["notify"] = true
ack, err := json.Marshal(mp)

labelMap := map[string]string{
api.LabelKeyAlert: meta.Name,
api.LabelKeyObjectName: hostname,
api.LabelKeyProblemRecovered: "false",
}

incidentList, err := f.extClient.MonitoringV1alpha1().Incidents(meta.Namespace).List(metav1.ListOptions{
LabelSelector: labels.SelectorFromSet(labelMap).String(),
})
if err != nil {
return err
}
return f.icingaClient.Actions("acknowledge-problem").Update([]string{}, string(ack)).Do().Err

var lastCreationTimestamp time.Time
var incident *api.Incident
for _, item := range incidentList.Items {
if item.CreationTimestamp.After(lastCreationTimestamp) {
lastCreationTimestamp = item.CreationTimestamp.Time
incident = &item
}
}

_, err = f.extClient.IncidentsV1alpha1().Acknowledgements(incident.Namespace).Create(&incident_api.Acknowledgement{
ObjectMeta: metav1.ObjectMeta{
Namespace: incident.Namespace,
Name: incident.Name,
},
Request: incident_api.AcknowledgementRequest{
Comment: "test",
},
})
if err != nil {
return err
}

return nil
}
Loading

0 comments on commit abef69f

Please sign in to comment.