Skip to content

Commit

Permalink
Merge e2e9620 into c49c2af
Browse files Browse the repository at this point in the history
  • Loading branch information
renovate[bot] committed Oct 7, 2021
2 parents c49c2af + e2e9620 commit b896443
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 215 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ buildscript {
openApiVersion = '1.5.11'
requestValidatorPactVersion = '2.20.0'
postgresVersion = '42.2.24'
kubernetesClientVersion = '3.2.0'
kubernetesClientVersion = '5.8.0'
httpClientVersion = '4.5.13'
consulApiVersion = '1.4.5'
coverallsVersion = '2.12.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
@Component
public class UpdateServicesTask {

private String environment;
private String space;
private ServiceLocator serviceLocator;
private JudgeDPublisher publisher;
private final String environment;
private final String space;
private final ServiceLocator serviceLocator;
private final JudgeDPublisher publisher;

@Autowired
public UpdateServicesTask(
UpdateServicesTask(
@Value("${hltech.contracts.judge-d.environment}") String environment,
@Value("${hltech.contracts.judge-d.space:default}") String space,
ServiceLocator serviceLocator,
Expand Down Expand Up @@ -49,6 +49,4 @@ public void updateServices() {
private static JudgeDPublisher.ServiceForm toForm(ServiceLocator.Service service) {
return new JudgeDPublisher.ServiceForm(service.getName(), service.getVersion());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@

@Configuration
@EnableScheduling
public class BeanFactory {
class BeanFactory {

@Bean
public ObjectMapper objectMapper() {
ObjectMapper objectMapper() {
return new ObjectMapper();
}

@Bean
public JudgeDPublisher judgeDEnvironmentPublisher(Feign feign, @Value("${hltech.contracts.judge-d.baseUrl}") String baseUrl) {
JudgeDPublisher judgeDEnvironmentPublisher(Feign feign, @Value("${hltech.contracts.judge-d.baseUrl}") String baseUrl) {
return feign.newInstance(new Target.HardCodedTarget<>(JudgeDPublisher.class, baseUrl));
}

@Bean
public Feign feign(ObjectFactory<HttpMessageConverters> messageConverters, ObjectMapper objectMapper) throws KeyManagementException, NoSuchAlgorithmException {
Feign feign(ObjectFactory<HttpMessageConverters> messageConverters, ObjectMapper objectMapper) throws KeyManagementException, NoSuchAlgorithmException {
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, new TrustManager[]{new TrustAllX509TrustManager()}, null);
SSLSocketFactory trustingSSLSocketFactory = ctx.getSocketFactory();
Expand Down Expand Up @@ -81,5 +81,4 @@ public X509Certificate[] getAcceptedIssuers() {
return null;
}
}

}
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package com.hltech.judged.agent.config;

import com.hltech.judged.agent.JudgeDPublisher;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.HashSet;
import java.util.Set;

@Slf4j
public class CachingDelegatingDPublisher {
@RequiredArgsConstructor
class CachingDelegatingDPublisher {

private final JudgeDPublisher judgeDPublisher;

private Set<JudgeDPublisher.ServiceForm> previouslySentEnvironment;

public CachingDelegatingDPublisher(JudgeDPublisher judgeDPublisher) {
this.judgeDPublisher = judgeDPublisher;
}

public void publish(String environment, String space, Set<JudgeDPublisher.ServiceForm> serviceForms) {
void publish(String environment, String space, Set<JudgeDPublisher.ServiceForm> serviceForms) {
if (previouslySentEnvironment == null || !previouslySentEnvironment.equals(serviceForms)) {
log.info("publishing services to Judge-D: " + serviceForms);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Configuration
@Profile("consul")
@RequiredArgsConstructor
public class ConsulBeanFactory {
class ConsulBeanFactory {

@Value("${hltech.contracts.judge-d.consul-host}")
private String consulUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
import java.util.Set;
import java.util.stream.Collectors;


@RequiredArgsConstructor
public class ConsulTagBasedServiceLocator implements ServiceLocator {
class ConsulTagBasedServiceLocator implements ServiceLocator {

private static final String VERSION_TAG_PREFIX = "version=";
private static final String TAG_SEPARATOR = "=";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

@Configuration
@Profile("kubernetes")
public class K8sBeanFactory {
class K8sBeanFactory {

@Bean
public KubernetesClient kubernetesClient() {
KubernetesClient kubernetesClient() {
return new DefaultKubernetesClient();
}

@Bean
public ServiceLocator serviceLocator(
ServiceLocator serviceLocator(
KubernetesClient kubernetesClient,
@Value("${hltech.contracts.judge-d.requiredLabel}") String requiredLabel,
@Value("${hltech.contracts.judge-d.excluded-namespaces:#{''}}") Set<String> excludedNamespaces,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import static java.util.stream.Collectors.toList;

public class K8sLabelBasedServiceLocator implements ServiceLocator {
class K8sLabelBasedServiceLocator implements ServiceLocator {

private static final String EXCLUDE_FROM_JURISDICTION_LABEL = "exclude-from-judged-jurisdiction";

Expand All @@ -23,7 +23,7 @@ public class K8sLabelBasedServiceLocator implements ServiceLocator {
private final Predicate<Namespace> excludedNamespacesFilter;
private final Predicate<Namespace> includedNamespacesFilter;

public K8sLabelBasedServiceLocator(
K8sLabelBasedServiceLocator(
KubernetesClient kubernetesClient,
String requiredLabel,
Set<String> excludedNamespaces,
Expand All @@ -42,7 +42,9 @@ public K8sLabelBasedServiceLocator(
@Override
public Set<Service> locateServices() {
List<String> namespacesToScan = kubernetesClient
.namespaces().list().getItems().stream().filter(excludedNamespacesFilter).filter(includedNamespacesFilter)
.namespaces().list().getItems().stream()
.filter(excludedNamespacesFilter)
.filter(includedNamespacesFilter)
.map(n -> n.getMetadata().getName())
.collect(toList());

Expand All @@ -69,7 +71,7 @@ private Optional<ServiceLocator.Service> fromImage(String image) {
imageVersion
));
} else {
return Optional.<ServiceLocator.Service>empty();
return Optional.empty();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package com.hltech.judged.agent

import com.github.tomakehurst.wiremock.junit.WireMockRule
import io.fabric8.kubernetes.api.model.*
import io.fabric8.kubernetes.api.model.ContainerBuilder
import io.fabric8.kubernetes.api.model.NamespaceListBuilder
import io.fabric8.kubernetes.api.model.PodBuilder
import io.fabric8.kubernetes.api.model.PodList
import io.fabric8.kubernetes.api.model.PodListBuilder
import io.fabric8.kubernetes.api.model.PodSpecBuilder
import io.fabric8.kubernetes.api.model.PodStatusBuilder
import io.fabric8.kubernetes.client.Config
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer
import org.springframework.beans.factory.annotation.Value
Expand All @@ -12,7 +18,11 @@ import spock.lang.Specification

import java.util.concurrent.TimeUnit

import static com.github.tomakehurst.wiremock.client.WireMock.*
import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson
import static com.github.tomakehurst.wiremock.client.WireMock.ok
import static com.github.tomakehurst.wiremock.client.WireMock.put
import static com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching
import static org.awaitility.Awaitility.await

@SpringBootTest
Expand Down Expand Up @@ -44,23 +54,25 @@ class K8sServiceLocatorFT extends Specification {
}

def 'should send update services message with expected names and versions'() {
given: "expected namespaces"
given: 'expected namespaces'
k8sServer.expect().get().withPath('/api/v1/namespaces')
.andReturn(200, new NamespaceListBuilder()
.addNewItem()
.withNewMetadata()
.withName('firstnamespace')
.withLabels([:])
.endMetadata()
.and()
.addNewItem()
.withNewMetadata()
.withName('secondnamespace')
.withLabels([:])
.endMetadata()
.and()
.build())
.always()

and: "expected pods"
and: 'expected pods'
PodList expectedPodList = new PodListBuilder()
.withItems(
buildPod('firstnamespace', 1, '78d588f9cc'),
Expand All @@ -72,23 +84,23 @@ class K8sServiceLocatorFT extends Specification {
.andReturn(HttpURLConnection.HTTP_OK, expectedPodList)
.always()

and: "expected message to publish"
and: 'expected message to publish'
def expectedRequestBody = '''
[
{
"name": "test_app_1",
"version": "78d588f9cc"
},
{
"name": "test_app_2",
"version": "54d576f9dh"
},
{
"name": "test_app_3",
"version": "98d500g9df"
}
]
'''
[
{
"name": "test_app_1",
"version": "78d588f9cc"
},
{
"name": "test_app_2",
"version": "54d576f9dh"
},
{
"name": "test_app_3",
"version": "98d500g9df"
}
]
'''

wireMockRule.stubFor(
put(urlPathMatching('/environments/test'))
Expand All @@ -106,6 +118,7 @@ class K8sServiceLocatorFT extends Specification {
new PodBuilder().withNewMetadata()
.withName("pod$index")
.withNamespace(namespace)
.withLabels([:])
.endMetadata()
.withSpec(
new PodSpecBuilder().withContainers(
Expand Down
Loading

0 comments on commit b896443

Please sign in to comment.