Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private List<DivideUpstream> parseUpstream(final V1IngressBackend backend, final
DivideUpstream upstream = new DivideUpstream();
upstream.setUpstreamUrl(upstreamIp + ":" + defaultPort);
upstream.setWeight(100);
upstream.setProtocol(Objects.isNull(protocol) ? "http://" : protocol[i++]);
upstream.setProtocol(Objects.isNull(protocol) || i >= protocol.length ? "http://" : protocol[i++]);
upstream.setWarmup(0);
upstream.setStatus(true);
upstream.setUpstreamHost("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ private List<DubboUpstream> parseUpstream(final V1HTTPIngressPath path, final St
DubboUpstream upstream = DubboUpstream.builder()
.upstreamUrl(upstreamIp + ":" + defaultPort)
.weight(100)
.protocol(Objects.isNull(protocols[i++]) ? "dubbo://" : protocols[i++])
.protocol(i >= protocols.length ? "dubbo://" : protocols[i++])
.warmup(0)
.status(true)
.upstreamHost("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
import io.kubernetes.client.openapi.models.V1EndpointSubsetBuilder;
import io.kubernetes.client.openapi.models.V1EndpointAddress;
import org.apache.shenyu.common.config.ssl.ShenyuSniAsyncMapping;
import org.apache.shenyu.common.dto.SelectorData;
import org.apache.shenyu.k8s.parser.IngressParser;
import org.apache.shenyu.k8s.reconciler.IngressReconciler;
import org.apache.shenyu.k8s.repository.ShenyuCacheRepository;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -119,4 +121,22 @@ public void testReconcile() {
verify(shenyuCacheRepository).saveOrUpdateSelectorData(any());
verify(shenyuCacheRepository).saveOrUpdateRuleData(any());
}

/**
* test reconcile with fewer protocols than endpoints.
*/
@Test
public void testReconcileWithFewerProtocolsThanEndpoints() {
V1Ingress ingress = ingressInformer.getIndexer().getByKey("mockedNamespace/mockedIngress");
Map<String, String> annotations = ingress.getMetadata().getAnnotations();
annotations.put("shenyu.apache.org/upstreams-protocol", "https://");
V1Endpoints endpoints = endpointsInformer.getIndexer().getByKey("mockedNamespace/testService");
endpoints.getSubsets().get(0).setAddresses(java.util.Arrays.asList(
new V1EndpointAddress().ip("127.0.0.1"), new V1EndpointAddress().ip("127.0.0.2")));
ingressReconciler.reconcile(new Request("mockedNamespace", "mockedIngress"));
ArgumentCaptor<SelectorData> selectorCaptor = ArgumentCaptor.forClass(SelectorData.class);
verify(shenyuCacheRepository).saveOrUpdateSelectorData(selectorCaptor.capture());
Assertions.assertTrue(selectorCaptor.getValue().getHandle().contains("https://"));
Assertions.assertTrue(selectorCaptor.getValue().getHandle().contains("http://"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
import io.kubernetes.client.openapi.models.V1Service;
import io.kubernetes.client.openapi.models.V1ServiceBuilder;
import org.apache.shenyu.common.config.ssl.ShenyuSniAsyncMapping;
import org.apache.shenyu.common.dto.SelectorData;
import org.apache.shenyu.k8s.parser.IngressParser;
import org.apache.shenyu.k8s.reconciler.IngressReconciler;
import org.apache.shenyu.k8s.repository.ShenyuCacheRepository;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -150,4 +152,22 @@ public void testReconcile() {
verify(shenyuCacheRepository).saveOrUpdateRuleData(any());
verify(shenyuCacheRepository).saveOrUpdateMetaData(any());
}

/**
* test reconcile with fewer protocols than endpoints.
*/
@Test
public void testReconcileWithFewerProtocolsThanEndpoints() {
V1Ingress ingress = ingressInformer.getIndexer().getByKey("mockedNamespace/mockedIngress");
Map<String, String> annotations = ingress.getMetadata().getAnnotations();
annotations.put("shenyu.apache.org/upstreams-protocol", "dubbo+ssl://");
V1Endpoints endpoints = endpointsInformer.getIndexer().getByKey("mockedNamespace/testService");
endpoints.getSubsets().get(0).setAddresses(java.util.Arrays.asList(
new V1EndpointAddress().ip("127.0.0.1"), new V1EndpointAddress().ip("127.0.0.2")));
ingressReconciler.reconcile(new Request("mockedNamespace", "mockedIngress"));
ArgumentCaptor<SelectorData> selectorCaptor = ArgumentCaptor.forClass(SelectorData.class);
verify(shenyuCacheRepository).saveOrUpdateSelectorData(selectorCaptor.capture());
Assertions.assertTrue(selectorCaptor.getValue().getHandle().contains("dubbo+ssl://"));
Assertions.assertTrue(selectorCaptor.getValue().getHandle().contains("dubbo://"));
}
}
Loading