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

CNF-11234: Enable RTE metrics to be scraped securely by Prometheus #1035

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions controllers/numaresourcesoperator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,8 @@ func daemonsetUpdater(mcpName string, gdm *rtestate.GeneratedDesiredManifest) er
// nothing to do!
return nil
}
rteupdate.SidecarContainerConfig(gdm.DaemonSet)
klog.V(5).Info("DaemonSet update: Added daemonset sidecar")
err = rteupdate.ContainerConfig(gdm.DaemonSet, gdm.DaemonSet.Name)
if err != nil {
// intentionally info because we want to keep going
Expand Down
76 changes: 76 additions & 0 deletions pkg/objectupdate/rte/rte.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package rte

import (
"context"
"fmt"
"path/filepath"

Expand All @@ -33,6 +34,7 @@ import (
nropv1 "github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1"

"github.com/openshift-kni/numaresources-operator/pkg/hash"
"github.com/openshift-kni/numaresources-operator/pkg/images"
)

// these should be provided by a deployer API
Expand Down Expand Up @@ -199,6 +201,80 @@ func ContainerConfig(ds *appsv1.DaemonSet, name string) error {
return nil
}

func SidecarContainerConfig(ds *appsv1.DaemonSet) {
// Define the sidecar container
Copy link
Member

Choose a reason for hiding this comment

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

redundant comment(s)

sidecarContainer := corev1.Container{
Name: "kube-rbac-proxy",
Image: "gcr.io/kubebuilder/kube-rbac-proxy:v0.15.0",
Args: []string{
"--secure-listen-address=0.0.0.0:8443",
"--upstream=http://127.0.0.1:2112",
"--config-file=/etc/kube-rbac-proxy/config.yaml",
"--tls-cert-file=/etc/tls/private/tls.crt",
"--tls-private-key-file=/etc/tls/private/tls.key",
"--logtostderr=true",
"--allow-paths=/metrics",
},
Ports: []corev1.ContainerPort{
{
ContainerPort: 8443,
Name: "https",
},
},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1m"),
corev1.ResourceMemory: resource.MustParse("15Mi"),
},
},
SecurityContext: &corev1.SecurityContext{
AllowPrivilegeEscalation: &[]bool{false}[0],
Copy link
Member

Choose a reason for hiding this comment

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

ptr.To?

Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
},
},
TerminationMessagePolicy: corev1.TerminationMessageFallbackToLogsOnError,
VolumeMounts: []corev1.VolumeMount{
{
MountPath: "/etc/kube-rbac-proxy",
Name: "numaresources-secret-kube-rbac-proxy-metric",
ReadOnly: true,
},
{
MountPath: "/etc/tls/private",
Name: "rte-secret-kube-rbac-proxy-tls",
ReadOnly: true,
},
},
}

// Define the volumes for the sidecar
Copy link
Member

Choose a reason for hiding this comment

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

redundant comment(s)

sidecarVolumes := []corev1.Volume{
{
Name: "rte-secret-kube-rbac-proxy-tls",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: "rte-secret-kube-rbac-proxy-tls",
},
},
},
{
Name: "numaresources-secret-kube-rbac-proxy-metric",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: "numaresources-secret-kube-rbac-proxy-metric",
},
},
},
}

// Add the volumes to the DaemonSet spec
Copy link
Member

Choose a reason for hiding this comment

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

redundant comment(s)

ds.Spec.Template.Spec.Volumes = append(ds.Spec.Template.Spec.Volumes, sidecarVolumes...)

// Add the sidecar container to the DaemonSet spec
Copy link
Member

Choose a reason for hiding this comment

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

redundant comment(s)

ds.Spec.Template.Spec.Containers = append(ds.Spec.Template.Spec.Containers, sidecarContainer)
}

func AddVolumeMountMemory(podSpec *corev1.PodSpec, cnt *corev1.Container, mountName, dirName string, sizeMiB int64) {
cnt.VolumeMounts = append(cnt.VolumeMounts,
corev1.VolumeMount{
Expand Down