Skip to content

Commit abef69f

Browse files
Mir Shahriartamalsaha
authored andcommitted
Add api password for e2e-test (#375)
1 parent c520036 commit abef69f

File tree

12 files changed

+139
-227
lines changed

12 files changed

+139
-227
lines changed

chart/searchlight/templates/secret.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ data:
1313
ICINGA_WEB_UI_PASSWORD: {{ .Values.icinga2web.password | b64enc | quote }}
1414
{{ else }}
1515
ICINGA_WEB_UI_PASSWORD: {{ randAlphaNum 10 | b64enc | quote }}
16+
{{- if .Values.icinga2.password }}
17+
ICINGA_API_PASSWORD: {{ .Values.icinga2.password | b64enc | quote }}
18+
{{ else }}
19+
ICINGA_API_PASSWORD: {{ randAlphaNum 10 | b64enc | quote }}
1620
{{ end -}}
1721
{{- if .Values.notifier.hipchat.authToken }}
1822
HIPCHAT_AUTH_TOKEN: {{ .Values.notifier.hipchat.authToken | b64enc | quote }}

chart/searchlight/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ logLevel: 3
4242
icinga2web:
4343
password: changeit
4444

45+
icinga2:
46+
password:
47+
4548
notifier:
4649
hipchat:
4750
authToken: ''

docs/setup/install.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ options:
5252
--image-pull-secret name of secret used to pull searchlight operator images
5353
--run-on-master run searchlight operator on master
5454
--enable-validating-webhook enable/disable validating webhooks for Searchlight CRD
55+
--icinga-api-password password used by icinga2 api (if unset, a random password will be generated and used)
5556
--enable-analytics send usage events to Google Analytics (default: true)
5657
--uninstall uninstall searchlight
5758
--purge purges searchlight crd objects and crds

hack/deploy/operator.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ metadata:
77
app: searchlight
88
data:
99
ICINGA_WEB_UI_PASSWORD: Y2hhbmdlaXQ=
10+
${SEARCHLIGHT_ICINGA_API_PASSWORD}
1011
---
1112
apiVersion: apps/v1beta1
1213
kind: Deployment

hack/deploy/searchlight.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export SEARCHLIGHT_NAMESPACE=kube-system
9191
export SEARCHLIGHT_SERVICE_ACCOUNT=searchlight-operator
9292
export SEARCHLIGHT_ENABLE_RBAC=true
9393
export SEARCHLIGHT_RUN_ON_MASTER=0
94+
export SEARCHLIGHT_ICINGA_API_PASSWORD=
9495
export SEARCHLIGHT_ENABLE_VALIDATING_WEBHOOK=false
9596
export SEARCHLIGHT_DOCKER_REGISTRY=appscode
9697
export SEARCHLIGHT_OPERATOR_TAG=7.0.0-rc.0
@@ -127,6 +128,7 @@ show_help() {
127128
echo " --image-pull-secret name of secret used to pull searchlight operator images"
128129
echo " --run-on-master run searchlight operator on master"
129130
echo " --enable-validating-webhook enable/disable validating webhooks for Searchlight CRDs"
131+
echo " --icinga-api-password password used by icinga2 api (if unset, a random password will be generated and used)"
130132
echo " --enable-analytics send usage events to Google Analytics (default: true)"
131133
echo " --uninstall uninstall searchlight"
132134
echo " --purge purges searchlight crd objects and crds"
@@ -187,6 +189,12 @@ while test $# -gt 0; do
187189
export SEARCHLIGHT_RUN_ON_MASTER=1
188190
shift
189191
;;
192+
--icinga-api-password*)
193+
pass=`echo $1 | sed -e 's/^[^=]*=//g'`
194+
pass_b64=`echo -n $pass | $ONESSL base64`
195+
export SEARCHLIGHT_ICINGA_API_PASSWORD="ICINGA_API_PASSWORD: '$pass_b64'"
196+
shift
197+
;;
190198
--uninstall)
191199
export SEARCHLIGHT_UNINSTALL=1
192200
shift

test/e2e/e2e_suite_test.go

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/appscode/searchlight/pkg/icinga"
1414
"github.com/appscode/searchlight/pkg/operator"
1515
"github.com/appscode/searchlight/test/e2e/framework"
16-
. "github.com/appscode/searchlight/test/e2e/matcher"
1716
. "github.com/onsi/ginkgo"
1817
"github.com/onsi/ginkgo/reporters"
1918
. "github.com/onsi/gomega"
@@ -26,15 +25,15 @@ import (
2625
)
2726

2827
var (
29-
provider string
30-
storageClass string
31-
providedIcinga string
28+
provider string
29+
storageClass string
30+
searchlightService string
3231
)
3332

3433
func init() {
3534
flag.StringVar(&provider, "provider", "minikube", "Kubernetes cloud provider")
3635
flag.StringVar(&storageClass, "storageclass", "", "Kubernetes StorageClass name")
37-
flag.StringVar(&providedIcinga, "provided-icinga", "", "Running Icinga reference")
36+
flag.StringVar(&searchlightService, "searchlight-service", "", "Running searchlight reference")
3837
}
3938

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

5857
var _ = BeforeSuite(func() {
58+
59+
Expect(searchlightService).ShouldNot(BeEmpty())
60+
5961
// Kubernetes config
6062
kubeconfigPath := filepath.Join(homedir.HomeDir(), ".kube/config")
6163
By("Using kubeconfig from " + kubeconfigPath)
@@ -75,28 +77,13 @@ var _ = BeforeSuite(func() {
7577
err = root.CreateNamespace()
7678
Expect(err).NotTo(HaveOccurred())
7779

78-
var slService *core.Service
79-
if providedIcinga == "" {
80-
// Create Searchlight deployment
81-
slDeployment := root.Invoke().DeploymentSearchlight()
82-
err = root.CreateDeployment(slDeployment)
83-
Expect(err).NotTo(HaveOccurred())
84-
By("Waiting for Running pods")
85-
root.EventuallyDeployment(slDeployment.ObjectMeta).Should(HaveRunningPods(*slDeployment.Spec.Replicas))
86-
// Create Searchlight service
87-
slService = root.Invoke().ServiceSearchlight()
88-
err = root.CreateService(slService)
89-
Expect(err).NotTo(HaveOccurred())
90-
root.EventuallyServiceLoadBalancer(slService.ObjectMeta, "icinga").Should(BeTrue())
91-
92-
} else {
93-
parts := strings.Split(providedIcinga, "@")
94-
om := metav1.ObjectMeta{
95-
Name: parts[0],
96-
Namespace: parts[1],
97-
}
98-
slService = &core.Service{ObjectMeta: om}
80+
parts := strings.Split(searchlightService, "@")
81+
Expect(len(parts)).Should(BeIdenticalTo(2))
82+
om := metav1.ObjectMeta{
83+
Name: parts[0],
84+
Namespace: parts[1],
9985
}
86+
slService := &core.Service{ObjectMeta: om}
10087

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

11198
cfg.BasicAuth.Username = ICINGA_API_USER
112-
cfg.BasicAuth.Password = ICINGA_API_PASSWORD
99+
cfg.BasicAuth.Password, err = root.Invoke().GetIcingaApiPassword(om)
100+
Expect(err).NotTo(HaveOccurred())
113101

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

126-
opc := &operator.OperatorConfig{
127-
Config: operator.Config{
128-
MaxNumRequeues: 3,
129-
NumThreads: 3,
130-
Verbosity: "6",
131-
},
132-
KubeClient: kubeClient,
133-
CRDClient: apiExtKubeClient,
134-
ExtClient: extClient,
135-
IcingaClient: icingaClient,
136-
}
137-
// Controller
138-
op, err = opc.New()
139-
Expect(err).NotTo(HaveOccurred())
140-
go op.RunWatchers(nil)
141114
})
142115

143116
var _ = AfterSuite(func() {

test/e2e/framework/httpserver.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,9 @@ func (f *Framework) EventuallyHTTPServerResponse(serverURL string) GomegaAsyncAs
4040
return Eventually(
4141
func() string {
4242
resp, err := http.Get(serverURL)
43-
if err != nil {
44-
return err.Error()
45-
}
46-
43+
Expect(err).NotTo(HaveOccurred())
4744
data, err := ioutil.ReadAll(resp.Body)
48-
if err != nil {
49-
return err.Error()
50-
}
45+
Expect(err).NotTo(HaveOccurred())
5146

5247
return string(data)
5348
},

test/e2e/framework/notification.go

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ package framework
33
import (
44
"encoding/json"
55
"fmt"
6+
"time"
67

8+
incident_api "github.com/appscode/searchlight/apis/incidents/v1alpha1"
9+
api "github.com/appscode/searchlight/apis/monitoring/v1alpha1"
710
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
"k8s.io/apimachinery/pkg/labels"
812
)
913

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

3943
func (f *Framework) AcknowledgeClusterAlertNotification(meta metav1.ObjectMeta, hostname string) error {
40-
mp := make(map[string]interface{})
41-
mp["type"] = "Service"
42-
mp["filter"] = fmt.Sprintf(`service.name == "%s" && host.name == "%s"`, meta.Name, hostname)
43-
mp["author"] = "e2e"
44-
mp["comment"] = "test"
45-
mp["notify"] = true
46-
ack, err := json.Marshal(mp)
44+
45+
labelMap := map[string]string{
46+
api.LabelKeyAlert: meta.Name,
47+
api.LabelKeyObjectName: hostname,
48+
api.LabelKeyProblemRecovered: "false",
49+
}
50+
51+
incidentList, err := f.extClient.MonitoringV1alpha1().Incidents(meta.Namespace).List(metav1.ListOptions{
52+
LabelSelector: labels.SelectorFromSet(labelMap).String(),
53+
})
4754
if err != nil {
4855
return err
4956
}
50-
return f.icingaClient.Actions("acknowledge-problem").Update([]string{}, string(ack)).Do().Err
57+
58+
var lastCreationTimestamp time.Time
59+
var incident *api.Incident
60+
for _, item := range incidentList.Items {
61+
if item.CreationTimestamp.After(lastCreationTimestamp) {
62+
lastCreationTimestamp = item.CreationTimestamp.Time
63+
incident = &item
64+
}
65+
}
66+
67+
_, err = f.extClient.IncidentsV1alpha1().Acknowledgements(incident.Namespace).Create(&incident_api.Acknowledgement{
68+
ObjectMeta: metav1.ObjectMeta{
69+
Namespace: incident.Namespace,
70+
Name: incident.Name,
71+
},
72+
Request: incident_api.AcknowledgementRequest{
73+
Comment: "test",
74+
},
75+
})
76+
if err != nil {
77+
return err
78+
}
79+
80+
return nil
5181
}

0 commit comments

Comments
 (0)