Skip to content

Commit

Permalink
Add route agent healthcheck
Browse files Browse the repository at this point in the history
Signed-off-by: Aswin Suryanarayanan <[email protected]>
  • Loading branch information
aswinsuryan committed Nov 27, 2024
1 parent 58b297e commit 1dde0cc
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,10 @@ const mockSubmarinerConfig: SubmarinerConfig = {
},
},
}
const SubmarinerConnectionDegraded = 'SubmarinerConnectionDegraded'
const SubmarinerAgentDegraded = 'SubmarinerAgentDegraded'
const SubmarinerGatewayNodesLabeled = 'SubmarinerGatewayNodesLabeled'
const RouteAgentConnectionDegraded = 'RouteAgentConnectionDegraded'

const mockSubmarinerAddonRosa: ManagedClusterAddOn = {
apiVersion: ManagedClusterAddOnApiVersion,
Expand All @@ -1209,6 +1213,46 @@ const mockSubmarinerAddonAro: ManagedClusterAddOn = {
spec: {
installNamespace: 'submariner-operator',
},
status: {
conditions: [
{
type: SubmarinerConnectionDegraded,
status: 'True',
lastTransitionTime: new Date('2024-11-01T10:00:00Z'),
message: 'Connection is degraded due to latency issues.',
reason: 'LatencyDetected',
},
{
type: SubmarinerAgentDegraded,
status: 'False',
lastTransitionTime: new Date('2024-11-01T09:00:00Z'),
message: 'Agent is functioning normally.',
reason: 'AllSystemsOperational',
},
{
type: SubmarinerGatewayNodesLabeled,
status: 'True',
lastTransitionTime: new Date('2024-11-01T08:30:00Z'),
message: 'All gateway nodes are properly labeled.',
reason: 'NodesLabeledSuccessfully',
},
{
type: RouteAgentConnectionDegraded,
status: 'False',
lastTransitionTime: new Date('2024-11-01T08:45:00Z'),
message: 'Route agent connection is stable.',
reason: 'ConnectionStable',
},
],
addOnMeta: {
displayName: 'Submariner Add-On',
description: 'Manages Submariner deployment for cross-cluster networking.',
},
addOnConfiguration: {
crdName: 'submarinerconfigs.submariner.io',
crName: 'submariner',
},
},
}

const mockSubmarinerAddonRoks: ManagedClusterAddOn = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ const SubmarinerConnectionDegraded: SubmarinerConnectionDegradedType = 'Submarin
type SubmarinerBrokerConfigAppliedType = 'SubmarinerBrokerConfigApplied'
const SubmarinerBrokerConfigApplied: SubmarinerBrokerConfigAppliedType = 'SubmarinerBrokerConfigApplied'

type RouteAgentConnectionDegradedType = 'RouteAgentConnectionDegraded'
const RouteAgentConnectionDegraded: RouteAgentConnectionDegradedType = 'RouteAgentConnectionDegraded'

export enum SubmarinerStatus {
'progressing' = 'progressing',
'healthy' = 'healthy',
Expand All @@ -70,19 +73,25 @@ export const submarinerHealthCheck = (mca: ManagedClusterAddOn) => {
const connectionDegradedCondition = mca.status?.conditions?.find((c) => c.type === SubmarinerConnectionDegraded)
const agentCondition = mca.status?.conditions?.find((c) => c.type === SubmarinerAgentDegraded)
const nodeLabeledCondition = mca.status?.conditions?.find((c) => c.type === SubmarinerGatewayNodesLabeled)
const routeAgentConnectionDegradedCondition = mca.status?.conditions?.find(
(c) => c.type === RouteAgentConnectionDegraded
)

const isConnectionProgressing = connectionDegradedCondition?.status === undefined
const isRouteAgentProgressing = routeAgentConnectionDegradedCondition?.status === undefined
const isAgentProgressing = agentCondition?.status === undefined
const isNodeLabeledProgressing = nodeLabeledCondition?.status === undefined

if (isConnectionProgressing || isAgentProgressing || isNodeLabeledProgressing) {
if (isConnectionProgressing || isRouteAgentProgressing || isAgentProgressing || isNodeLabeledProgressing) {
return SubmarinerStatus.progressing
} else {
const isHealthyConnection = connectionDegradedCondition?.status === 'False'
const isHealthyRouteAgent = routeAgentConnectionDegradedCondition?.status === 'False'
const isHealthyAgent = agentCondition?.status === 'False'
const isNodeLabeled = nodeLabeledCondition?.status === 'True'
const isConnectionHealthy = isHealthyConnection && isHealthyRouteAgent

if (isHealthyConnection && isHealthyAgent && isNodeLabeled) {
if (isHealthyAgent && isNodeLabeled && isConnectionHealthy) {
return SubmarinerStatus.healthy
} else {
return SubmarinerStatus.degraded
Expand Down Expand Up @@ -154,17 +163,34 @@ export function ClusterSetSubmarinerPageContent() {
header: t('table.submariner.connection'),
cell: (mca: ManagedClusterAddOn) => {
const connectionDegradedCondition = mca.status?.conditions?.find((c) => c.type === SubmarinerConnectionDegraded)
const routeAgentConnectionDegradedCondition = mca.status?.conditions?.find(
(c) => c.type === RouteAgentConnectionDegraded
)

let type: StatusType = StatusType.progress
let status: string = t('status.submariner.progressing')
let message: string | undefined = t('status.submariner.progressing.message')
if (connectionDegradedCondition) {
status =
connectionDegradedCondition?.status === 'True'
? t('status.submariner.connection.degraded')
: t('status.submariner.connection.healthy')
type = connectionDegradedCondition?.status === 'True' ? StatusType.danger : StatusType.healthy
message = connectionDegradedCondition.message

const isSubmarinerDegraded = connectionDegradedCondition?.status === 'True'
const isRouteAgentDegraded = routeAgentConnectionDegradedCondition?.status === 'True'

if (isSubmarinerDegraded || isRouteAgentDegraded) {
status = t('status.submariner.connection.degraded')
type = StatusType.danger
if (isSubmarinerDegraded) {
message = connectionDegradedCondition?.message
} else {
message = routeAgentConnectionDegradedCondition?.message
}
} else if (
connectionDegradedCondition?.status === 'False' &&
routeAgentConnectionDegradedCondition?.status === 'False'
) {
type = StatusType.healthy
status = t('status.submariner.connection.healthy')
message = connectionDegradedCondition?.message
}

return <AcmInlineStatus type={type} status={status} popover={message ? { bodyContent: message } : undefined} />
},
},
Expand Down

0 comments on commit 1dde0cc

Please sign in to comment.