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

Closed
wants to merge 10 commits into from
22 changes: 18 additions & 4 deletions pkg/images/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ import (
)

const (
envVarPodNamespace = "NAMESPACE"
envVarPodName = "PODNAME"
NullPolicy = corev1.PullPolicy("")
NullImage = ""
envVarPodNamespace = "NAMESPACE"
envVarPodName = "PODNAME"
NullPolicy = corev1.PullPolicy("")
NullImage = ""
kubeRbacProxyContainerName = "kube-rbac-proxy"
)

func GetCurrentImage(ctx context.Context) (string, corev1.PullPolicy, error) {
Expand All @@ -46,6 +47,19 @@ func GetCurrentImage(ctx context.Context) (string, corev1.PullPolicy, error) {
return GetImageFromPod(ctx, podNamespace, podName, "")
}

func GetKubeRbacProxyImage(ctx context.Context) (string, error) {
podNamespace, ok := os.LookupEnv(envVarPodNamespace)
if !ok {
return NullImage, fmt.Errorf("environment variable not set: %q", envVarPodNamespace)
}
podName, ok := os.LookupEnv(envVarPodName)
if !ok {
return NullImage, fmt.Errorf("environment variable not set: %q", envVarPodName)
}
img, _, err := GetImageFromPod(ctx, podNamespace, podName, kubeRbacProxyContainerName)
return img, err
}

func GetImageFromPod(ctx context.Context, namespace, podName, containerName string) (string, corev1.PullPolicy, error) {
k8sCli, err := clientutil.NewK8s()
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions pkg/objectupdate/rte/rte.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ func SidecarContainerConfig(ds *appsv1.DaemonSet) {

// 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)

// Pull kube-rbac-proxy image from operator proxy.
if sidecarImage, err := images.GetKubeRbacProxyImage(context.TODO()); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

this should be a parameter, this code should not access the cluster APIs. We should detect this image once (in main.go and pass it down here.

klog.InfoS("unable to find current image, using hardcoded", "error", err)
} else {
sidecarContainer.Image = sidecarImage
}
}

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