31
31
import io .kubernetes .client .openapi .models .V1IngressTLS ;
32
32
import io .kubernetes .client .openapi .models .V1Secret ;
33
33
import io .kubernetes .client .openapi .models .V1Service ;
34
+ import io .kubernetes .client .openapi .models .V1ServiceBackendPort ;
34
35
import org .apache .commons .collections4 .CollectionUtils ;
35
36
import org .apache .commons .lang3 .StringUtils ;
36
37
import org .apache .commons .lang3 .tuple .Pair ;
@@ -128,13 +129,16 @@ public ShenyuMemoryConfig parse(final V1Ingress ingress, final CoreV1Api coreV1A
128
129
if (Objects .nonNull (tlsList ) && CollectionUtils .isNotEmpty (tlsList )) {
129
130
List <SslCrtAndKeyStream > sslList = new ArrayList <>();
130
131
for (V1IngressTLS tls : tlsList ) {
131
- if (Objects .nonNull (tls .getSecretName ()) && Objects .nonNull (tls .getHosts ()) && CollectionUtils .isNotEmpty (tls .getHosts ())) {
132
+ List <String > hosts = tls .getHosts ();
133
+ String secretName = tls .getSecretName ();
134
+ if (Objects .nonNull (secretName ) && CollectionUtils .isNotEmpty (hosts )) {
132
135
try {
133
- V1Secret secret = coreV1Api .readNamespacedSecret (tls .getSecretName (), namespace , "ture" );
134
- if (secret .getData () != null ) {
135
- InputStream keyCertChainInputStream = new ByteArrayInputStream (secret .getData ().get ("tls.crt" ));
136
- InputStream keyInputStream = new ByteArrayInputStream (secret .getData ().get ("tls.key" ));
137
- tls .getHosts ().forEach (host ->
136
+ V1Secret secret = coreV1Api .readNamespacedSecret (secretName , namespace , "ture" );
137
+ Map <String , byte []> secretData = secret .getData ();
138
+ if (Objects .nonNull (secretData )) {
139
+ InputStream keyCertChainInputStream = new ByteArrayInputStream (secretData .get ("tls.crt" ));
140
+ InputStream keyInputStream = new ByteArrayInputStream (secretData .get ("tls.key" ));
141
+ hosts .forEach (host ->
138
142
sslList .add (new SslCrtAndKeyStream (host , keyCertChainInputStream , keyInputStream ))
139
143
);
140
144
}
@@ -186,11 +190,19 @@ private List<DubboUpstream> getDefaultDubboRouteConfig(final V1IngressBackend de
186
190
}
187
191
188
192
private String parsePort (final V1IngressServiceBackend service ) {
189
- if (Objects .nonNull (service .getPort ())) {
190
- if (service .getPort ().getNumber () != null && service .getPort ().getNumber () > 0 ) {
191
- return String .valueOf (service .getPort ().getNumber ());
192
- } else if (service .getPort ().getName () != null && StringUtils .isNoneBlank (service .getPort ().getName ().trim ())) {
193
- return service .getPort ().getName ().trim ();
193
+ V1ServiceBackendPort servicePort = service .getPort ();
194
+ if (Objects .nonNull (servicePort )) {
195
+ Integer portNumber = servicePort .getNumber ();
196
+ if (Objects .nonNull (portNumber ) && portNumber > 0 ) {
197
+ return String .valueOf (portNumber );
198
+ } else {
199
+ String servicePortName = servicePort .getName ();
200
+ if (Objects .nonNull (servicePortName )) {
201
+ String trim = servicePortName .trim ();
202
+ if (StringUtils .isNoneBlank (trim )) {
203
+ return trim ;
204
+ }
205
+ }
194
206
}
195
207
}
196
208
return null ;
@@ -207,11 +219,12 @@ private List<IngressConfiguration> parseIngressRule(final V1IngressRule ingressR
207
219
List <V1HTTPIngressPath > paths = ingressRule .getHttp ().getPaths ();
208
220
if (Objects .nonNull (paths )) {
209
221
for (V1HTTPIngressPath path : paths ) {
210
- if (path .getPath () == null ) {
222
+ String pathPath = path .getPath ();
223
+ if (Objects .isNull (pathPath )) {
211
224
continue ;
212
225
}
213
226
OperatorEnum operator = getOperator (path .getPathType ());
214
- ConditionData pathCondition = createPathCondition (path . getPath () , operator );
227
+ ConditionData pathCondition = createPathCondition (pathPath , operator );
215
228
List <ConditionData > conditionList = new ArrayList <>(2 );
216
229
if (Objects .nonNull (hostCondition )) {
217
230
conditionList .add (hostCondition );
@@ -222,7 +235,7 @@ private List<IngressConfiguration> parseIngressRule(final V1IngressRule ingressR
222
235
if (upstreamList .isEmpty ()) {
223
236
upstreamList = dubboUpstreamList ;
224
237
}
225
- SelectorData selectorData = createSelectorData (path . getPath () , conditionList , upstreamList );
238
+ SelectorData selectorData = createSelectorData (pathPath , conditionList , upstreamList );
226
239
List <RuleData > ruleDataList = new ArrayList <>();
227
240
List <MetaData > metaDataList = new ArrayList <>();
228
241
for (String label : labels .keySet ()) {
0 commit comments