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

Skip observability controller tests if no SA TLS cert #3138

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions controllers/observability/pod_disruption_budget_at_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import (
)

const (
// ServiceAccountTlsCertPath is the path to the service account TLS certificate
// used for TLS communication with the alertmanager API
ServiceAccountTlsCertPath = "/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt"

alertmanagerSvcHost = "https://alertmanager-main.openshift-monitoring.svc.cluster.local:9094"
tlsCertPath = "/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt"
)

func (r *Reconciler) ensurePodDisruptionBudgetAtLimitIsSilenced() error {
Expand Down Expand Up @@ -64,7 +67,7 @@ func (r *Reconciler) ensurePodDisruptionBudgetAtLimitIsSilenced() error {
}

func (r *Reconciler) NewAlertmanagerApi() (*alertmanager.Api, error) {
caCert, err := os.ReadFile(tlsCertPath)
caCert, err := os.ReadFile(ServiceAccountTlsCertPath)
if err != nil {
return nil, fmt.Errorf("failed to read ca cert: %w", err)
}
Expand Down
30 changes: 29 additions & 1 deletion tests/func-tests/observability_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package tests_test

import (
"context"
"errors"
"os"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -13,8 +15,22 @@ import (
tests "github.com/kubevirt/hyperconverged-cluster-operator/tests/func-tests"
)

var _ = Describe("Observability Controller", Label(tests.OpenshiftLabel, "observability_controller"), func() {
const testName = "observability_controller"

var _ = Describe("Observability Controller", Label(tests.OpenshiftLabel, testName), func() {
Context("PodDisruptionBudgetAtLimit", func() {
BeforeEach(func(ctx context.Context) {
cli := tests.GetControllerRuntimeClient()
tests.FailIfNotOpenShift(ctx, cli, testName)

certExists, err := serviceAccountTlsCertPathExists()
Expect(err).ToNot(HaveOccurred())

if !certExists {
Fail("Service account TLS certificate path does not exist")
}
})

It("should be silenced", func() {
r := observability.NewReconciler(tests.GetClientConfig())

Expand Down Expand Up @@ -55,3 +71,15 @@ var _ = Describe("Observability Controller", Label(tests.OpenshiftLabel, "observ
})
})
})

func serviceAccountTlsCertPathExists() (bool, error) {
_, err := os.Stat(observability.ServiceAccountTlsCertPath)
if errors.Is(err, os.ErrNotExist) {
return false, nil
}
if err != nil {
return false, err
}

return true, nil
}
Loading