Skip to content

Commit

Permalink
fix: Fix deployments page to filter out specific namespace incase two…
Browse files Browse the repository at this point in the history
… namespaces have deployments with same name
  • Loading branch information
tiithansen committed Jun 11, 2024
1 parent 92ffb9b commit a5eca4b
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/pages/Workloads/pages/DeploymentPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Heading from "components/Heading";
import { CPUUsagePanel } from "../components/CPUUsagePanel";
import { MemoryUsagePanel } from "../components/MemoryUsagePanel";

function getPods(deployment: string) {
function getPods(deployment: string, namespace: string) {
const staticLabelFilters: LabelFilters = [
{
label: 'created_by_name',
Expand All @@ -22,13 +22,18 @@ function getPods(deployment: string) {
label: 'created_by_kind',
op: '=',
value: 'ReplicaSet'
},
{
label: 'namespace',
op: '=',
value: namespace
}
]

return getPodsScene(staticLabelFilters, false, false)
}

function getReplicasPanel(deployment: string) {
function getReplicasPanel(deployment: string, namespace: string) {
return PanelBuilders.timeseries()
.setTitle('Replicas')
.setData(new SceneQueryRunner({
Expand All @@ -43,6 +48,7 @@ function getReplicasPanel(deployment: string) {
max(
${Metrics.kubeDeploymentStatusReplicasUnavailable.name}{
${Metrics.kubeDeploymentStatusReplicasUnavailable.labels.deployment}=~"${deployment}",
${Metrics.kubeDeploymentStatusReplicasUnavailable.labels.namespace}="${namespace}",
cluster="$cluster"
}
) by (${Metrics.kubeDeploymentStatusReplicasUnavailable.labels.deployment})`,
Expand All @@ -54,6 +60,7 @@ function getReplicasPanel(deployment: string) {
max(
${Metrics.kubeDeploymentStatusReplicasAvailable.name}{
${Metrics.kubeDeploymentStatusReplicasAvailable.labels.deployment}=~"${deployment}",
${Metrics.kubeDeploymentStatusReplicasAvailable.labels.namespace}="${namespace}",
cluster="$cluster"
}
) by (${Metrics.kubeDeploymentStatusReplicasAvailable.labels.deployment})`,
Expand All @@ -65,6 +72,7 @@ function getReplicasPanel(deployment: string) {
max(
${Metrics.kubeDeploymentStatusReplicas.name}{
${Metrics.kubeDeploymentStatusReplicas.labels.deployment}=~"${deployment}",
${Metrics.kubeDeploymentStatusReplicas.labels.namespace}="${namespace}",
cluster="$cluster"
}
) by (${Metrics.kubeDeploymentStatusReplicas.labels.deployment})`,
Expand All @@ -81,7 +89,7 @@ function getReplicasPanel(deployment: string) {
.build()
}

function getScene(deployment: string) {
function getScene(deployment: string, namespace = '$namespace') {
return new EmbeddedScene({
controls: [
new VariableValueSelectors({}),
Expand All @@ -106,12 +114,16 @@ function getScene(deployment: string) {
label: 'deployment',
op: '=',
value: deployment,
}, {
label: 'namespace',
op: '=',
value: namespace,
}]),
}),
new SceneFlexItem({
height: 200,
width: `${(2/3) * 100}%`,
body: getReplicasPanel(deployment),
body: getReplicasPanel(deployment, namespace),
})
]
}),
Expand All @@ -129,11 +141,19 @@ function getScene(deployment: string) {
label: 'pod',
op: '=~',
value: `${deployment}.*`
}, {
label: 'namespace',
op: '=',
value: namespace
}]),
MemoryUsagePanel([{
label: 'pod',
op: '=~',
value: `${deployment}.*`
}, {
label: 'namespace',
op: '=',
value: namespace
}]),
]
}),
Expand All @@ -148,7 +168,7 @@ function getScene(deployment: string) {
children: [
new SceneFlexItem({
width: '100%',
body: getPods(deployment),
body: getPods(deployment, namespace),
}),
]
}),
Expand All @@ -168,12 +188,12 @@ export function DeploymentPage(routeMatch: SceneRouteMatch<any>, parent: SceneAp
const timeRange = createTimeRange()

return new SceneAppPage({
title: `Deployment - ${routeMatch.params.name}`,
title: `Deployment - ${routeMatch.params.namespace}/${routeMatch.params.name}`,
titleIcon: 'dashboard',
$variables: variables,
$timeRange: timeRange,
url: prefixRoute(`${ROUTES.Workloads}/deployments/${routeMatch.params.namespace}/${routeMatch.params.name}`),
getScene: () => getScene(routeMatch.params.name),
getScene: () => getScene(routeMatch.params.name, routeMatch.params.namespace),
getParentPage: () => parent,
})
}

0 comments on commit a5eca4b

Please sign in to comment.