forked from eclipse-jkube/jkube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (jkube-kit/config/service) : Detect and warn user if Ingress con…
…troller not available (eclipse-jkube#1478) + Add IngressControllerDetectorService which will try to detect whether any Ingress Controller is present in the cluster before applying Ingress. At the moment, it supports detecting these Ingress Controllers: - Contour - Ingress Kong - Ingress Nginx - OpenShift Ingress Controller This is based on Kind Ingress guide, we can also expand it if we want to. Signed-off-by: Rohan Kumar <rohaan@redhat.com>
- Loading branch information
1 parent
7777376
commit 841dbbc
Showing
21 changed files
with
1,077 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/IngressControllerDetector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.kit.common; | ||
|
||
import io.fabric8.kubernetes.client.KubernetesClientException; | ||
|
||
public interface IngressControllerDetector { | ||
/** | ||
* Returns boolean value whether Ingress Controller is running in Kubernetes Cluster | ||
* @return true if Ingress Controller is present, false otherwise | ||
*/ | ||
default boolean isDetected() { | ||
try { | ||
return hasIngressClass() && isIngressControllerReady(); | ||
} catch (KubernetesClientException exception) { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Returns whether IngressClass for corresponding controller is installed in cluster | ||
* | ||
* @return true if IngressClass is installed, false otherwise | ||
*/ | ||
boolean hasIngressClass(); | ||
|
||
/** | ||
* Is Ingress Controller pod running in the cluster | ||
* | ||
* @return boolean value if Ingress Controller is running, false otherwise. | ||
*/ | ||
boolean isIngressControllerReady(); | ||
|
||
/** | ||
* Returns boolean value whether currently logged user has got enough permissions to | ||
* check for current IngressController implementation | ||
* @return true if it has permissions, false otherwise | ||
*/ | ||
boolean hasPermissions(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
.../eclipse/jkube/kit/config/service/ingresscontroller/ContourIngressControllerDetector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.kit.config.service.ingresscontroller; | ||
|
||
import io.fabric8.kubernetes.api.model.authorization.v1.SelfSubjectAccessReview; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import org.eclipse.jkube.kit.common.IngressControllerDetector; | ||
import org.eclipse.jkube.kit.common.util.KubernetesHelper; | ||
|
||
import static org.eclipse.jkube.kit.common.util.KubernetesHelper.createNewSelfSubjectAccessReview; | ||
import static org.eclipse.jkube.kit.common.util.KubernetesHelper.hasAccessForAction; | ||
|
||
public class ContourIngressControllerDetector implements IngressControllerDetector { | ||
private final KubernetesClient client; | ||
private static final String INGRESS_CONTOUR_NAMESPACE = "projectcontour"; | ||
|
||
public ContourIngressControllerDetector(KubernetesClient client) { | ||
this.client = client; | ||
} | ||
|
||
@Override | ||
public boolean hasIngressClass() { | ||
return !client.network().v1().ingressClasses() | ||
.withLabel("app.kubernetes.io/name", "contour") | ||
.list() | ||
.getItems() | ||
.isEmpty(); | ||
} | ||
|
||
@Override | ||
public boolean isIngressControllerReady() { | ||
return isComponentReady("envoy") && | ||
isComponentReady("contour"); | ||
} | ||
|
||
@Override | ||
public boolean hasPermissions() { | ||
SelfSubjectAccessReview listIngressClassAccess = createNewSelfSubjectAccessReview("networking.k8s.io", "ingressclasses", null, "list"); | ||
SelfSubjectAccessReview listPodsAnyNamespaceAccess = createNewSelfSubjectAccessReview(null, "pods", INGRESS_CONTOUR_NAMESPACE, "list"); | ||
|
||
return hasAccessForAction(client, listIngressClassAccess) && hasAccessForAction(client, listPodsAnyNamespaceAccess); | ||
} | ||
|
||
private boolean isComponentReady(String componentName) { | ||
return client.pods() | ||
.inNamespace(INGRESS_CONTOUR_NAMESPACE) | ||
.withLabel("app.kubernetes.io/component", componentName) | ||
.list() | ||
.getItems() | ||
.stream() | ||
.anyMatch(KubernetesHelper::isPodReady); | ||
} | ||
} |
Oops, something went wrong.