3
3
*/
4
4
import * as constants from '../../constants.js' ;
5
5
import { SoloError } from '../../errors.js' ;
6
+ import { ConsensusNodeStates } from './enumerations.js' ;
6
7
7
8
import { type K8Factory } from '../../kube/k8_factory.js' ;
8
9
import { type ComponentsDataWrapper } from './components_data_wrapper.js' ;
9
10
import { type BaseComponent } from './components/base_component.js' ;
10
11
import { type NamespaceName } from '../../kube/resources/namespace/namespace_name.js' ;
11
12
import { type V1Pod } from '@kubernetes/client-node' ;
12
- import { ConsensusNodeStates } from './enumerations .js' ;
13
+ import { type LocalConfig } from '../local_config .js' ;
13
14
14
15
/**
15
16
* Static class is used to validate that components in the remote config
16
17
* are present in the kubernetes cluster, and throw errors if there is mismatch.
17
18
*/
18
19
export class RemoteConfigValidator {
19
20
/**
20
- * Gathers together and handles validation of all components.
21
+ * Gathers and handles validation of all components.
21
22
*
22
23
* @param namespace - namespace to validate the components in.
23
- * @param components - components which to validate.
24
+ * @param components - components to validate.
24
25
* @param k8Factory - to validate the elements.
25
- * TODO: Make compatible with multi-cluster K8 implementation
26
+ * @param localConfig - to get the context from cluster
26
27
*/
27
28
public static async validateComponents (
28
29
namespace : NamespaceName ,
29
30
components : ComponentsDataWrapper ,
30
31
k8Factory : K8Factory ,
32
+ localConfig : LocalConfig ,
31
33
) : Promise < void > {
32
34
await Promise . all ( [
33
- ...RemoteConfigValidator . validateRelays ( namespace , components , k8Factory ) ,
34
- ...RemoteConfigValidator . validateHaProxies ( namespace , components , k8Factory ) ,
35
- ...RemoteConfigValidator . validateMirrorNodes ( namespace , components , k8Factory ) ,
36
- ...RemoteConfigValidator . validateEnvoyProxies ( namespace , components , k8Factory ) ,
37
- ...RemoteConfigValidator . validateConsensusNodes ( namespace , components , k8Factory ) ,
38
- ...RemoteConfigValidator . validateMirrorNodeExplorers ( namespace , components , k8Factory ) ,
35
+ ...RemoteConfigValidator . validateRelays ( namespace , components , k8Factory , localConfig ) ,
36
+ ...RemoteConfigValidator . validateHaProxies ( namespace , components , k8Factory , localConfig ) ,
37
+ ...RemoteConfigValidator . validateMirrorNodes ( namespace , components , k8Factory , localConfig ) ,
38
+ ...RemoteConfigValidator . validateEnvoyProxies ( namespace , components , k8Factory , localConfig ) ,
39
+ ...RemoteConfigValidator . validateConsensusNodes ( namespace , components , k8Factory , localConfig ) ,
40
+ ...RemoteConfigValidator . validateMirrorNodeExplorers ( namespace , components , k8Factory , localConfig ) ,
39
41
] ) ;
40
42
}
41
43
42
44
private static validateRelays (
43
45
namespace : NamespaceName ,
44
46
components : ComponentsDataWrapper ,
45
47
k8Factory : K8Factory ,
48
+ localConfig : LocalConfig ,
46
49
) : Promise < void > [ ] {
47
50
return Object . values ( components . relays ) . map ( async component => {
51
+ const context = localConfig . clusterRefs [ component . cluster ] ;
52
+ const labels = [ constants . SOLO_RELAY_LABEL ] ;
48
53
try {
49
- const pods : V1Pod [ ] = await k8Factory . default ( ) . pods ( ) . list ( namespace , [ constants . SOLO_RELAY_LABEL ] ) ;
54
+ const pods : V1Pod [ ] = await k8Factory . getK8 ( context ) . pods ( ) . list ( namespace , labels ) ;
50
55
51
- // to return the generic error message
52
- if ( ! pods . length ) throw new Error ( 'Pod not found' ) ;
56
+ if ( ! pods . length ) throw new Error ( 'Pod not found' ) ; // to return the generic error message
53
57
} catch ( e ) {
54
58
RemoteConfigValidator . throwValidationError ( 'Relay' , component , e ) ;
55
59
}
@@ -60,16 +64,15 @@ export class RemoteConfigValidator {
60
64
namespace : NamespaceName ,
61
65
components : ComponentsDataWrapper ,
62
66
k8Factory : K8Factory ,
67
+ localConfig : LocalConfig ,
63
68
) : Promise < void > [ ] {
64
69
return Object . values ( components . haProxies ) . map ( async component => {
70
+ const context = localConfig . clusterRefs [ component . cluster ] ;
71
+ const labels = [ `app=${ component . name } ` ] ;
65
72
try {
66
- const pods : V1Pod [ ] = await k8Factory
67
- . default ( )
68
- . pods ( )
69
- . list ( namespace , [ `app=${ component . name } ` ] ) ;
73
+ const pods : V1Pod [ ] = await k8Factory . getK8 ( context ) . pods ( ) . list ( namespace , labels ) ;
70
74
71
- // to return the generic error message
72
- if ( ! pods . length ) throw new Error ( 'Pod not found' ) ;
75
+ if ( ! pods . length ) throw new Error ( 'Pod not found' ) ; // to return the generic error message
73
76
} catch ( e ) {
74
77
RemoteConfigValidator . throwValidationError ( 'HaProxy' , component , e ) ;
75
78
}
@@ -80,13 +83,15 @@ export class RemoteConfigValidator {
80
83
namespace : NamespaceName ,
81
84
components : ComponentsDataWrapper ,
82
85
k8Factory : K8Factory ,
86
+ localConfig : LocalConfig ,
83
87
) : Promise < void > [ ] {
84
88
return Object . values ( components . mirrorNodes ) . map ( async component => {
89
+ const context = localConfig . clusterRefs [ component . cluster ] ;
90
+ const labels = constants . SOLO_HEDERA_MIRROR_IMPORTER ;
85
91
try {
86
- const pods : V1Pod [ ] = await k8Factory . default ( ) . pods ( ) . list ( namespace , constants . SOLO_HEDERA_MIRROR_IMPORTER ) ;
92
+ const pods : V1Pod [ ] = await k8Factory . getK8 ( context ) . pods ( ) . list ( namespace , labels ) ;
87
93
88
- // to return the generic error message
89
- if ( ! pods . length ) throw new Error ( 'Pod not found' ) ;
94
+ if ( ! pods . length ) throw new Error ( 'Pod not found' ) ; // to return the generic error message
90
95
} catch ( e ) {
91
96
RemoteConfigValidator . throwValidationError ( 'Mirror node' , component , e ) ;
92
97
}
@@ -97,16 +102,15 @@ export class RemoteConfigValidator {
97
102
namespace : NamespaceName ,
98
103
components : ComponentsDataWrapper ,
99
104
k8Factory : K8Factory ,
105
+ localConfig : LocalConfig ,
100
106
) : Promise < void > [ ] {
101
107
return Object . values ( components . envoyProxies ) . map ( async component => {
108
+ const context = localConfig . clusterRefs [ component . cluster ] ;
109
+ const labels = [ `app=${ component . name } ` ] ;
102
110
try {
103
- const pods : V1Pod [ ] = await k8Factory
104
- . default ( )
105
- . pods ( )
106
- . list ( namespace , [ `app=${ component . name } ` ] ) ;
111
+ const pods : V1Pod [ ] = await k8Factory . getK8 ( context ) . pods ( ) . list ( namespace , labels ) ;
107
112
108
- // to return the generic error message
109
- if ( ! pods . length ) throw new Error ( 'Pod not found' ) ;
113
+ if ( ! pods . length ) throw new Error ( 'Pod not found' ) ; // to return the generic error message
110
114
} catch ( e ) {
111
115
RemoteConfigValidator . throwValidationError ( 'Envoy proxy' , component , e ) ;
112
116
}
@@ -117,17 +121,17 @@ export class RemoteConfigValidator {
117
121
namespace : NamespaceName ,
118
122
components : ComponentsDataWrapper ,
119
123
k8Factory : K8Factory ,
124
+ localConfig : LocalConfig ,
120
125
) : Promise < void > [ ] {
121
126
return Object . values ( components . consensusNodes ) . map ( async component => {
127
+ if ( component . state === ConsensusNodeStates . REQUESTED ) return ;
128
+
129
+ const context = localConfig . clusterRefs [ component . cluster ] ;
130
+ const labels = [ `app=network-${ component . name } ` ] ;
122
131
try {
123
- if ( component . state === ConsensusNodeStates . REQUESTED ) return ;
124
- const pods : V1Pod [ ] = await k8Factory
125
- . default ( )
126
- . pods ( )
127
- . list ( namespace , [ `app=network-${ component . name } ` ] ) ;
128
-
129
- // to return the generic error message
130
- if ( ! pods . length ) throw new Error ( 'Pod not found' ) ;
132
+ const pods : V1Pod [ ] = await k8Factory . getK8 ( context ) . pods ( ) . list ( namespace , labels ) ;
133
+
134
+ if ( ! pods . length ) throw new Error ( 'Pod not found' ) ; // to return the generic error message
131
135
} catch ( e ) {
132
136
RemoteConfigValidator . throwValidationError ( 'Consensus node' , component , e ) ;
133
137
}
@@ -138,13 +142,15 @@ export class RemoteConfigValidator {
138
142
namespace : NamespaceName ,
139
143
components : ComponentsDataWrapper ,
140
144
k8Factory : K8Factory ,
145
+ localConfig : LocalConfig ,
141
146
) : Promise < void > [ ] {
142
147
return Object . values ( components . mirrorNodeExplorers ) . map ( async component => {
148
+ const context = localConfig . clusterRefs [ component . cluster ] ;
149
+ const labels = [ constants . SOLO_HEDERA_EXPLORER_LABEL ] ;
143
150
try {
144
- const pods : V1Pod [ ] = await k8Factory . default ( ) . pods ( ) . list ( namespace , [ constants . SOLO_HEDERA_EXPLORER_LABEL ] ) ;
151
+ const pods : V1Pod [ ] = await k8Factory . getK8 ( context ) . pods ( ) . list ( namespace , labels ) ;
145
152
146
- // to return the generic error message
147
- if ( ! pods . length ) throw new Error ( 'Pod not found' ) ;
153
+ if ( ! pods . length ) throw new Error ( 'Pod not found' ) ; // to return the generic error message
148
154
} catch ( e ) {
149
155
RemoteConfigValidator . throwValidationError ( 'Mirror node explorer' , component , e ) ;
150
156
}
0 commit comments