Skip to content

Commit 04891a2

Browse files
committed
Fix: checking for CRD fails in namespaced mode
1 parent 2d676dd commit 04891a2

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

  • src/main/kotlin/eu/openanalytics/shinyproxyoperator

src/main/kotlin/eu/openanalytics/shinyproxyoperator/Operator.kt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import io.fabric8.kubernetes.api.model.apps.ReplicaSetList
3737
import io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress
3838
import io.fabric8.kubernetes.api.model.networking.v1beta1.IngressList
3939
import io.fabric8.kubernetes.client.DefaultKubernetesClient
40+
import io.fabric8.kubernetes.client.KubernetesClientException
4041
import io.fabric8.kubernetes.client.NamespacedKubernetesClient
4142
import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext
4243
import io.fabric8.kubernetes.client.dsl.base.OperationContext
@@ -191,17 +192,26 @@ class Operator(client: NamespacedKubernetesClient? = null,
191192

192193
fun prepare() {
193194
logger.info("Starting ShinyProxy Operator")
194-
if (client.customResourceDefinitions().withName("shinyproxies.openanalytics.eu").get() == null) {
195+
try {
196+
if (client.customResourceDefinitions().withName("shinyproxies.openanalytics.eu").get() == null) {
197+
println()
198+
println()
199+
println("ERROR: the CustomResourceDefinition (CRD) of the Operator does not exist!")
200+
println("The name of the CRD is 'shinyproxies.openanalytics.eu'")
201+
println("Create the CRD first, before starting the operator")
202+
println()
203+
println("Exiting in 10 seconds because of the above error")
204+
Thread.sleep(10000) // sleep 10 seconds to make it easier to find this error by an sysadmin
205+
206+
exitProcess(2)
207+
}
208+
} catch (e: KubernetesClientException) {
195209
println()
196210
println()
197-
println("ERROR: the CustomResourceDefinition (CRD) of the Operator does not exist!")
198-
println("The name of the CRD is 'shinyproxies.openanalytics.eu'")
199-
println("Create the CRD first, before starting the operator")
211+
println("Warning: could not check whether ShinyProxy CRD does not exits.")
212+
println("This is normal when the ServiceAccount of the operator does not have permission to access CRDs (at cluster scope).")
213+
println("If you get an unexpected erorr after this message, make sure that the CRD exists.")
200214
println()
201-
println("Exiting in 10 seconds because of the above error")
202-
Thread.sleep(10000) // sleep 10 seconds to make it easier to find this error by an sysadmin
203-
204-
exitProcess(2)
205215
}
206216

207217
informerFactory.startAllRegisteredInformers()

0 commit comments

Comments
 (0)