1
- import * as _ from 'lodash' ;
2
1
import {
3
2
cronJobGVK ,
4
3
deploymentConfigGVK ,
5
4
deploymentGVK ,
6
- METADATA_ANNOTATION_APP_VERSION ,
7
- METADATA_ANNOTATION_QUARKUS_BUILD_TIMESTAMP ,
5
+ LAST_LANGUAGE_LOCAL_STORAGE_KEY ,
8
6
} from './const' ;
9
- import { CamelAppKind } from './types' ;
10
7
import { K8sResourceKind } from '@openshift-console/dynamic-plugin-sdk' ;
11
8
9
+ export const getLastLanguage = ( ) : string =>
10
+ localStorage . getItem ( LAST_LANGUAGE_LOCAL_STORAGE_KEY ) ?? navigator . language ;
11
+
12
12
export function CamelAppOwnerGVK ( kind : string ) {
13
13
switch ( kind ) {
14
14
case deploymentConfigGVK . kind :
@@ -20,31 +20,6 @@ export function CamelAppOwnerGVK(kind: string) {
20
20
}
21
21
}
22
22
23
- export function getAppVersion ( app : CamelAppKind ) : string | null {
24
- if ( app && app . metadata ) {
25
- return app . metadata . annotations ?. [ METADATA_ANNOTATION_APP_VERSION ] ;
26
- }
27
- return null ;
28
- }
29
-
30
- export function getBuildTimestamp ( app : CamelAppKind ) : string | null {
31
- if ( app && app . metadata ) {
32
- return app . metadata . annotations ?. [ METADATA_ANNOTATION_QUARKUS_BUILD_TIMESTAMP ] ;
33
- }
34
- return null ;
35
- }
36
-
37
- export function getHealthEndpoints ( framework : string ) : string [ ] {
38
- switch ( framework ) {
39
- case 'quarkus' :
40
- return [ '/observe/health/live' , '/observe/health/ready' , '/observe/health/started' ] ;
41
- case 'Spring-Boot' :
42
- return [ '/observe/health/liveness' , '/observe/health/readiness' ] ;
43
- default :
44
- return [ ] ;
45
- }
46
- }
47
-
48
23
// TODO use something else than Unknown
49
24
export function serviceMatchLabelValue ( camelAppOwner : K8sResourceKind ) : string {
50
25
if ( camelAppOwner . kind == 'Deployment' ) {
@@ -56,84 +31,3 @@ export function serviceMatchLabelValue(camelAppOwner: K8sResourceKind): string {
56
31
}
57
32
return 'Unknown' ;
58
33
}
59
-
60
- // Pods status utils
61
-
62
- const isContainerFailedFilter = ( containerStatus ) => {
63
- return containerStatus . state . terminated && containerStatus . state . terminated . exitCode !== 0 ;
64
- } ;
65
-
66
- export const isContainerLoopingFilter = ( containerStatus ) => {
67
- return (
68
- containerStatus . state . waiting && containerStatus . state . waiting . reason === 'CrashLoopBackOff'
69
- ) ;
70
- } ;
71
-
72
- const numContainersReadyFilter = ( pod ) => {
73
- const {
74
- status : { containerStatuses } ,
75
- } = pod ;
76
- let numReady = 0 ;
77
- _ . forEach ( containerStatuses , ( status ) => {
78
- if ( status . ready ) {
79
- numReady ++ ;
80
- }
81
- } ) ;
82
- return numReady ;
83
- } ;
84
-
85
- const isReady = ( pod ) => {
86
- const {
87
- spec : { containers } ,
88
- } = pod ;
89
- const numReady = numContainersReadyFilter ( pod ) ;
90
- const total = _ . size ( containers ) ;
91
-
92
- return numReady === total ;
93
- } ;
94
-
95
- const podWarnings = ( pod ) => {
96
- const {
97
- status : { phase, containerStatuses } ,
98
- } = pod ;
99
- if ( phase === 'Running' && containerStatuses ) {
100
- return _ . map ( containerStatuses , ( containerStatus ) => {
101
- if ( ! containerStatus . state ) {
102
- return null ;
103
- }
104
-
105
- if ( isContainerFailedFilter ( containerStatus ) ) {
106
- if ( _ . has ( pod , [ 'metadata' , 'deletionTimestamp' ] ) ) {
107
- return 'Failed' ;
108
- }
109
- return 'Warning' ;
110
- }
111
- if ( isContainerLoopingFilter ( containerStatus ) ) {
112
- return 'CrashLoopBackOff' ;
113
- }
114
- return null ;
115
- } ) . filter ( ( x ) => x ) ;
116
- }
117
- return null ;
118
- } ;
119
-
120
- export const getPodStatus = ( pod ) => {
121
- if ( _ . has ( pod , [ 'metadata' , 'deletionTimestamp' ] ) ) {
122
- return 'Terminating' ;
123
- }
124
- const warnings = podWarnings ( pod ) ;
125
- if ( warnings !== null && warnings . length ) {
126
- if ( warnings . includes ( 'CrashLoopBackOff' ) ) {
127
- return 'CrashLoopBackOff' ;
128
- }
129
- if ( warnings . includes ( 'Failed' ) ) {
130
- return 'Failed' ;
131
- }
132
- return 'Warning' ;
133
- }
134
- const phase = _ . get ( pod , [ 'status' , 'phase' ] , 'Unknown' ) ;
135
- if ( phase === 'Running' && ! isReady ( pod ) ) {
136
- return 'NotReady' ;
137
- }
138
- return phase ;
139
- } ;
0 commit comments