Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration tests for grafana deployment #1156

Merged
merged 9 commits into from
Jul 28, 2023

Conversation

ggriffiths
Copy link

What this PR does / why we need it:
Adds a few tests to the operator integration test suite for validating grafana deployments, svcs, configmaps, and airgapped support.

Which issue(s) this PR fixes (optional)
Closes #

Special notes for your reviewer:

@ggriffiths
Copy link
Author

Ran the test suite a few times, works as expected:

--- PASS: TestGrafana (173.22s)
    --- PASS: TestGrafana/GrafanaInstall (173.15s)
    --- PASS: TestGrafana/GrafanaInstallAirgapped (0.07s)
PASS
==================================================
--- PASS:
    GrafanaInstall [XXX XXX]
    GrafanaInstallAirgapped [XXX XXX]
--- SKIP:
--- FAIL:
==================================================

DONE 3 tests in 173.491s
Tests passed

@ggriffiths ggriffiths force-pushed the grafana_integration_test branch 4 times, most recently from ed0168d to baac997 Compare July 24, 2023 23:43
Copy link
Collaborator

@nikolaypopov nikolaypopov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes are needed here, let me know if you want to sync up

pkg/util/test/util.go Outdated Show resolved Hide resolved
pkg/util/test/util.go Outdated Show resolved Hide resolved
pkg/util/test/util.go Outdated Show resolved Hide resolved
pkg/util/test/util.go Outdated Show resolved Hide resolved
pkg/util/test/util.go Outdated Show resolved Hide resolved
@ggriffiths ggriffiths force-pushed the grafana_integration_test branch 2 times, most recently from 6fbadde to 3fc01a0 Compare July 25, 2023 19:54
@ggriffiths
Copy link
Author

Tested again after addressing comments:

time="2023-07-25T19:53:35Z" level=info msg="Using version extracted from image name: 2.13.6"
time="2023-07-25T19:53:35Z" level=info msg="Update StorageCluster px-test-grafana in kube-system"
2023/07/25 19:53:35 grafana is not installed with image docker.io/grafana/grafana:8.5.27. number of pods: 0 Next retry in: 10s
time="2023-07-25T19:53:45Z" level=info msg="Grafana installed successfully with image docker.io/grafana/grafana:8.5.27"
--- PASS: TestGrafana (158.30s)
    --- PASS: TestGrafana/GrafanaInstall (143.24s)
    --- PASS: TestGrafana/GrafanaInstallVersionManifest (15.06s)
PASS
==================================================
--- PASS:
    GrafanaInstall [XXX XXX]
    GrafanaInstallVersionManifest [XXX XXX]
--- SKIP:
--- FAIL:
==================================================

DONE 3 tests in 158.637s
Tests passed

pkg/util/test/util.go Outdated Show resolved Hide resolved
@ggriffiths ggriffiths force-pushed the grafana_integration_test branch 3 times, most recently from dff6bce to fab127e Compare July 26, 2023 00:15
Copy link
Collaborator

@nikolaypopov nikolaypopov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks much better, please address comments and build and image so I can run it in one of the basic jobs

Comment on lines 3025 to 3052
func ValidateGrafanaDeploymentImage(image string) error {
check := func() (interface{}, bool, error) {
pods, err := coreops.Instance().GetPods("kube-system", map[string]string{"app": "grafana"})
if err != nil {
return "", true, err
}

podCount := len(pods.Items)
if podCount > 0 && len(pods.Items[0].Spec.Containers) > 0 {
actualImage := pods.Items[0].Spec.Containers[0].Image
if actualImage == image {
logrus.Infof("Grafana installed successfully with image %s", image)
return "", false, nil
} else {
logrus.Errorf("Grafana not yet ready with image %s", image)
return "", true, fmt.Errorf("grafana is not installed with expected image %s. actual: %s", image, actualImage)
}
} else {
return "", true, fmt.Errorf("grafana is not installed with image %s. number of pods: %v", image, podCount)
}
}

if _, err := task.DoRetryWithTimeout(check, 1*time.Minute, 10*time.Second); err != nil {
return err
}

return nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this since you using validateContainerImageInsidePods() and we don't need this any more


func ValidateGrafanaDeployment(cluster *corev1.StorageCluster, shouldBeInstalled bool, pxImageList map[string]string) error {
check := func() (interface{}, bool, error) {
pods, err := coreops.Instance().GetPods("kube-system", map[string]string{"app": "grafana"})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't hardcode kube-system, this can be installed into any namespace, let's get namespace from cluster.Namespace and use that instead

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 2994 to 2997
if len(pods.Items) == 0 || pods.Items[0].Status.Phase != v1.PodRunning {
logrus.Errorf("Grafana not yet ready")
return "", true, fmt.Errorf("grafana is not installed when it should be")
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is grafana a deployment? Maybe just using sched-ops function ValidateDeployment should be enough here as it would do all the pod validation, if its not and its just a pod, this should be ok

Comment on lines 3001 to 3002
logrus.Errorf("Grafana image is invalid yet ready")
return "", true, fmt.Errorf("grafana is not installed when it should be")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not log error and then return it, let's just return verbose error instead

Comment on lines 3012 to 3013
logrus.Errorf("Grafana not yet uninstalled")
return "", true, fmt.Errorf("grafana is installed when it is expected to be uninstalled")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here and all other place you have this

Copy link
Collaborator

@nikolaypopov nikolaypopov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, let's run op-basic job once with this private image before merging. Let me know when you have an image ready

@ggriffiths
Copy link
Author

Thanks, sent the test image.

@ggriffiths ggriffiths force-pushed the grafana_integration_test branch 7 times, most recently from 4039639 to 032506a Compare July 27, 2023 18:43
@nikolaypopov nikolaypopov self-requested a review July 27, 2023 22:01
@ggriffiths ggriffiths force-pushed the grafana_integration_test branch 3 times, most recently from e85c1e9 to c6efb64 Compare July 28, 2023 00:00
@ggriffiths ggriffiths force-pushed the grafana_integration_test branch 2 times, most recently from cf214db to 98eda84 Compare July 28, 2023 01:34
Grant Griffiths added 9 commits July 28, 2023 01:44
Signed-off-by: Grant Griffiths <ggriffiths@purestorage.com>
Signed-off-by: Grant Griffiths <ggriffiths@purestorage.com>
Signed-off-by: Grant Griffiths <ggriffiths@purestorage.com>
Signed-off-by: Grant Griffiths <ggriffiths@purestorage.com>
Signed-off-by: Grant Griffiths <ggriffiths@purestorage.com>
Signed-off-by: Grant Griffiths <ggriffiths@purestorage.com>
Signed-off-by: Grant Griffiths <ggriffiths@purestorage.com>
Signed-off-by: Grant Griffiths <ggriffiths@purestorage.com>
Signed-off-by: Grant Griffiths <ggriffiths@purestorage.com>
@ggriffiths ggriffiths merged commit 8078b73 into libopenstorage:master Jul 28, 2023
7 checks passed
@ggriffiths ggriffiths deleted the grafana_integration_test branch July 28, 2023 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants