|  | 
|  | 1 | +/* | 
|  | 2 | + * Copyright 2012-2024 the original author or authors. | 
|  | 3 | + * | 
|  | 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | + * you may not use this file except in compliance with the License. | 
|  | 6 | + * You may obtain a copy of the License at | 
|  | 7 | + * | 
|  | 8 | + *      https://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | + * | 
|  | 10 | + * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | + * See the License for the specific language governing permissions and | 
|  | 14 | + * limitations under the License. | 
|  | 15 | + */ | 
|  | 16 | + | 
|  | 17 | +package org.springframework.cloud.kubernetes.fabric8.catalog.watch; | 
|  | 18 | + | 
|  | 19 | +import java.util.Map; | 
|  | 20 | +import java.util.Set; | 
|  | 21 | + | 
|  | 22 | +import io.fabric8.kubernetes.client.Config; | 
|  | 23 | +import io.fabric8.kubernetes.client.KubernetesClient; | 
|  | 24 | +import io.fabric8.kubernetes.client.KubernetesClientBuilder; | 
|  | 25 | +import org.junit.jupiter.api.BeforeAll; | 
|  | 26 | +import org.junit.jupiter.api.extension.ExtendWith; | 
|  | 27 | +import org.testcontainers.k3s.K3sContainer; | 
|  | 28 | + | 
|  | 29 | +import org.springframework.boot.test.system.OutputCaptureExtension; | 
|  | 30 | +import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; | 
|  | 31 | +import org.springframework.cloud.kubernetes.integration.tests.commons.Commons; | 
|  | 32 | +import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util; | 
|  | 33 | +import org.springframework.test.context.TestPropertySource; | 
|  | 34 | + | 
|  | 35 | +/** | 
|  | 36 | + * @author wind57 | 
|  | 37 | + */ | 
|  | 38 | + | 
|  | 39 | +@TestPropertySource( | 
|  | 40 | +		properties = { "spring.main.cloud-platform=kubernetes", "spring.cloud.config.import-check.enabled=false", | 
|  | 41 | +				"spring.cloud.kubernetes.discovery.catalogServicesWatchDelay=2000", | 
|  | 42 | +				"spring.cloud.kubernetes.client.namespace=default", | 
|  | 43 | +				"logging.level.org.springframework.cloud.kubernetes.fabric8.discovery=DEBUG" }) | 
|  | 44 | +@ExtendWith(OutputCaptureExtension.class) | 
|  | 45 | +abstract class Fabric8CatalogWatchBase { | 
|  | 46 | + | 
|  | 47 | +	protected static final String NAMESPACE = "default"; | 
|  | 48 | + | 
|  | 49 | +	protected static final String NAMESPACE_A = "a"; | 
|  | 50 | + | 
|  | 51 | +	protected static final String NAMESPACE_B = "b"; | 
|  | 52 | + | 
|  | 53 | +	protected static final K3sContainer K3S = Commons.container(); | 
|  | 54 | + | 
|  | 55 | +	protected static Util util; | 
|  | 56 | + | 
|  | 57 | +	@BeforeAll | 
|  | 58 | +	protected static void beforeAll() { | 
|  | 59 | +		K3S.start(); | 
|  | 60 | +		util = new Util(K3S); | 
|  | 61 | +	} | 
|  | 62 | + | 
|  | 63 | +	protected static KubernetesDiscoveryProperties discoveryProperties(boolean useEndpointSlices) { | 
|  | 64 | +		return new KubernetesDiscoveryProperties(true, false, Set.of(NAMESPACE, NAMESPACE_A), true, 60, false, null, | 
|  | 65 | +				Set.of(443, 8443), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, useEndpointSlices, | 
|  | 66 | +				false, null); | 
|  | 67 | +	} | 
|  | 68 | + | 
|  | 69 | +	protected static KubernetesClient client() { | 
|  | 70 | +		String kubeConfigYaml = K3S.getKubeConfigYaml(); | 
|  | 71 | +		Config config = Config.fromKubeconfig(kubeConfigYaml); | 
|  | 72 | +		return new KubernetesClientBuilder().withConfig(config).build(); | 
|  | 73 | +	} | 
|  | 74 | + | 
|  | 75 | +} | 
0 commit comments