Skip to content

redesign #906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 4, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.javaoperatorsdk.operator.ReconcilerUtils;
import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceConfiguration;
import io.javaoperatorsdk.operator.api.reconciler.Constants;
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResourceControllerFactory;
import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilter;
import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilters;

Expand Down Expand Up @@ -54,10 +54,6 @@ default List<DependentResourceConfiguration> getDependentResources() {
return Collections.emptyList();
}

default DependentResourceControllerFactory<R> dependentFactory() {
return new DependentResourceControllerFactory<>() {};
}

default Optional<Duration> reconciliationMaxInterval() {
return Optional.of(Duration.ofHours(10L));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Set;

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceConfiguration;
import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilter;

public class DefaultControllerConfiguration<R extends HasMetadata>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.javaoperatorsdk.operator.api.config.dependent;

import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;

public @interface Dependent {

Class<?> resourceType();

Class<? extends DependentResource> type();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.javaoperatorsdk.operator.api.config;
package io.javaoperatorsdk.operator.api.config.dependent;

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;

public interface DependentResourceConfiguration<R, P extends HasMetadata> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.javaoperatorsdk.operator.api.config;
package io.javaoperatorsdk.operator.api.config.dependent;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package io.javaoperatorsdk.operator.api.reconciler.dependent;
package io.javaoperatorsdk.operator.api.config.dependent;

import java.util.Set;

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.javaoperatorsdk.operator.api.config.ConfigurationService;
import io.javaoperatorsdk.operator.api.config.DependentResource;
import io.javaoperatorsdk.operator.api.config.DependentResourceConfiguration;
import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration;
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;
import io.javaoperatorsdk.operator.processing.event.source.AssociatedSecondaryResourceIdentifier;
import io.javaoperatorsdk.operator.processing.event.source.PrimaryResourcesRetriever;
import io.javaoperatorsdk.operator.processing.event.source.informer.InformerConfiguration;

public interface KubernetesDependentResourceConfiguration<R extends HasMetadata, P extends HasMetadata>
extends InformerConfiguration<R, P>, DependentResourceConfiguration<R, P> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.javaoperatorsdk.operator.processing.event.source.informer;
package io.javaoperatorsdk.operator.api.config.informer;

import java.util.Collections;
import java.util.Objects;
Expand All @@ -12,6 +12,7 @@
import io.javaoperatorsdk.operator.processing.event.ResourceID;
import io.javaoperatorsdk.operator.processing.event.source.AssociatedSecondaryResourceIdentifier;
import io.javaoperatorsdk.operator.processing.event.source.PrimaryResourcesRetriever;
import io.javaoperatorsdk.operator.processing.event.source.informer.Mappers;

public interface InformerConfiguration<R extends HasMetadata, P extends HasMetadata>
extends ResourceConfiguration<R> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import java.lang.annotation.Target;
import java.util.concurrent.TimeUnit;

import io.javaoperatorsdk.operator.api.config.Dependent;
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResourceController;
import io.javaoperatorsdk.operator.api.config.dependent.Dependent;
import io.javaoperatorsdk.operator.processing.dependent.DependentResourceController;
import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilter;

@Retention(RetentionPolicy.RUNTIME)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.javaoperatorsdk.operator.api.reconciler.dependent;

import java.util.Optional;

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.javaoperatorsdk.operator.api.config.Utils;
import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext;
import io.javaoperatorsdk.operator.processing.event.source.EventSource;

public interface DependentResource<R, P extends HasMetadata> {
default EventSource initEventSource(EventSourceContext<P> context) {
throw new IllegalStateException("Must be implemented if not automatically provided by the SDK");
}

@SuppressWarnings("unchecked")
default Class<R> resourceType() {
return (Class<R>) Utils.getFirstTypeArgumentFromInterface(getClass());
}

default void delete(R fetched, P primary, Context context) {}

/**
* Computes the desired state of the dependent based on the state provided by the specified
* primary resource.
*
* The default implementation returns {@code empty} which corresponds to the case where the
* associated dependent should never be created by the associated reconciler or that the global
* state of the cluster doesn't allow for the resource to be created at this point.
*
* @param primary the primary resource associated with the reconciliation process
* @param context the {@link Context} associated with the reconciliation process
* @return an instance of the dependent resource matching the desired state specified by the
* primary resource or {@code empty} if the dependent shouldn't be created at this point
* (or ever)
*/
default Optional<R> desired(P primary, Context context) {
return Optional.empty();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should not have a default implementation.

The most common case is like in the WebPage, when all the resources are managed by the operator, IMHO that should be the default approach. If the resource is not managed by us (so not created and not updated) should be probably a feature flag/mode on the resources. Maybe eventually a different type of resource.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow. If we're not creating, nor updating the resource, why would it even be a dependent?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To get input from it, like not sure from nodes or other configurations of the cluster. But something like this happens also in the tomcat example too if remember correctly.

}

/**
* Checks whether the actual resource as fetched from the cluster matches the desired state
* expressed by the specified primary resource.
*
* The default implementation always return {@code true}, which corresponds to the behavior where
* the dependent never needs to be updated after it's been created.
*
* Note that failure to properly implement this method will lead to infinite loops. In particular,
* for typical Kubernetes resource implementations, simply calling
* {@code desired(primary, context).equals(actual)} is not enough because metadata will usually be
* different.
*
* @param actual the current state of the resource as fetched from the cluster
* @param primary the primary resource associated with the reconciliation request
* @param context the {@link Context} associated with the reconciliation request
* @return {@code true} if the actual state of the resource matches the desired state expressed by
* the specified primary resource, {@code false} otherwise
*/
default boolean match(R actual, P primary, Context context) {
return true;
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading