7070import io .fabric8 .kubernetes .client .ConfigBuilder ;
7171import io .fabric8 .kubernetes .client .DefaultKubernetesClient ;
7272import io .fabric8 .kubernetes .client .KubernetesClient ;
73+ import io .fabric8 .kubernetes .client .KubernetesClientException ;
7374import io .fabric8 .kubernetes .client .dsl .LogWatch ;
7475import io .fabric8 .kubernetes .client .dsl .NonNamespaceOperation ;
7576import io .fabric8 .kubernetes .client .dsl .Resource ;
@@ -389,11 +390,20 @@ private LocalDateTime getEventTime(Event event) {
389390 }
390391
391392 private void parseKubernetesEvents (Proxy proxy , Container container , Pod pod ) {
392- List <Event > events = kubeClient .v1 ().events ().withInvolvedObject (new ObjectReferenceBuilder ()
393- .withKind ("Pod" )
394- .withName (pod .getMetadata ().getName ())
395- .withNamespace (pod .getMetadata ().getNamespace ())
396- .build ()).list ().getItems ();
393+ List <Event > events ;
394+ try {
395+ events = kubeClient .v1 ().events ().withInvolvedObject (new ObjectReferenceBuilder ()
396+ .withKind ("Pod" )
397+ .withName (pod .getMetadata ().getName ())
398+ .withNamespace (pod .getMetadata ().getNamespace ())
399+ .build ()).list ().getItems ();
400+ } catch (KubernetesClientException ex ) {
401+ if (ex .getCode () == 403 ) {
402+ log .warn ("Cannot parse events of pod because of insufficient permissions. If fine-grained statistics are desired, give the ShinyProxy ServiceAccount permission to events of pods." );
403+ return ;
404+ }
405+ throw ex ;
406+ }
397407
398408 LocalDateTime pullingTime = null ;
399409 LocalDateTime pulledTime = null ;
@@ -418,7 +428,7 @@ private void parseKubernetesEvents(Proxy proxy, Container container, Pod pod) {
418428 }
419429
420430 if (scheduledTime != null ) {
421- proxyStatusService .containerScheduled (proxy , container , scheduledTime );
431+ proxyStatusService .containerScheduled (proxy , container , scheduledTime );
422432 }
423433 }
424434
0 commit comments