Skip to content

Commit

Permalink
started work
Browse files Browse the repository at this point in the history
  • Loading branch information
wind57 committed Sep 22, 2023
1 parent 4c5eecf commit bbc75ba
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import org.springframework.web.reactive.function.client.WebClient;

import static org.awaitility.Awaitility.await;
import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.Fabric8CatalogWatchUtil.patchForEndpointSlices;
import static org.springframework.cloud.kubernetes.integration.tests.commons.Commons.pomVersion;

/**
* @author wind57
Expand All @@ -57,26 +59,31 @@ class Fabric8CatalogWatchIT {

private static final String NAMESPACE = "default";

private static final K3sContainer K3S = Commons.container();
private static final String IMAGE_NAME = "spring-cloud-kubernetes-fabric8-client-catalog-watcher";

private static final String DOCKER_IMAGE = "docker.io/springcloud/" + IMAGE_NAME + ":" + pomVersion();

private static KubernetesClient client;
private static final K3sContainer K3S = Commons.container();

private static Util util;

@BeforeAll
static void beforeAll() throws Exception {
K3S.start();
util = new Util(K3S);
client = util.client();
KubernetesClient client = util.client();

Commons.validateImage(APP_NAME, K3S);
Commons.loadSpringCloudKubernetesImage(APP_NAME, K3S);

app(Phase.CREATE);

util.setUp(NAMESPACE);
}

@AfterAll
static void afterAll() {
app(Phase.DELETE);
Commons.systemPrune();
}

Expand All @@ -95,18 +102,16 @@ void beforeEach() {
*/
@Test
void testCatalogWatchWithEndpoints() throws Exception {
app(false, Phase.CREATE);
assertLogStatement("stateGenerator is of type: Fabric8EndpointsCatalogWatch");
test();
app(false, Phase.DELETE);

testCatalogWatchWithEndpointSlices();
}

@Test
void testCatalogWatchWithEndpointSlices() throws Exception {
app(true, Phase.CREATE);
patchForEndpointSlices(util, DOCKER_IMAGE, IMAGE_NAME, NAMESPACE);
assertLogStatement("stateGenerator is of type: Fabric8EndpointSliceV1CatalogWatch");
test();
app(true, Phase.DELETE);
}

/**
Expand Down Expand Up @@ -143,6 +148,9 @@ private void test() {
// watcher implementation
// we will get the first busybox instances here.
if (result != null) {
if (result.size() != 3) {
return false;
}
holder[0] = result.get(0);
holder[1] = result.get(1);
return true;
Expand Down Expand Up @@ -195,16 +203,13 @@ private void test() {

}

private static void app(boolean useEndpointSlices, Phase phase) {
private static void app(Phase phase) {

InputStream endpointsDeploymentStream = util.inputStream("app/watcher-endpoints-deployment.yaml");
InputStream endpointSlicesDeploymentStream = util.inputStream("app/watcher-endpoint-slices-deployment.yaml");
InputStream serviceStream = util.inputStream("app/watcher-service.yaml");
InputStream ingressStream = util.inputStream("app/watcher-ingress.yaml");

Deployment deployment = useEndpointSlices
? Serialization.unmarshal(endpointSlicesDeploymentStream, Deployment.class)
: Serialization.unmarshal(endpointsDeploymentStream, Deployment.class);
Deployment deployment = Serialization.unmarshal(endpointsDeploymentStream, Deployment.class);
Service service = Serialization.unmarshal(serviceStream, Service.class);
Ingress ingress = Serialization.unmarshal(ingressStream, Ingress.class);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2013-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.cloud.kubernetes.fabric8.catalog.watch;

import java.util.Map;

import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util;

/**
* @author wind57
*/
final class Fabric8CatalogWatchUtil {

private static final Map<String, String> POD_LABELS = Map.of();

private Fabric8CatalogWatchUtil() {

}

static final String BODY_ONE = """
{
"spec": {
"template": {
"spec": {
"containers": [{
"name": "spring-cloud-kubernetes-fabric8-client-discovery",
"image": "image_name_here",
"env": [
{
"name": "LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_COMMONS_DISCOVERY",
"value": "DEBUG"
},
{
"name": "LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_CLIENT_DISCOVERY_HEALTH",
"value": "DEBUG"
},
{
"name": "LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_FABRIC8_DISCOVERY",
"value": "DEBUG"
},
{
"name": "SPRING_CLOUD_DISCOVERY_REACTIVE_ENABLED",
"value": "FALSE"
}
]
}]
}
}
}
}
""";

static void patchForEndpointSlices(Util util, String dockerImage, String deploymentName, String namespace) {
util.patchWithReplace(dockerImage, deploymentName, namespace, BODY_ONE, POD_LABELS);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ spec:
- name: LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_FABRIC8_DISCOVERY
value: DEBUG
- name: SPRING_CLOUD_KUBERNETES_DISCOVERY_USE_ENDPOINT_SLICES
value: false
value: "false"

0 comments on commit bbc75ba

Please sign in to comment.