diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-common/src/main/java/org/apache/shenyu/springboot/starter/client/common/config/ShenyuClientCommonBeanConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-common/src/main/java/org/apache/shenyu/springboot/starter/client/common/config/ShenyuClientCommonBeanConfiguration.java index b16a9b8e9662..948d75af5f4d 100644 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-common/src/main/java/org/apache/shenyu/springboot/starter/client/common/config/ShenyuClientCommonBeanConfiguration.java +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-common/src/main/java/org/apache/shenyu/springboot/starter/client/common/config/ShenyuClientCommonBeanConfiguration.java @@ -73,7 +73,7 @@ public ShenyuClientConfig shenyuClientConfig() { * @return the shenyu discovery config */ @Bean - @ConditionalOnProperty(prefix = "shenyu.discovery", name = "enable", matchIfMissing = false, havingValue = "true") + @ConditionalOnProperty(prefix = "shenyu.discovery", name = "enable", havingValue = "true") @ConfigurationProperties(prefix = "shenyu.discovery") public ShenyuDiscoveryConfig shenyuDiscoveryConfig() { return new ShenyuDiscoveryConfig(); diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway/src/main/java/org/apache/shenyu/springboot/starter/netty/ShenyuNettyWebServerConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway/src/main/java/org/apache/shenyu/springboot/starter/netty/ShenyuNettyWebServerConfiguration.java index 09b88531a1c3..775ddb40c170 100644 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway/src/main/java/org/apache/shenyu/springboot/starter/netty/ShenyuNettyWebServerConfiguration.java +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-gateway/src/main/java/org/apache/shenyu/springboot/starter/netty/ShenyuNettyWebServerConfiguration.java @@ -19,6 +19,7 @@ import io.netty.channel.ChannelOption; import io.netty.channel.WriteBufferWaterMark; +import org.apache.commons.collections4.CollectionUtils; import org.apache.shenyu.common.config.NettyHttpProperties; import org.apache.shenyu.common.exception.ShenyuException; import org.apache.shenyu.common.config.ssl.ShenyuSniAsyncMapping; @@ -99,12 +100,13 @@ public NettyReactiveWebServerFactory nettyReactiveWebServerFactory(final ObjectP throw new ShenyuException("Can not find shenyuSniAsyncMapping bean"); } if ("manual".equals(sniProperties.getMod())) { - if (Objects.isNull(sniProperties.getCertificates()) || sniProperties.getCertificates().isEmpty()) { + List<SslCrtAndKeyFile> sslCrtAndKeyFiles = sniProperties.getCertificates(); + if (CollectionUtils.isEmpty(sslCrtAndKeyFiles)) { throw new ShenyuException("At least one certificate is required"); } // Use the first certificate as the default certificate (this default certificate will not actually be used) - List<SslCrtAndKeyFile> certificates = sniProperties.getCertificates(); + List<SslCrtAndKeyFile> certificates = sslCrtAndKeyFiles; for (SslCrtAndKeyFile certificate : certificates) { try { shenyuSniAsyncMapping.addSslCertificate(certificate); diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-k8s/src/main/java/org/apache/shenyu/springboot/starter/k8s/IngressControllerConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-k8s/src/main/java/org/apache/shenyu/springboot/starter/k8s/IngressControllerConfiguration.java index d745b89f4d42..0a6ad99abd1e 100644 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-k8s/src/main/java/org/apache/shenyu/springboot/starter/k8s/IngressControllerConfiguration.java +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-k8s/src/main/java/org/apache/shenyu/springboot/starter/k8s/IngressControllerConfiguration.java @@ -35,6 +35,7 @@ import io.kubernetes.client.openapi.models.V1Service; import io.kubernetes.client.openapi.models.V1ServiceList; import io.kubernetes.client.util.generic.GenericKubernetesApi; +import org.apache.commons.collections4.MapUtils; import org.apache.shenyu.common.config.NettyHttpProperties; import org.apache.shenyu.common.config.ssl.ShenyuSniAsyncMapping; import org.apache.shenyu.common.exception.ShenyuException; @@ -55,6 +56,8 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.time.Duration; + +import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.concurrent.Executors; @@ -97,7 +100,6 @@ public Controller ingressController(final SharedInformerFactory sharedInformerFa .build()); // TODO support config in application.yaml builder.withWorkerCount(2); -// builder.withReadyFunc(ingressReconciler::informerReady); return builder.withReconciler(ingressReconciler).withName("ingressController").build(); } @@ -260,9 +262,11 @@ public TcpSslContextSpec tcpSslContextSpec(final ObjectProvider<NettyHttpPropert String defaultNamespace = Optional.ofNullable(sniProperties.getDefaultK8sSecretNamespace()).orElse("default"); CoreV1Api coreV1Api = new CoreV1Api(apiClient); V1Secret secret = coreV1Api.readNamespacedSecret(defaultName, defaultNamespace, "true"); - if (Objects.nonNull(secret.getData())) { - InputStream crtStream = new ByteArrayInputStream(secret.getData().get("tls.crt")); - InputStream keyStream = new ByteArrayInputStream(secret.getData().get("tls.key")); + + Map<String, byte[]> secretData = secret.getData(); + if (MapUtils.isEmpty(secretData)) { + InputStream crtStream = new ByteArrayInputStream(secretData.get("tls.crt")); + InputStream keyStream = new ByteArrayInputStream(secretData.get("tls.key")); return TcpSslContextSpec.forServer(crtStream, keyStream); } else { throw new ShenyuException(String.format("Can not read cert and key from default secret %s/%s", defaultNamespace, defaultName));