Skip to content

Commit

Permalink
chore: autoformat
Browse files Browse the repository at this point in the history
  • Loading branch information
secondsun committed Dec 9, 2021
1 parent 7fdacac commit e1300c8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
28 changes: 16 additions & 12 deletions source/rhoas/src/main/java/com/openshift/cloud/RHOASOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,32 @@ public int run(String... args) throws Exception {

private void cleanupDeletedLegacyFinalizers() {

//Clean up legacy Finalizers for deleted resources
//We removed finalizers for several types, but didn't correctly remove them from instanced resources in k8s
//if those resources were deleted then we need to remove the finalizers here outside of the normal reconsiliation loop
// Clean up legacy Finalizers for deleted resources
// We removed finalizers for several types, but didn't correctly remove them from instanced
// resources in k8s
// if those resources were deleted then we need to remove the finalizers here outside of the
// normal reconsiliation loop
var srcs = new ArrayList<>(client.serviceRegistryConnection().list().getItems());
srcs.removeIf(item -> !item.isMarkedForDeletion());
srcs.forEach(src->src.removeFinalizer("serviceregistryconnections.rhoas.redhat.com/finalizer"));
srcs.forEach(src->client.serviceRegistryConnection().createOrReplace(src));
srcs.forEach(
src -> src.removeFinalizer("serviceregistryconnections.rhoas.redhat.com/finalizer"));
srcs.forEach(src -> client.serviceRegistryConnection().createOrReplace(src));

var csrs = new ArrayList<>(client.cloudServicesRequest().list().getItems());
var csrs = new ArrayList<>(client.cloudServicesRequest().list().getItems());
csrs.removeIf(item -> !item.isMarkedForDeletion());
csrs.forEach(csr->csr.removeFinalizer("cloudservicesrequests.rhoas.redhat.com/finalizer"));
csrs.forEach(csr->client.cloudServicesRequest().createOrReplace(csr));
csrs.forEach(csr -> csr.removeFinalizer("cloudservicesrequests.rhoas.redhat.com/finalizer"));
csrs.forEach(csr -> client.cloudServicesRequest().createOrReplace(csr));

var akcs = new ArrayList<>(client.kafkaConnection().list().getItems());
akcs.removeIf(item -> !item.isMarkedForDeletion());
akcs.forEach(akc->akc.removeFinalizer("kafkaconnections.rhoas.redhat.com/finalizer"));
akcs.forEach(akc->client.kafkaConnection().createOrReplace(akc));
akcs.forEach(akc -> akc.removeFinalizer("kafkaconnections.rhoas.redhat.com/finalizer"));
akcs.forEach(akc -> client.kafkaConnection().createOrReplace(akc));

var csars = new ArrayList<>(client.cloudServiceAccountRequest().list().getItems());
csars.removeIf(item -> !item.isMarkedForDeletion());
csars.forEach(csar->csar.removeFinalizer("cloudserviceaccountrequests.rhoas.redhat.com/finalizer"));
csars.forEach(csar->client.cloudServiceAccountRequest().createOrReplace(csar));
csars.forEach(
csar -> csar.removeFinalizer("cloudserviceaccountrequests.rhoas.redhat.com/finalizer"));
csars.forEach(csar -> client.cloudServiceAccountRequest().createOrReplace(csar));


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,14 @@ public MixedOperation<CloudServiceAccountRequest, CloudServiceAccountRequestList
KubernetesDeserializer.registerCustomKind(getApiVersion(CloudServiceAccountRequest.class),
csarCrd.getKind(), CloudServiceAccountRequest.class);

return client.resources(CloudServiceAccountRequest.class, CloudServiceAccountRequestList.class);
return client.resources(CloudServiceAccountRequest.class, CloudServiceAccountRequestList.class);
}

public MixedOperation<ServiceRegistryConnection, ServiceRegistryConnectionList, Resource<ServiceRegistryConnection>> serviceRegistryConnection() {
KubernetesDeserializer.registerCustomKind(getApiVersion(ServiceRegistryConnection.class),
srcCrd.getKind(), ServiceRegistryConnection.class);

return client.resources(ServiceRegistryConnection.class, ServiceRegistryConnectionList.class);
return client.resources(ServiceRegistryConnection.class, ServiceRegistryConnectionList.class);
}

private CustomResourceDefinition initCloudServiceAccountRequestCRDAndClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ public abstract class AbstractCloudServicesController<T extends CustomResource>
public static final String COMPONENT_LABEL_KEY = "app.kubernetes.io/component";
public static final String MANAGED_BY_LABEL_KEY = "app.kubernetes.io/managed-by";

public static final List<String> LEGACY_FINALIZERS = List.of(
"cloudservicesrequests.rhoas.redhat.com/finalizer",
"cloudserviceaccountrequests.rhoas.redhat.com/finalizer",
"kafkaconnections.rhoas.redhat.com/finalizer",
"serviceregistryconnections.rhoas.redhat.com/finalizer"
);
public static final List<String> LEGACY_FINALIZERS =
List.of("cloudservicesrequests.rhoas.redhat.com/finalizer",
"cloudserviceaccountrequests.rhoas.redhat.com/finalizer",
"kafkaconnections.rhoas.redhat.com/finalizer",
"serviceregistryconnections.rhoas.redhat.com/finalizer");

public static final String COMPONENT_LABEL_VALUE = "external-service";
public static final String MANAGED_BY_LABEL_VALUE = "rhoas";
Expand Down Expand Up @@ -110,21 +109,23 @@ private boolean requiresLabelUpdate(T resource) {
}

/**
* We used to have finalizers for some classes, but these were removed.
* This method checks to see if a legacy finalizer is attatched and removes it.
* We used to have finalizers for some classes, but these were removed. This method checks to see
* if a legacy finalizer is attatched and removes it.
*
* @param resource
* @return if a finalizer should be removed
*/
private boolean shouldRemoveFinalizer(T resource) {
var finalizers = resource.getMetadata().getFinalizers();
var toRemove = finalizers.stream().filter(finalizer -> LEGACY_FINALIZERS.contains(finalizer)).collect(Collectors.toList());
var toRemove = finalizers.stream().filter(finalizer -> LEGACY_FINALIZERS.contains(finalizer))
.collect(Collectors.toList());
return toRemove.size() > 0;
}

private void removeFinalizer(T resource) {
var finalizers = resource.getMetadata().getFinalizers();
var toRemove = finalizers.stream().filter(finalizer -> LEGACY_FINALIZERS.contains(finalizer)).collect(Collectors.toList());
var toRemove = finalizers.stream().filter(finalizer -> LEGACY_FINALIZERS.contains(finalizer))
.collect(Collectors.toList());
LOG.warning("Found legacy Finalizers " + toRemove);
toRemove.forEach(finalizer -> resource.removeFinalizer(finalizer));
}
Expand Down

0 comments on commit e1300c8

Please sign in to comment.