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

Bug 1926876: pkg/manifests: fix prometheus-proxy trustedCA #1051

Merged
merged 2 commits into from
Mar 13, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/manifests/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,7 @@ func (f *Factory) PrometheusK8s(host string, grpcTLS *v1.Secret, trustedCABundle
// 1. Prometheus, because users might want to configure external remote write.
// 2. In OAuth proxy, as that communicates externally when executing the OAuth handshake.
for i, container := range p.Spec.Containers {
if container.Name == "prometeus-proxy" || container.Name == "prometheus" {
if container.Name == "prometheus-proxy" || container.Name == "prometheus" {
p.Spec.Containers[i].VolumeMounts = append(
p.Spec.Containers[i].VolumeMounts,
trustedCABundleVolumeMount(volumeName),
Expand Down
140 changes: 136 additions & 4 deletions pkg/manifests/manifests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ ingress:
}

for _, container := range p.Spec.Containers {
if container.Name == "oauth-proxy" && container.Image != "docker.io/openshift/origin-oauth-proxy:latest" {
if container.Name == "prometheus-proxy" && container.Image != "docker.io/openshift/origin-oauth-proxy:latest" {
t.Fatalf("image for %s is not configured correctly: %s", container.Name, container.Image)
}

Expand All @@ -971,6 +971,16 @@ ingress:
if container.Name == "prom-label-proxy" && container.Image != "docker.io/openshift/origin-prom-label-proxy:latest" {
t.Fatalf("image for %s is not configured correctly: %s", container.Name, container.Image)
}

volumeName := "prometheus-trusted-ca-bundle"
if container.Name == "prometheus-proxy" || container.Name == "prometheus" {
if !trustedCABundleVolumeConfigured(p.Spec.Volumes, volumeName) {
t.Fatalf("trusted CA bundle volume for %s is not configured correctly", container.Name)
}
if !trustedCABundleVolumeMountsConfigured(container.VolumeMounts, volumeName) {
t.Fatalf("trusted CA bundle volume mount for %s is not configured correctly", container.Name)
}
}
}

cpuLimit := p.Spec.Resources.Limits[v1.ResourceCPU]
Expand Down Expand Up @@ -1083,7 +1093,10 @@ ingress:
})

f := NewFactory("openshift-monitoring", "openshift-user-workload-monitoring", c, NewAssets(assetsPath))
a, err := f.AlertmanagerMain("alertmanager-main.openshift-monitoring.svc", nil)
a, err := f.AlertmanagerMain(
"alertmanager-main.openshift-monitoring.svc",
&v1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1129,6 +1142,18 @@ ingress:
if storageRequestPtr.String() != "10Gi" {
t.Fatal("Alertmanager volumeClaimTemplate not configured correctly, expected 10Gi storage request, but found", storageRequestPtr.String())
}

for _, container := range a.Spec.Containers {
volumeName := "alertmanager-trusted-ca-bundle"
if container.Name == "prometheus-proxy" || container.Name == "prometheus" {
if !trustedCABundleVolumeConfigured(a.Spec.Volumes, volumeName) {
t.Fatalf("trusted CA bundle volume for %s is not configured correctly", container.Name)
}
if !trustedCABundleVolumeMountsConfigured(container.VolumeMounts, volumeName) {
t.Fatalf("trusted CA bundle volume mount for %s is not configured correctly", container.Name)
}
}
}
}

func TestNodeExporter(t *testing.T) {
Expand Down Expand Up @@ -1371,9 +1396,12 @@ func TestThanosQuerierConfiguration(t *testing.T) {
t.Fatal(err)
}

tls := &v1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
f := NewFactory("openshift-monitoring", "openshift-user-workload-monitoring", c, NewAssets(assetsPath))
d, err := f.ThanosQuerierDeployment(tls, false, nil)
d, err := f.ThanosQuerierDeployment(
&v1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
false,
&v1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1439,5 +1467,109 @@ func TestThanosQuerierConfiguration(t *testing.T) {
})
}
}

if c.Name == "oauth-proxy" {
volumeName := "thanos-querier-trusted-ca-bundle"
if !trustedCABundleVolumeConfigured(d.Spec.Template.Spec.Volumes, volumeName) {
t.Fatalf("trusted CA bundle volume for %s is not configured correctly", c.Name)
}
if !trustedCABundleVolumeMountsConfigured(c.VolumeMounts, volumeName) {
t.Fatalf("trusted CA bundle volume mount for %s is not configured correctly", c.Name)
}
}
}
}

func TestGrafanaConfiguration(t *testing.T) {
c, err := NewConfigFromString(``)
if err != nil {
t.Fatal(err)
}
f := NewFactory("openshift-monitoring", "openshift-user-workload-monitoring", c, NewAssets(assetsPath))
d, err := f.GrafanaDeployment(&v1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "foo"}})
if err != nil {
t.Fatal(err)
}

for _, container := range d.Spec.Template.Spec.Containers {
if container.Name == "grafana-proxy" {
volumeName := "grafana-trusted-ca-bundle"
if !trustedCABundleVolumeConfigured(d.Spec.Template.Spec.Volumes, volumeName) {
t.Fatalf("trusted CA bundle volume for %s is not configured correctly", container.Name)
}
if !trustedCABundleVolumeMountsConfigured(container.VolumeMounts, volumeName) {
t.Fatalf("trusted CA bundle volume mount for %s is not configured correctly", container.Name)
}
}
}
}

func TestTelemeterConfiguration(t *testing.T) {
c, err := NewConfigFromString(``)
if err != nil {
t.Fatal(err)
}
f := NewFactory("openshift-monitoring", "openshift-user-workload-monitoring", c, NewAssets(assetsPath))
d, err := f.TelemeterClientDeployment(&v1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "foo"}})
if err != nil {
t.Fatal(err)
}

for _, container := range d.Spec.Template.Spec.Containers {
if container.Name == "telemeter-client" {
volumeName := "telemeter-trusted-ca-bundle"
if !trustedCABundleVolumeConfigured(d.Spec.Template.Spec.Volumes, volumeName) {
t.Fatalf("trusted CA bundle volume for %s is not configured correctly", container.Name)
}
if !trustedCABundleVolumeMountsConfigured(container.VolumeMounts, volumeName) {
t.Fatalf("trusted CA bundle volume mount for %s is not configured correctly", container.Name)
}
}
}
}

func TestThanosRulerConfiguration(t *testing.T) {
c, err := NewConfigFromString(``)
if err != nil {
t.Fatal(err)
}
f := NewFactory("openshift-monitoring", "openshift-user-workload-monitoring", c, NewAssets(assetsPath))
tr, err := f.ThanosRulerCustomResource(
"",
&v1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
&v1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
)
if err != nil {
t.Fatal(err)
}

for _, container := range tr.Spec.Containers {
if container.Name == "thanos-ruler-proxy" {
volumeName := "thanos-ruler-trusted-ca-bundle"
if !trustedCABundleVolumeConfigured(tr.Spec.Volumes, volumeName) {
t.Fatalf("trusted CA bundle volume for %s is not configured correctly", container.Name)
}
if !trustedCABundleVolumeMountsConfigured(container.VolumeMounts, volumeName) {
t.Fatalf("trusted CA bundle volume mount for %s is not configured correctly", container.Name)
}
}
}
}

func trustedCABundleVolumeConfigured(volumes []v1.Volume, volumeName string) bool {
for _, volume := range volumes {
if volume.Name == volumeName {
return true
}
}
return false
}

func trustedCABundleVolumeMountsConfigured(volumeMounts []v1.VolumeMount, volumeName string) bool {
for _, volumeMount := range volumeMounts {
if volumeMount.Name == volumeName {
return true
}
}
return false
}