Skip to content
Merged
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
13 changes: 3 additions & 10 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
pull_request:
paths-ignore:
- 'docs/**'
branches: [ main, v1, v2, next ]
branches: [ main, v1, v2, v3, next ]
workflow_dispatch:
jobs:
check_format_and_unit_tests:
Expand All @@ -35,14 +35,7 @@ jobs:
strategy:
matrix:
java: [ 11, 17 ]
kubernetes: ['v1.20.15','v1.21.12', 'v1.22.9', 'v1.23.6', 'v1.24.0' ]
exclude:
- java: 11
kubernetes: 'v1.20.15'
- java: 11
kubernetes: 'v1.21.12'
- java: 11
kubernetes: 'v1.22.9'
kubernetes: [ 'v1.22.13', 'v1.23.10', 'v1.24.4', 'v1.25.0' ]
steps:
- uses: actions/checkout@v3
- name: Set up Java and Maven
Expand All @@ -54,7 +47,7 @@ jobs:
- name: Set up Minikube
uses: manusa/[email protected]
with:
minikube version: 'v1.25.2'
minikube version: 'v1.26.0'
kubernetes version: ${{ matrix.kubernetes }}
driver: 'docker'
- name: Run integration tests
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ jobs:
ref: "v2"
- uses: actions/checkout@v3
if: ${{ startsWith(github.event.release.tag_name, 'v3.') }}
with:
ref: "v3"
- uses: actions/checkout@v3
if: ${{ startsWith(github.event.release.tag_name, 'v4.') }}
- name: Set up Java and Maven
uses: actions/setup-java@v3
with:
Expand All @@ -29,6 +33,11 @@ jobs:
run: ./mvnw ${MAVEN_ARGS} versions:set -DnewVersion="${RELEASE_VERSION:1}" versions:commit
env:
RELEASE_VERSION: ${{ github.event.release.tag_name }}
- name: change version to release version for bom module
working-directory: ./operator-framework-bom
run: ./mvnw ${MAVEN_ARGS} versions:set -DnewVersion="${RELEASE_VERSION:1}" versions:commit
env:
RELEASE_VERSION: ${{ github.event.release.tag_name }}
- name: Release Maven package
uses: samuelmeuli/action-maven-publish@v1
with:
Expand All @@ -54,6 +63,10 @@ jobs:
ref: "v2"
- uses: actions/checkout@v3
if: ${{ startsWith(github.event.release.tag_name, 'v3.') }}
with:
ref: "v3"
- uses: actions/checkout@v3
if: ${{ startsWith(github.event.release.tag_name, 'v4.') }}
- name: Set up Java and Maven
uses: actions/setup-java@v3
with:
Expand Down Expand Up @@ -86,4 +99,10 @@ jobs:
if: ${{ startsWith(github.event.release.tag_name, 'v3.' ) }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: "v3"
- name: Push changes v4
uses: ad-m/github-push-action@master
if: ${{ startsWith(github.event.release.tag_name, 'v4.' ) }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

2 changes: 1 addition & 1 deletion .github/workflows/snapshot-releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
push:
paths-ignore:
- 'docs/**'
branches: [ main, v1, v2, next ]
branches: [ main, v1, v2, v3, next ]
workflow_dispatch:
jobs:
test:
Expand Down
4 changes: 2 additions & 2 deletions docs/documentation/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ the events. This means that should the leader change for any reason, for example
crashed, the other instances are already warmed up and ready to pick up where the previous
leader left off should one of them become elected leader.

See sample configuration in the [E2E test](https://github.com/java-operator-sdk/java-operator-sdk/blob/144947d89323f1c65de6e86bd8b9a6a8ffe714ff/sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestOperator.java#L26-L30)
See sample configuration in the [E2E test](https://github.com/java-operator-sdk/java-operator-sdk/blob/8865302ac0346ee31f2d7b348997ec2913d5922b/sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestOperator.java#L21-L23)
.

## Monitoring with Micrometer
Expand Down Expand Up @@ -725,4 +725,4 @@ with a `mycrs` plural form will result in 2 files:

**NOTE:**
> Quarkus users using the `quarkus-operator-sdk` extension do not need to add any extra dependency
> to get their CRD generated as this is handled by the extension itself.
> to get their CRD generated as this is handled by the extension itself.
2 changes: 1 addition & 1 deletion micrometer-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>java-operator-sdk</artifactId>
<groupId>io.javaoperatorsdk</groupId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
76 changes: 75 additions & 1 deletion operator-framework-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>io.javaoperatorsdk</groupId>
<artifactId>operator-framework-bom</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<name>Operator SDK - Bill of Materials</name>
<packaging>pom</packaging>

Expand Down Expand Up @@ -34,6 +34,80 @@
</dependencies>
</dependencyManagement>

<properties>
<nexus-staging-maven-plugin.version>1.6.13</nexus-staging-maven-plugin.version>
<maven-gpg-plugin.version>3.0.1</maven-gpg-plugin.version>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.4.1</maven-javadoc-plugin.version>
</properties>

<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven-gpg-plugin.version}</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
<configuration>
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>${nexus-staging-maven-plugin.version}</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
Expand Down
2 changes: 1 addition & 1 deletion operator-framework-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.javaoperatorsdk</groupId>
<artifactId>java-operator-sdk</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.javaoperatorsdk.operator;

import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -10,7 +10,6 @@
import io.fabric8.kubernetes.client.extended.leaderelection.LeaderCallbacks;
import io.fabric8.kubernetes.client.extended.leaderelection.LeaderElectionConfig;
import io.fabric8.kubernetes.client.extended.leaderelection.LeaderElector;
import io.fabric8.kubernetes.client.extended.leaderelection.LeaderElectorBuilder;
import io.fabric8.kubernetes.client.extended.leaderelection.resourcelock.LeaseLock;
import io.fabric8.kubernetes.client.extended.leaderelection.resourcelock.Lock;
import io.javaoperatorsdk.operator.api.config.ConfigurationServiceProvider;
Expand All @@ -23,7 +22,7 @@ public class LeaderElectionManager {
private LeaderElector leaderElector = null;
private final ControllerManager controllerManager;
private String identity;
private CompletableFuture<?> leaderElectionFuture;
private Future<?> leaderElectionFuture;

public LeaderElectionManager(ControllerManager controllerManager) {
this.controllerManager = controllerManager;
Expand All @@ -33,11 +32,9 @@ public void init(LeaderElectionConfiguration config, KubernetesClient client) {
this.identity = identity(config);
Lock lock = new LeaseLock(config.getLeaseNamespace(), config.getLeaseName(), identity);
// releaseOnCancel is not used in the underlying implementation
leaderElector = new LeaderElectorBuilder(client,
ConfigurationServiceProvider.instance().getExecutorService())
.withConfig(
new LeaderElectionConfig(lock, config.getLeaseDuration(), config.getRenewDeadline(),
config.getRetryPeriod(), leaderCallbacks(), true, config.getLeaseName()))
leaderElector = client.leaderElector().withConfig(
new LeaderElectionConfig(lock, config.getLeaseDuration(), config.getRenewDeadline(),
config.getRetryPeriod(), leaderCallbacks(), true, config.getLeaseName()))
.build();
}

Expand Down Expand Up @@ -73,7 +70,8 @@ private String identity(LeaderElectionConfiguration config) {

public void start() {
if (isLeaderElectionEnabled()) {
leaderElectionFuture = leaderElector.start();
leaderElectionFuture =
ConfigurationServiceProvider.instance().getExecutorService().submit(leaderElector::run);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import org.slf4j.LoggerFactory;

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.Version;
import io.javaoperatorsdk.operator.api.config.*;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
Expand Down Expand Up @@ -59,7 +59,7 @@ public Operator(KubernetesClient client, Consumer<ConfigurationServiceOverrider>
*/
public Operator(KubernetesClient kubernetesClient, ConfigurationService configurationService) {
this.kubernetesClient =
kubernetesClient != null ? kubernetesClient : new KubernetesClientBuilder().build();
kubernetesClient != null ? kubernetesClient : new DefaultKubernetesClient();
configurationService.getLeaderElectionConfiguration()
.ifPresent(c -> leaderElectionManager.init(c, this.kubernetesClient));
ConfigurationServiceProvider.set(configurationService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ public static String getResourceTypeNameWithVersion(Class<? extends HasMetadata>
return getResourceTypeName(resourceClass) + "/" + version;
}

public static String getResourceTypeName(
Class<? extends HasMetadata> resourceClass) {
final var group = HasMetadata.getGroup(resourceClass);
final var plural = HasMetadata.getPlural(resourceClass);
return (group == null || group.isEmpty()) ? plural : plural + "." + group;
public static String getResourceTypeName(Class<? extends HasMetadata> resourceClass) {
return HasMetadata.getFullResourceName(resourceClass);
}

public static String getDefaultFinalizerName(Class<? extends HasMetadata> resourceClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class WorkflowReconcileExecutor<P extends HasMetadata> {
new ConcurrentHashMap<>();

private final Set<DependentResourceNode> markedForDelete = ConcurrentHashMap.newKeySet();
private final Set<DependentResourceNode> deleteConditionNotMet = ConcurrentHashMap.newKeySet();
private final Set<DependentResourceNode> deletePostConditionNotMet =
ConcurrentHashMap.newKeySet();
// used to remember reconciled (not deleted or errored) dependents
private final Set<DependentResourceNode> reconciled = ConcurrentHashMap.newKeySet();
private final Map<DependentResource, ReconcileResult> reconcileResults =
Expand Down Expand Up @@ -99,7 +100,7 @@ private synchronized <R> void handleReconcile(DependentResourceNode<R, P> depend
}
}

private void handleDelete(DependentResourceNode dependentResourceNode) {
private synchronized void handleDelete(DependentResourceNode dependentResourceNode) {
log.debug("Submitting for delete: {}", dependentResourceNode);

if (alreadyVisited(dependentResourceNode)
Expand All @@ -119,7 +120,7 @@ private void handleDelete(DependentResourceNode dependentResourceNode) {
private boolean allDependentsDeletedAlready(DependentResourceNode<?, P> dependentResourceNode) {
var dependents = dependentResourceNode.getParents();
return dependents.stream().allMatch(d -> alreadyVisited.contains(d) && !notReady.contains(d)
&& !exceptionsDuringExecution.containsKey(d) && !deleteConditionNotMet.contains(d));
&& !exceptionsDuringExecution.containsKey(d) && !deletePostConditionNotMet.contains(d));
}


Expand Down Expand Up @@ -207,16 +208,17 @@ public void run() {
&& !(dependentResource instanceof GarbageCollected)) {
((Deleter<P>) dependentResourceNode.getDependentResource()).delete(primary, context);
}
alreadyVisited.add(dependentResourceNode);
boolean deletePostConditionMet =
deletePostCondition.map(c -> c.isMet(primary,
dependentResourceNode.getDependentResource().getSecondaryResource(primary)
.orElse(null),
context)).orElse(true);
if (deletePostConditionMet) {
alreadyVisited.add(dependentResourceNode);
handleDependentDeleted(dependentResourceNode);
} else {
deleteConditionNotMet.add(dependentResourceNode);
deletePostConditionNotMet.add(dependentResourceNode);
alreadyVisited.add(dependentResourceNode);
}
} catch (RuntimeException e) {
handleExceptionInExecutor(dependentResourceNode, e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package io.javaoperatorsdk.operator.processing.event;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -10,6 +14,7 @@
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.kubernetes.client.dsl.internal.HasMetadataOperationsImpl;
import io.fabric8.kubernetes.client.utils.Serialization;
import io.javaoperatorsdk.operator.OperatorException;
import io.javaoperatorsdk.operator.api.ObservedGenerationAware;
import io.javaoperatorsdk.operator.api.config.ConfigurationServiceProvider;
Expand Down Expand Up @@ -367,9 +372,9 @@ public R updateResource(R resource) {
resource.getMetadata().getResourceVersion());
return resourceOperation
.inNamespace(resource.getMetadata().getNamespace())
.resource(resource)
.withName(getName(resource))
.lockResourceVersion(resource.getMetadata().getResourceVersion())
.replace();
.replace(resource);
}

@SuppressWarnings({"rawtypes", "unchecked"})
Expand All @@ -388,11 +393,15 @@ public R patchStatus(R resource, R originalResource) {
// don't do optimistic locking on patch
originalResource.getMetadata().setResourceVersion(null);
resource.getMetadata().setResourceVersion(null);
try {
try (var bis = new ByteArrayInputStream(
Serialization.asJson(originalResource).getBytes(StandardCharsets.UTF_8))) {
return resourceOperation
.inNamespace(resource.getMetadata().getNamespace())
.resource(originalResource)
// will be simplified in fabric8 v6
.load(bis)
.editStatus(r -> resource);
} catch (IOException e) {
throw new IllegalStateException(e);
} finally {
// restore initial resource version
originalResource.getMetadata().setResourceVersion(resourceVersion);
Expand Down
Loading