Skip to content

refactor: fix Context is a raw type #1037

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 2 commits into from
Mar 15, 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 @@ -3,5 +3,5 @@
import io.fabric8.kubernetes.api.model.HasMetadata;

public interface ContextInitializer<P extends HasMetadata> {
void initContext(P primary, Context context);
void initContext(P primary, Context<P> context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected R handleUpdate(R actual, R desired, P primary, Context<P> context) {
return res;
}

public Matcher.Result<R> match(R actualResource, P primary, Context context) {
public Matcher.Result<R> match(R actualResource, P primary, Context<P> context) {
return matcher.match(actualResource, primary, context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public R update(R actual, R target, P primary, Context<P> context) {
return prepare(target, primary, "Updating").replace(updatedActual);
}

public Result<R> match(R actualResource, P primary, Context context) {
public Result<R> match(R actualResource, P primary, Context<P> context) {
return matcher.match(actualResource, primary, context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private void updatePostExecutionControlWithReschedule(
}


private PostExecutionControl<R> handleCleanup(R resource, Context context) {
private PostExecutionControl<R> handleCleanup(R resource, Context<R> context) {
log.debug(
"Executing delete for resource: {} with version: {}",
getName(resource),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static class TestKubernetesDependentResource
extends KubernetesDependentResource<Deployment, TestCustomResource> {

@Override
protected Deployment desired(TestCustomResource primary, Context context) {
protected Deployment desired(TestCustomResource primary, Context<TestCustomResource> context) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public Optional<SampleExternalResource> fetchResource(HasMetadata primaryResourc

@Override
public SampleExternalResource create(
SampleExternalResource desired, TestCustomResource primary, Context context) {
SampleExternalResource desired, TestCustomResource primary,
Context<TestCustomResource> context) {
return SampleExternalResource.testResource1();
}

Expand All @@ -122,15 +123,16 @@ public SampleExternalResource update(
SampleExternalResource actual,
SampleExternalResource desired,
TestCustomResource primary,
Context context) {
Context<TestCustomResource> context) {
return SampleExternalResource.testResource1();
}

@Override
public void delete(TestCustomResource primary, Context context) {}
public void delete(TestCustomResource primary, Context<TestCustomResource> context) {}

@Override
protected SampleExternalResource desired(TestCustomResource primary, Context context) {
protected SampleExternalResource desired(TestCustomResource primary,
Context<TestCustomResource> context) {
return SampleExternalResource.testResource1();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public MyController(Consumer<TestCustomResource> consumer) {

@Override
public UpdateControl<TestCustomResource> reconcile(
TestCustomResource resource, Context context) {
TestCustomResource resource, Context<TestCustomResource> context) {

LOGGER.info("Received event on: {}", resource);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class DuplicateCRController implements Reconciler<TestCustomResource> {

@Override
public UpdateControl<TestCustomResource> reconcile(TestCustomResource resource,
Context context) {
Context<TestCustomResource> context) {
return UpdateControl.noUpdate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public TestCustomReconciler(KubernetesClient kubernetesClient, boolean updateSta

@Override
public DeleteControl cleanup(
TestCustomResource resource, Context context) {
TestCustomResource resource, Context<TestCustomResource> context) {
Boolean delete =
kubernetesClient
.configMaps()
Expand All @@ -59,7 +59,7 @@ public DeleteControl cleanup(

@Override
public UpdateControl<TestCustomResource> reconcile(
TestCustomResource resource, Context context) {
TestCustomResource resource, Context<TestCustomResource> context) {
if (!resource.getMetadata().getFinalizers().contains(FINALIZER_NAME)) {
throw new IllegalStateException("Finalizer is not present.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class TestCustomReconcilerOtherV1 implements Reconciler<TestCustomResourc

@Override
public UpdateControl<TestCustomResourceOtherV1> reconcile(TestCustomResourceOtherV1 resource,
Context context) {
Context<TestCustomResourceOtherV1> context) {
return UpdateControl.noUpdate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ private static class OneDepReconciler implements Reconciler<ConfigMap> {
public static final String CONFIGURED_NS = "foo";

@Override
public UpdateControl<ConfigMap> reconcile(ConfigMap resource, Context context) {
public UpdateControl<ConfigMap> reconcile(ConfigMap resource, Context<ConfigMap> context) {
return null;
}
}

private static class NoDepReconciler implements Reconciler<ConfigMap> {

@Override
public UpdateControl<ConfigMap> reconcile(ConfigMap resource, Context context) {
public UpdateControl<ConfigMap> reconcile(ConfigMap resource, Context<ConfigMap> context) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static class TestCustomFinalizerReconciler

@Override
public UpdateControl<TestCustomFinalizerReconciler.InnerCustomResource> reconcile(
InnerCustomResource resource, Context context) {
InnerCustomResource resource, Context<InnerCustomResource> context) {
return null;
}

Expand All @@ -123,7 +123,7 @@ static class NotAutomaticallyCreated implements Reconciler<TestCustomResource> {

@Override
public UpdateControl<TestCustomResource> reconcile(
TestCustomResource resource, Context context) {
TestCustomResource resource, Context<TestCustomResource> context) {
return null;
}
}
Expand All @@ -133,7 +133,7 @@ static class TestCustomReconciler implements Reconciler<TestCustomResource> {

@Override
public UpdateControl<TestCustomResource> reconcile(
TestCustomResource resource, Context context) {
TestCustomResource resource, Context<TestCustomResource> context) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public class CreateUpdateEventFilterTestReconciler

@Override
public UpdateControl<CreateUpdateEventFilterTestCustomResource> reconcile(
CreateUpdateEventFilterTestCustomResource resource, Context context) {
CreateUpdateEventFilterTestCustomResource resource,
Context<CreateUpdateEventFilterTestCustomResource> context) {
numberOfExecutions.incrementAndGet();

ConfigMap configMap =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class CustomFilteringTestReconciler implements Reconciler<CustomFiltering

@Override
public UpdateControl<CustomFilteringTestResource> reconcile(CustomFilteringTestResource resource,
Context context) {
Context<CustomFilteringTestResource> context) {
numberOfExecutions.incrementAndGet();
return UpdateControl.noUpdate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class DeploymentReconciler

@Override
public UpdateControl<Deployment> reconcile(
Deployment resource, Context context) {
Deployment resource, Context<Deployment> context) {

log.info("Reconcile deployment: {}", resource);
numberOfExecutions.incrementAndGet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class DoubleUpdateTestCustomReconciler

@Override
public UpdateControl<DoubleUpdateTestCustomResource> reconcile(
DoubleUpdateTestCustomResource resource, Context context) {
DoubleUpdateTestCustomResource resource, Context<DoubleUpdateTestCustomResource> context) {
numberOfExecutions.addAndGet(1);

log.info("Value: " + resource.getSpec().getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class EventSourceTestCustomReconciler

@Override
public UpdateControl<EventSourceTestCustomResource> reconcile(
EventSourceTestCustomResource resource, Context context) {
EventSourceTestCustomResource resource, Context<EventSourceTestCustomResource> context) {

numberOfExecutions.addAndGet(1);
ensureStatusExists(resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public List<EventSource> prepareEventSources(

@Override
public UpdateControl<InformerEventSourceTestCustomResource> reconcile(
InformerEventSourceTestCustomResource resource, Context context) {
InformerEventSourceTestCustomResource resource,
Context<InformerEventSourceTestCustomResource> context) {
numberOfExecutions.incrementAndGet();

resource.setStatus(new InformerEventSourceTestCustomResourceStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class MaxIntervalTestReconciler

@Override
public UpdateControl<MaxIntervalTestCustomResource> reconcile(
MaxIntervalTestCustomResource resource, Context context) {
MaxIntervalTestCustomResource resource, Context<MaxIntervalTestCustomResource> context) {
numberOfExecutions.addAndGet(1);
return UpdateControl.noUpdate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public class MultiVersionCRDTestReconciler1

@Override
public UpdateControl<MultiVersionCRDTestCustomResource1> reconcile(
MultiVersionCRDTestCustomResource1 resource, Context context) {
MultiVersionCRDTestCustomResource1 resource,
Context<MultiVersionCRDTestCustomResource1> context) {
log.info("Reconcile MultiVersionCRDTestCustomResource1: {}",
resource.getMetadata().getName());
resource.getStatus().setValue1(resource.getStatus().getValue1() + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class MultiVersionCRDTestReconciler2

@Override
public UpdateControl<MultiVersionCRDTestCustomResource2> reconcile(
MultiVersionCRDTestCustomResource2 resource, Context context) {
MultiVersionCRDTestCustomResource2 resource,
Context<MultiVersionCRDTestCustomResource2> context) {
log.info("Reconcile MultiVersionCRDTestCustomResource2: {}",
resource.getMetadata().getName());
resource.getStatus().setValue1(resource.getStatus().getValue1() + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ObservedGenerationTestReconciler

@Override
public UpdateControl<ObservedGenerationTestCustomResource> reconcile(
ObservedGenerationTestCustomResource resource, Context context) {
ObservedGenerationTestCustomResource resource,
Context<ObservedGenerationTestCustomResource> context) {
log.info("Reconcile ObservedGenerationTestCustomResource: {}",
resource.getMetadata().getName());
return UpdateControl.updateStatus(resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void setKubernetesClient(KubernetesClient kubernetesClient) {

@Override
public DeleteControl cleanup(
TestCustomResource resource, Context context) {
TestCustomResource resource, Context<TestCustomResource> context) {
Boolean delete =
kubernetesClient
.configMaps()
Expand All @@ -82,7 +82,7 @@ public DeleteControl cleanup(

@Override
public UpdateControl<TestCustomResource> reconcile(
TestCustomResource resource, Context context) {
TestCustomResource resource, Context<TestCustomResource> context) {
numberOfExecutions.addAndGet(1);
if (!resource.getMetadata().getFinalizers().contains(FINALIZER_NAME)) {
throw new IllegalStateException("Finalizer is not present.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public List<EventSource> prepareEventSources(

@Override
public UpdateControl<StandaloneDependentTestCustomResource> reconcile(
StandaloneDependentTestCustomResource primary, Context context) {
StandaloneDependentTestCustomResource primary,
Context<StandaloneDependentTestCustomResource> context) {
deploymentDependent.reconcile(primary, context);
Optional<Deployment> deployment = deploymentDependent.getResource(primary);
if (deployment.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class SubResourceTestCustomReconciler

@Override
public UpdateControl<SubResourceTestCustomResource> reconcile(
SubResourceTestCustomResource resource, Context context) {
SubResourceTestCustomResource resource, Context<SubResourceTestCustomResource> context) {
numberOfExecutions.addAndGet(1);
if (!resource.getMetadata().getFinalizers().contains(FINALIZER_NAME)) {
throw new IllegalStateException("Finalizer is not present.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private static String encode(String value) {
}

@Override
protected Secret desired(MySQLSchema schema, Context context) {
protected Secret desired(MySQLSchema schema, Context<MySQLSchema> context) {
final var password = RandomStringUtils
.randomAlphanumeric(16); // NOSONAR: we don't need cryptographically-strong randomness here
final var name = schema.getMetadata().getName();
Expand All @@ -49,7 +49,7 @@ private String getSecretName(String name) {
}

@Override
public Result<Secret> match(Secret actual, MySQLSchema primary, Context context) {
public Result<Secret> match(Secret actual, MySQLSchema primary, Context<MySQLSchema> context) {
final var desiredSecretName = getSecretName(primary.getMetadata().getName());
return Result.nonComputed(actual.getMetadata().getName().equals(desiredSecretName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private static String tomcatImage(Tomcat tomcat) {
}

@Override
protected Deployment desired(Tomcat tomcat, Context context) {
protected Deployment desired(Tomcat tomcat, Context<Tomcat> context) {
Deployment deployment =
ReconcilerUtils.loadYaml(Deployment.class, getClass(), "deployment.yaml");
final ObjectMeta tomcatMetadata = tomcat.getMetadata();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ServiceDependentResource extends KubernetesDependentResource<Servic
implements Creator<Service, Tomcat>, Updater<Service, Tomcat> {

@Override
protected Service desired(Tomcat tomcat, Context context) {
protected Service desired(Tomcat tomcat, Context<Tomcat> context) {
final ObjectMeta tomcatMetadata = tomcat.getMetadata();
return new ServiceBuilder(ReconcilerUtils.loadYaml(Service.class, getClass(), "service.yaml"))
.editMetadata()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public List<EventSource> prepareEventSources(EventSourceContext<WebPage> context
}

@Override
public UpdateControl<WebPage> reconcile(WebPage webPage, Context context) {
public UpdateControl<WebPage> reconcile(WebPage webPage, Context<WebPage> context) {
if (webPage.getSpec().getHtml().contains("error")) {
// special case just to showcase error if doing a demo
throw new ErrorSimulationException("Simulating error");
Expand Down Expand Up @@ -166,7 +166,7 @@ private class ConfigMapDependentResource
PrimaryToSecondaryMapper<WebPage> {

@Override
protected ConfigMap desired(WebPage webPage, Context context) {
protected ConfigMap desired(WebPage webPage, Context<WebPage> context) {
Map<String, String> data = new HashMap<>();
data.put("index.html", webPage.getSpec().getHtml());
return new ConfigMapBuilder()
Expand All @@ -180,7 +180,8 @@ protected ConfigMap desired(WebPage webPage, Context context) {
}

@Override
public ConfigMap update(ConfigMap actual, ConfigMap target, WebPage primary, Context context) {
public ConfigMap update(ConfigMap actual, ConfigMap target, WebPage primary,
Context<WebPage> context) {
var res = super.update(actual, target, primary, context);
var ns = actual.getMetadata().getNamespace();
log.info("Restarting pods because HTML has changed in {}", ns);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ public CustomServiceReconciler(KubernetesClient kubernetesClient) {
}

@Override
public DeleteControl cleanup(CustomService resource, Context context) {
public DeleteControl cleanup(CustomService resource, Context<CustomService> context) {
log.info("Cleaning up for: {}", resource.getMetadata().getName());
return Reconciler.super.cleanup(resource, context);
}

@Override
public UpdateControl<CustomService> reconcile(
CustomService resource, Context context) {
CustomService resource, Context<CustomService> context) {
log.info("Reconciling: {}", resource.getMetadata().getName());

ServicePort servicePort = new ServicePort();
Expand Down