From f7ce18fa1679e3a2ca90651b5c6c9b0b151840ad Mon Sep 17 00:00:00 2001 From: Jack Lin Date: Thu, 18 Jul 2024 16:49:41 +0800 Subject: [PATCH] feat(csi metrics): enable csi sidecar metrics ref: longhorn/longhorn 7938 Signed-off-by: Jack Lin --- csi/deployment.go | 28 ++++++++++++++++++++++++++++ csi/deployment_util.go | 3 ++- types/types.go | 6 ++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/csi/deployment.go b/csi/deployment.go index 368b3d50ef..242f9cdac1 100644 --- a/csi/deployment.go +++ b/csi/deployment.go @@ -70,6 +70,7 @@ func NewAttacherDeployment(namespace, serviceAccount, attacherImage, rootDir str "--leader-election-namespace=$(POD_NAMESPACE)", fmt.Sprintf("--kube-api-qps=%v", types.KubeAPIQPS), fmt.Sprintf("--kube-api-burst=%v", types.KubeAPIBurst), + fmt.Sprintf("--http-endpoint=:%v", types.CSISidecarMetricsPort), }, int32(replicaCount), tolerations, @@ -78,6 +79,12 @@ func NewAttacherDeployment(namespace, serviceAccount, attacherImage, rootDir str registrySecret, imagePullPolicy, nodeSelector, + []corev1.ContainerPort{ + { + Name: types.CSISidecarPortNameAttacher, + ContainerPort: types.CSISidecarMetricsPort, + }, + }, ) return &AttacherDeployment{ @@ -119,6 +126,7 @@ func NewProvisionerDeployment(namespace, serviceAccount, provisionerImage, rootD "--default-fstype=ext4", fmt.Sprintf("--kube-api-qps=%v", types.KubeAPIQPS), fmt.Sprintf("--kube-api-burst=%v", types.KubeAPIBurst), + fmt.Sprintf("--http-endpoint=:%v", types.CSISidecarMetricsPort), }, int32(replicaCount), tolerations, @@ -127,6 +135,12 @@ func NewProvisionerDeployment(namespace, serviceAccount, provisionerImage, rootD registrySecret, imagePullPolicy, nodeSelector, + []corev1.ContainerPort{ + { + Name: types.CSISidecarPortNameProvisioner, + ContainerPort: types.CSISidecarMetricsPort, + }, + }, ) return &ProvisionerDeployment{ @@ -168,6 +182,7 @@ func NewResizerDeployment(namespace, serviceAccount, resizerImage, rootDir strin "--leader-election-namespace=$(POD_NAMESPACE)", fmt.Sprintf("--kube-api-qps=%v", types.KubeAPIQPS), fmt.Sprintf("--kube-api-burst=%v", types.KubeAPIBurst), + fmt.Sprintf("--http-endpoint=:%v", types.CSISidecarMetricsPort), // Issue: https://github.com/longhorn/longhorn/issues/3303 // TODO: Remove this after upgrading the CSI resizer version that contains the fix of https://github.com/kubernetes-csi/external-resizer/issues/175 "--handle-volume-inuse-error=false", @@ -179,6 +194,12 @@ func NewResizerDeployment(namespace, serviceAccount, resizerImage, rootDir strin registrySecret, imagePullPolicy, nodeSelector, + []corev1.ContainerPort{ + { + Name: types.CSISidecarPortNameResizer, + ContainerPort: types.CSISidecarMetricsPort, + }, + }, ) return &ResizerDeployment{ @@ -219,6 +240,7 @@ func NewSnapshotterDeployment(namespace, serviceAccount, snapshotterImage, rootD "--leader-election-namespace=$(POD_NAMESPACE)", fmt.Sprintf("--kube-api-qps=%v", types.KubeAPIQPS), fmt.Sprintf("--kube-api-burst=%v", types.KubeAPIBurst), + fmt.Sprintf("--http-endpoint=:%v", types.CSISidecarMetricsPort), }, int32(replicaCount), tolerations, @@ -227,6 +249,12 @@ func NewSnapshotterDeployment(namespace, serviceAccount, snapshotterImage, rootD registrySecret, imagePullPolicy, nodeSelector, + []corev1.ContainerPort{ + { + Name: types.CSISidecarPortNameSnapshotter, + ContainerPort: types.CSISidecarMetricsPort, + }, + }, ) return &SnapshotterDeployment{ diff --git a/csi/deployment_util.go b/csi/deployment_util.go index eee4f9cdd0..a976affe1e 100644 --- a/csi/deployment_util.go +++ b/csi/deployment_util.go @@ -35,7 +35,7 @@ const ( ) func getCommonDeployment(commonName, namespace, serviceAccount, image, rootDir string, args []string, replicaCount int32, - tolerations []corev1.Toleration, tolerationsString, priorityClass, registrySecret string, imagePullPolicy corev1.PullPolicy, nodeSelector map[string]string) *appsv1.Deployment { + tolerations []corev1.Toleration, tolerationsString, priorityClass, registrySecret string, imagePullPolicy corev1.PullPolicy, nodeSelector map[string]string, ports []corev1.ContainerPort) *appsv1.Deployment { deploymentLabels := types.GetBaseLabelsForSystemManagedComponent() deploymentLabels["app"] = commonName @@ -91,6 +91,7 @@ func getCommonDeployment(commonName, namespace, serviceAccount, image, rootDir s Image: image, Args: args, ImagePullPolicy: imagePullPolicy, + Ports: ports, Env: []corev1.EnvVar{ { Name: "ADDRESS", diff --git a/types/types.go b/types/types.go index f4059923ca..c599843330 100644 --- a/types/types.go +++ b/types/types.go @@ -212,6 +212,12 @@ const ( KubeAPIQPS = 50 KubeAPIBurst = 100 + + CSISidecarMetricsPort = 8000 + CSISidecarPortNameAttacher = "csi-attacher" + CSISidecarPortNameProvisioner = "csi-provisioner" + CSISidecarPortNameResizer = "csi-resizer" + CSISidecarPortNameSnapshotter = "csi-snapshotter" ) const (