Skip to content

Commit

Permalink
Merge pull request #17 from inloco/feat/analysis-run-parser
Browse files Browse the repository at this point in the history
Parse AnalysisRuns to improve UI
  • Loading branch information
rbreeze authored Oct 19, 2022
2 parents 6b33a7a + b727c6c commit cef69c3
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions ui/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import { RolloutWidget } from "argo-rollouts/ui/src/app/components/rollout/rollout";
import { ObjectMeta, TypeMeta } from "argo-rollouts/ui/src/models/kubernetes";
import { RolloutRolloutInfo } from "argo-rollouts/ui/src/models/rollout/generated";
import { RolloutRolloutInfo, RolloutReplicaSetInfo, RolloutAnalysisRunInfo } from "argo-rollouts/ui/src/models/rollout/generated";

export type State = TypeMeta & { metadata: ObjectMeta } & {
status: any;
Expand All @@ -15,6 +15,7 @@ const parseInfoFromResourceNode = (
const ro: RolloutRolloutInfo = {};
const { spec, status, metadata } = resource;
ro.objectMeta = metadata as any;
ro.analysisRuns = parseAnalysisRuns(tree, resource);
ro.replicaSets = parseReplicaSets(tree, resource);

if (spec.strategy.canary) {
Expand Down Expand Up @@ -95,8 +96,8 @@ const parseCurrentSetWeight = (resource: State, currentStepIndex: number): strin
return "0";
};

const parseRevision = (rs: any) => {
for (const item of rs.info || []) {
const parseRevision = (node: any) => {
for (const item of node.info || []) {
if (item.name === "Revision") {
const parts = item.value.split(":") || [];
return parts.length == 2 ? parts[1] : "0";
Expand All @@ -112,7 +113,36 @@ const parsePodStatus = (pod: any) => {
}
};

const parseReplicaSets = (tree: any, rollout: any) => {
const parseAnalysisRuns = (tree: any, rollout: any): RolloutAnalysisRunInfo[] => tree.nodes
.filter(node => (node.kind === 'AnalysisRun') && (node.parentRefs.some(ref => ref.name === rollout.metadata.name)))
.map(node => ({
objectMeta: {
creationTimestamp: {
seconds: node.createdAt,
},
name: node.name,
namespace: node.namespace,
resourceVersion: node.version,
uid: node.uid,
},
revision: parseRevision(node),
status: parseAnalysisRunStatus(node.health.status),
}) as RolloutAnalysisRunInfo);

const parseAnalysisRunStatus = (status: string): string => {
switch(status) {
case 'Healthy':
return 'Successful';
case 'Progressing':
return 'Running';
case 'Degraded':
return 'Failure';
default:
return 'Error';
}
}

const parseReplicaSets = (tree: any, rollout: any): RolloutReplicaSetInfo[] => {
const allReplicaSets = [];
const allPods = [];
for (const node of tree.nodes) {
Expand Down

0 comments on commit cef69c3

Please sign in to comment.