Skip to content

Commit

Permalink
Update Fabric8 version and usage. (#431)
Browse files Browse the repository at this point in the history
* Remove disabled tests.
  • Loading branch information
Corneil du Plessis authored Jan 26, 2024
1 parent 43d7551 commit b7398c0
Show file tree
Hide file tree
Showing 20 changed files with 236 additions and 193 deletions.
30 changes: 30 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
root = true

[*.java]
indent_style = tab
indent_size = 4

[*.adoc]
indent_style = tab
indent_size = 4

[*.groovy]
indent_style = tab
indent_size = 4

[*.xml]
indent_style = tab
indent_size = 4

[*.yml]
indent_style = space
indent_size = 2

[*.yaml]
indent_style = space
indent_size = 2

[*.sh]
indent_style = space
indent_size = 4
end_of_line = lf
2 changes: 1 addition & 1 deletion .github/workflows/ci-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
# build
- name: Build
run: |
mvn -U -B clean package -T 0.5C
mvn -U -B clean package
- name: Capture Test Results
if: failure()
uses: actions/upload-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
# build and publish
- name: Build and Publish
run: |
jfrog rt mvn -U -B clean install -T 0.5C
jfrog rt mvn -U -B clean install
jfrog rt build-publish
- name: Test Report
uses: dorny/test-reporter@v1
Expand Down
9 changes: 3 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@
<maven-resolver.version>1.9.18</maven-resolver.version>
<maven-wagon.version>3.5.3</maven-wagon.version>
<commons-io.version>2.15.1</commons-io.version>
<kubernetes-fabric8-client.version>5.12.4</kubernetes-fabric8-client.version>
<kubernetes-fabric8-client.version>6.9.2</kubernetes-fabric8-client.version>
<spring-boot.version>3.2.2</spring-boot.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<json-path.version>2.9.0</json-path.version> <!-- TODO remove when fixed in SB -->
</properties>

<modules>
Expand All @@ -83,11 +84,7 @@
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>3.4.0</version>
<version>${json-path.version}</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.cloudfoundry.operations.applications.InstanceDetail;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;

Expand All @@ -44,7 +43,6 @@

import static org.assertj.core.api.Assertions.assertThat;

@Disabled
public class CloudFoundryActuatorTemplateTests extends AbstractAppDeployerTestSupport {

private ActuatorOperations actuatorOperations;
Expand Down
5 changes: 0 additions & 5 deletions spring-cloud-deployer-kubernetes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
<java-semver.version>0.9.0</java-semver.version>
<maven.compiler.plugin.version>3.8.0</maven.compiler.plugin.version>
<powermock.version>2.0.2</powermock.version>
<okhttp.version>3.14.9</okhttp.version>
<fabric8-kubernetes-client.version>5.12.4</fabric8-kubernetes-client.version>
</properties>


Expand All @@ -46,7 +44,6 @@
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<version>${fabric8-kubernetes-client.version}</version>
</dependency>
<dependency>
<groupId>org.hashids</groupId>
Expand Down Expand Up @@ -85,13 +82,11 @@
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<version>${okhttp.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
* @author Enrique Medina Montenegro
* @author Ilayaperumal Gopinathan
* @author Chris Bono
* @author Corneil du Plessis
*/
public class AbstractKubernetesDeployer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import io.fabric8.kubernetes.api.model.ServiceList;
import io.fabric8.kubernetes.api.model.ServicePort;
import io.fabric8.kubernetes.api.model.ServiceSpecBuilder;
import io.fabric8.kubernetes.api.model.StatusDetails;
import io.fabric8.kubernetes.api.model.VolumeBuilder;
import io.fabric8.kubernetes.api.model.VolumeMountBuilder;
import io.fabric8.kubernetes.api.model.apps.Deployment;
Expand All @@ -50,12 +51,16 @@
import io.fabric8.kubernetes.api.model.apps.StatefulSetSpec;
import io.fabric8.kubernetes.api.model.apps.StatefulSetSpecBuilder;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable;
import io.fabric8.kubernetes.client.dsl.PodResource;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.kubernetes.client.dsl.RollableScalableResource;
import io.fabric8.kubernetes.client.dsl.ScalableResource;
import io.fabric8.kubernetes.client.dsl.ServiceResource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.deployer.spi.app.AppDeployer;
import org.springframework.cloud.deployer.spi.app.AppInstanceStatus;
import org.springframework.cloud.deployer.spi.app.AppScaleRequest;
Expand All @@ -81,17 +86,16 @@
* @author Christian Tzolov
* @author Omar Gonzalez
* @author Chris Bono
* @author Corneil du Plessis
*/
public class KubernetesAppDeployer extends AbstractKubernetesDeployer implements AppDeployer {

protected final Log logger = LogFactory.getLog(getClass().getName());

@Autowired
public KubernetesAppDeployer(KubernetesDeployerProperties properties, KubernetesClient client) {
this(properties, client, new DefaultContainerFactory(properties));
}

@Autowired
public KubernetesAppDeployer(KubernetesDeployerProperties properties, KubernetesClient client,
ContainerFactory containerFactory) {
this.properties = properties;
Expand All @@ -106,7 +110,7 @@ public String deploy(AppDeploymentRequest request) {
String appId = createDeploymentId(request);
if (logger.isDebugEnabled()) {
ArgumentSanitizer sanitizer = new ArgumentSanitizer();
Map<String,String> sanitized = sanitizer.sanitizeProperties(request.getDeploymentProperties());
Map<String, String> sanitized = sanitizer.sanitizeProperties(request.getDeploymentProperties());
List<String> sanitizedCommandlineArguments = sanitizer.sanitizeArguments(request.getCommandlineArguments());
logger.debug(String.format("Deploying app: %s, request: commandlineArguments=%s, deploymentProperties=%s, definition=%s, resource=%s", appId, sanitizedCommandlineArguments, sanitized, request.getDefinition(), request.getResource()));
}
Expand Down Expand Up @@ -218,15 +222,22 @@ public void scale(AppScaleRequest appScaleRequest) {
logger.debug(String.format("Scale app: %s to: %s", deploymentId, appScaleRequest.getCount()));
}

ScalableResource scalableResource = this.client.apps().deployments().withName(deploymentId);
if (scalableResource.get() == null) {
scalableResource = this.client.apps().statefulSets().withName(deploymentId);
}
if (scalableResource.get() == null) {
throw new IllegalStateException(String.format("App '%s' is not deployed", deploymentId));
}
scalableResource.scale(appScaleRequest.getCount(), true);
}
try {
ScalableResource<?> scalableResource = this.client.apps().deployments().withName(deploymentId);
if (scalableResource.get() == null) {
scalableResource = this.client.apps().statefulSets().withName(deploymentId);
}
if (scalableResource.get() == null) {
throw new IllegalStateException(String.format("App '%s' is not deployed", deploymentId));
}
scalableResource.scale(appScaleRequest.getCount(), true);
} catch (KubernetesClientException x) {
logger.debug("scale:exception:" + x, x);
throw new IllegalStateException(x);
}


}

@Override
public RuntimeEnvironmentInfo environmentInfo() {
Expand Down Expand Up @@ -364,7 +375,7 @@ protected void createService(AppDeploymentRequest request) {
if (createLoadBalancer == null) {
isCreateLoadBalancer = properties.isCreateLoadBalancer();
} else {
if ("true".equals(createLoadBalancer.toLowerCase())) {
if ("true".equalsIgnoreCase(createLoadBalancer)) {
isCreateLoadBalancer = true;
}
}
Expand All @@ -379,7 +390,7 @@ protected void createService(AppDeploymentRequest request) {

if (createNodePort != null) {
spec.withType("NodePort");
if (!"true".equals(createNodePort.toLowerCase())) {
if (!"true".equalsIgnoreCase(createNodePort)) {
try {
Integer nodePort = Integer.valueOf(createNodePort);
servicePort.setNodePort(nodePort);
Expand Down Expand Up @@ -488,7 +499,7 @@ private Set<ServicePort> addAdditionalServicePorts(String additionalServicePorts
* <p>
* Since 1.8 the annotation method has been removed, and the initContainer API is supported since 1.6
*
* @param podSpec the current pod spec the container is being added to
* @param podSpec the current pod spec the container is being added to
* @param imageName the image name to use in the init container
* @return a container definition with the aforementioned configuration
*/
Expand Down Expand Up @@ -520,7 +531,7 @@ private Container createStatefulSetInitContainer(PodSpec podSpec, String imageNa

private String setIndexProperty(String name) {
return String
.format("echo %s=\"$(expr $HOSTNAME | grep -o \"[[:digit:]]*$\")\" >> "+
.format("echo %s=\"$(expr $HOSTNAME | grep -o \"[[:digit:]]*$\")\" >> " +
"/config/application.properties", name);
}

Expand All @@ -538,62 +549,62 @@ private void deleteAllObjects(String appIdToDelete) {
}

private void deleteService(Map<String, String> labels) {
FilterWatchListDeletable<Service, ServiceList> servicesToDelete =
FilterWatchListDeletable<Service, ServiceList, ServiceResource<Service>> servicesToDelete =
client.services().withLabels(labels);

if (servicesToDelete != null && servicesToDelete.list().getItems() != null) {
boolean servicesDeleted = servicesToDelete.delete();
if (logger.isDebugEnabled()) {
logger.debug(String.format("Service deleted for: %s - %b", labels, servicesDeleted));
}
List<StatusDetails> servicesDeleted = servicesToDelete.delete();
if (logger.isDebugEnabled()) {
logger.debug(String.format("Service deleted for: %s - %s", labels, servicesDeleted));
}
}
}

private void deleteDeployment(Map<String, String> labels) {
FilterWatchListDeletable<Deployment, DeploymentList> deploymentsToDelete =
FilterWatchListDeletable<Deployment, DeploymentList, RollableScalableResource<Deployment>> deploymentsToDelete =
client.apps().deployments().withLabels(labels);

if (deploymentsToDelete != null && deploymentsToDelete.list().getItems() != null) {
boolean deploymentsDeleted = deploymentsToDelete.delete();
if (logger.isDebugEnabled()) {
logger.debug(String.format("Deployment deleted for: %s - %b", labels, deploymentsDeleted));
}
List<StatusDetails> deploymentsDeleted = deploymentsToDelete.delete();
if (logger.isDebugEnabled()) {
logger.debug(String.format("Deployment deleted for: %s - %s", labels, deploymentsDeleted));
}
}
}

private void deleteStatefulSet(Map<String, String> labels) {
FilterWatchListDeletable<StatefulSet, StatefulSetList> ssToDelete =
FilterWatchListDeletable<StatefulSet, StatefulSetList, RollableScalableResource<StatefulSet>> ssToDelete =
client.apps().statefulSets().withLabels(labels);

if (ssToDelete != null && ssToDelete.list().getItems() != null) {
boolean ssDeleted = ssToDelete.delete();
List<StatusDetails> ssDeleted = ssToDelete.delete();
if (logger.isDebugEnabled()) {
logger.debug(String.format("StatefulSet deleted for: %s - %b", labels, ssDeleted));
logger.debug(String.format("StatefulSet deleted for: %s - %s", labels, ssDeleted));
}
}
}

private void deletePod(Map<String, String> labels) {
FilterWatchListDeletable<Pod, PodList> podsToDelete = client.pods()
FilterWatchListDeletable<Pod, PodList, PodResource> podsToDelete = client.pods()
.withLabels(labels);

if (podsToDelete != null && podsToDelete.list().getItems() != null) {
boolean podsDeleted = podsToDelete.delete();
if (logger.isDebugEnabled()) {
logger.debug(String.format("Pod deleted for: %s - %b", labels, podsDeleted));
}
List<StatusDetails> podsDeleted = podsToDelete.delete();
if (logger.isDebugEnabled()) {
logger.debug(String.format("Pod deleted for: %s - %s", labels, podsDeleted));
}
}
}

private void deletePvc(Map<String, String> labels) {
FilterWatchListDeletable<PersistentVolumeClaim, PersistentVolumeClaimList> pvcsToDelete = client.persistentVolumeClaims()
FilterWatchListDeletable<PersistentVolumeClaim, PersistentVolumeClaimList, Resource<PersistentVolumeClaim>> pvcsToDelete = client.persistentVolumeClaims()
.withLabels(labels);

if (pvcsToDelete != null && pvcsToDelete.list().getItems() != null) {
boolean pvcsDeleted = pvcsToDelete.delete();
if (logger.isDebugEnabled()) {
logger.debug(String.format("PVC deleted for: %s - %b", labels, pvcsDeleted));
}
List<StatusDetails> pvcsDeleted = pvcsToDelete.delete();
if (logger.isDebugEnabled()) {
logger.debug(String.format("PVC deleted for: %s - %s", labels, pvcsDeleted));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import io.fabric8.kubernetes.api.model.LocalObjectReference;
import io.fabric8.kubernetes.api.model.PodSpec;
import io.fabric8.kubernetes.api.model.StatusCause;
import io.fabric8.kubernetes.api.model.batch.v1.CronJobList;
import io.fabric8.kubernetes.api.model.StatusDetails;
import io.fabric8.kubernetes.api.model.batch.v1.CronJob;
import io.fabric8.kubernetes.api.model.batch.v1.CronJobBuilder;
import io.fabric8.kubernetes.api.model.batch.v1.CronJobList;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientException;

Expand All @@ -47,6 +48,7 @@
*
* @author Chris Schaefer
* @author Ilayaperumal Gopinathan
* @author Corneil du Plessis
*/
public class KubernetesScheduler extends AbstractKubernetesDeployer implements Scheduler {
protected static final String SPRING_CRONJOB_ID_KEY = "spring-cronjob-id";
Expand Down Expand Up @@ -158,10 +160,10 @@ public void validateScheduleName(ScheduleRequest request) {

@Override
public void unschedule(String scheduleName) {
boolean unscheduled = this.client.batch().v1().cronjobs().withName(scheduleName).delete();
List<StatusDetails> unscheduled = this.client.batch().v1().cronjobs().withName(scheduleName).delete();

if (!unscheduled) {
throw new SchedulerException("Failed to unschedule schedule " + scheduleName + " does not exist.");
if (unscheduled == null || unscheduled.isEmpty()) {
throw new SchedulerException("Failed to unschedule " + scheduleName);
}
}

Expand Down
Loading

0 comments on commit b7398c0

Please sign in to comment.