Skip to content
Draft
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 @@ -23,6 +23,8 @@
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.api.model.ObjectReferenceBuilder;
import io.fabric8.kubernetes.client.KubernetesClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;

Expand All @@ -37,6 +39,7 @@
* https://github.com/EnMasseProject/enmasse/blob/master/k8s-api/src/main/java/io/enmasse/k8s/api/KubeEventLogger.java
*/
public class EventUtils {
private static final Logger LOG = LoggerFactory.getLogger(EventUtils.class);

public static String generateEventName(
HasMetadata target,
Expand Down Expand Up @@ -125,6 +128,11 @@ public static boolean createOrUpdateEventWithLabels(
@Nullable Duration interval,
@Nullable Predicate<Map<String, String>> dedupePredicate,
@Nullable Map<String, String> labels) {
var namespace = target.getMetadata().getNamespace();
if (isNamespaceMarkedForDeletion(client, namespace)) {
LOG.info("Ignoring event because namespace is marked for deletion");
return true;
}
String eventName =
generateEventName(
target, type, reason, messageKey != null ? messageKey : message, component);
Expand Down Expand Up @@ -213,4 +221,13 @@ private static boolean labelCheck(
|| (existing.getMetadata() != null
&& dedupePredicate.test(existing.getMetadata().getLabels()));
}

private static boolean isNamespaceMarkedForDeletion(KubernetesClient client, String namespace) {
try {
return client.namespaces().withName(namespace).get().isMarkedForDeletion();
} catch (Exception e) {
LOG.warn("Error while checking namespace status", e);
return false;
}
}
}
1 change: 1 addition & 0 deletions helm/flink-kubernetes-operator/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ rules:
- events
- configmaps
- secrets
- namespaces
verbs:
- "*"
{{- if .Values.rbac.nodesRule.create }}
Expand Down