Skip to content

Commit

Permalink
refactor: align k8s loggins
Browse files Browse the repository at this point in the history
  • Loading branch information
matteo-s committed Jul 11, 2024
1 parent 1414aaf commit 35f0dba
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ public List<V1Pod> pods(K object) throws K8sFrameworkException {
return pods.getItems();
} catch (ApiException e) {
log.error("Error with k8s: {}", e.getMessage());
if (log.isDebugEnabled()) {
log.debug("k8s api response: {}", e.getResponseBody());
if (log.isTraceEnabled()) {
log.trace("k8s api response: {}", e.getResponseBody());
}

throw new K8sFrameworkException(e.getMessage());
Expand Down Expand Up @@ -288,8 +288,8 @@ public List<CoreLog> logs(K object) throws K8sFrameworkException {
return logs;
} catch (ApiException e) {
log.error("Error with k8s: {}", e.getMessage());
if (log.isDebugEnabled()) {
log.debug("k8s api response: {}", e.getResponseBody());
if (log.isTraceEnabled()) {
log.trace("k8s api response: {}", e.getResponseBody());
}

throw new K8sFrameworkException(e.getMessage());
Expand Down Expand Up @@ -338,8 +338,8 @@ public List<CoreMetric> metrics(K object) throws K8sFrameworkException {
return metrics;
} catch (ApiException e) {
log.error("Error with k8s: {}", e.getMessage());
if (log.isDebugEnabled()) {
log.debug("k8s api response: {}", e.getResponseBody());
if (log.isTraceEnabled()) {
log.trace("k8s api response: {}", e.getResponseBody());
}

throw new K8sFrameworkException(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ public V1CronJob get(@NotNull V1CronJob job) throws K8sFrameworkException {
return batchV1Api.readNamespacedCronJob(jobName, namespace, null);
} catch (ApiException e) {
log.info("Error with k8s: {}", e.getMessage());
if (log.isDebugEnabled()) {
log.debug("k8s api response: {}", e.getResponseBody());
if (log.isTraceEnabled()) {
log.trace("k8s api response: {}", e.getResponseBody());
}

throw new K8sFrameworkException(e.getMessage());
Expand All @@ -234,8 +234,8 @@ public V1CronJob create(V1CronJob job) throws K8sFrameworkException {
return batchV1Api.createNamespacedCronJob(namespace, job, null, null, null, null);
} catch (ApiException e) {
log.error("Error with k8s: {}", e.getResponseBody());
if (log.isDebugEnabled()) {
log.debug("k8s api response: {}", e.getResponseBody());
if (log.isTraceEnabled()) {
log.trace("k8s api response: {}", e.getResponseBody());
}

throw new K8sFrameworkException(e.getResponseBody());
Expand All @@ -253,8 +253,8 @@ public void delete(V1CronJob job) throws K8sFrameworkException {
batchV1Api.deleteNamespacedCronJob(jobName, namespace, null, null, null, null, null, null);
} catch (ApiException e) {
log.error("Error with k8s: {}", e.getResponseBody());
if (log.isDebugEnabled()) {
log.debug("k8s api response: {}", e.getResponseBody());
if (log.isTraceEnabled()) {
log.trace("k8s api response: {}", e.getResponseBody());
}

throw new K8sFrameworkException(e.getResponseBody());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ public K8sDeploymentRunnable run(K8sDeploymentRunnable runnable) throws K8sFrame
log.info("create initConfigMap for {}", String.valueOf(initConfigMap.getMetadata().getName()));
coreV1Api.createNamespacedConfigMap(namespace, initConfigMap, null, null, null, null);
}
} catch (ApiException | NullPointerException e) {
} catch (ApiException e) {
log.error("Error with k8s: {}", e.getMessage());
if (log.isTraceEnabled()) {
log.trace("k8s api response: {}", e.getResponseBody());
}

throw new K8sFrameworkException(e.getMessage());
}

Expand Down Expand Up @@ -328,8 +333,8 @@ public V1Deployment apply(@NotNull V1Deployment deployment) throws K8sFrameworkE
return appsV1Api.replaceNamespacedDeployment(deploymentName, namespace, deployment, null, null, null, null);
} catch (ApiException e) {
log.error("Error with k8s: {}", e.getMessage());
if (log.isDebugEnabled()) {
log.debug("k8s api response: {}", e.getResponseBody());
if (log.isTraceEnabled()) {
log.trace("k8s api response: {}", e.getResponseBody());
}

throw new K8sFrameworkException(e.getMessage());
Expand All @@ -347,8 +352,8 @@ public V1Deployment get(@NotNull V1Deployment deployment) throws K8sFrameworkExc
return appsV1Api.readNamespacedDeployment(deploymentName, namespace, null);
} catch (ApiException e) {
log.info("Error with k8s: {}", e.getResponseBody());
if (log.isDebugEnabled()) {
log.debug("k8s api response: {}", e.getResponseBody());
if (log.isTraceEnabled()) {
log.trace("k8s api response: {}", e.getResponseBody());
}

throw new K8sFrameworkException(e.getResponseBody());
Expand All @@ -365,8 +370,8 @@ public V1Deployment create(V1Deployment deployment) throws K8sFrameworkException
return appsV1Api.createNamespacedDeployment(namespace, deployment, null, null, null, null);
} catch (ApiException e) {
log.error("Error with k8s: {}", e.getResponseBody());
if (log.isDebugEnabled()) {
log.debug("k8s api response: {}", e.getResponseBody());
if (log.isTraceEnabled()) {
log.trace("k8s api response: {}", e.getResponseBody());
}

throw new K8sFrameworkException(e.getResponseBody());
Expand All @@ -383,8 +388,8 @@ public void delete(@NotNull V1Deployment deployment) throws K8sFrameworkExceptio
appsV1Api.deleteNamespacedDeployment(deploymentName, namespace, null, null, null, null, null, null);
} catch (ApiException e) {
log.error("Error with k8s: {}", e.getResponseBody());
if (log.isDebugEnabled()) {
log.debug("k8s api response: {}", e.getResponseBody());
if (log.isTraceEnabled()) {
log.trace("k8s api response: {}", e.getResponseBody());
}

throw new K8sFrameworkException(e.getResponseBody());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ public K8sJobRunnable run(K8sJobRunnable runnable) throws K8sFrameworkException
log.info("create initConfigMap for {}", String.valueOf(initConfigMap.getMetadata().getName()));
coreV1Api.createNamespacedConfigMap(namespace, initConfigMap, null, null, null, null);
}
} catch (ApiException | NullPointerException e) {
} catch (ApiException e) {
log.error("Error with k8s: {}", e.getMessage());
if (log.isTraceEnabled()) {
log.trace("k8s api response: {}", e.getResponseBody());
}

throw new K8sFrameworkException(e.getMessage());
}

Expand Down Expand Up @@ -342,8 +347,8 @@ public V1Job get(@NotNull V1Job job) throws K8sFrameworkException {
return batchV1Api.readNamespacedJob(jobName, namespace, null);
} catch (ApiException e) {
log.info("Error with k8s: {}", e.getMessage());
if (log.isDebugEnabled()) {
log.debug("k8s api response: {}", e.getResponseBody());
if (log.isTraceEnabled()) {
log.trace("k8s api response: {}", e.getResponseBody());
}

throw new K8sFrameworkException(e.getMessage());
Expand All @@ -363,9 +368,9 @@ public V1Job create(V1Job job) throws K8sFrameworkException {
log.info("Job created: {}", Objects.requireNonNull(createdJob.getMetadata()).getName());
return createdJob;
} catch (ApiException e) {
log.error("Error with k8s: {}", e.getResponseBody());
if (log.isDebugEnabled()) {
log.debug("k8s api response: {}", e.getResponseBody());
log.error("Error with k8s: {}", e.getMessage());
if (log.isTraceEnabled()) {
log.trace("k8s api response: {}", e.getResponseBody());
}

throw new K8sFrameworkException(e.getResponseBody());
Expand All @@ -382,9 +387,9 @@ public void delete(V1Job job) throws K8sFrameworkException {

batchV1Api.deleteNamespacedJob(jobName, namespace, null, null, null, null, null, null);
} catch (ApiException e) {
log.error("Error with k8s: {}", e.getResponseBody());
if (log.isDebugEnabled()) {
log.debug("k8s api response: {}", e.getResponseBody());
log.error("Error with k8s: {}", e.getMessage());
if (log.isTraceEnabled()) {
log.trace("k8s api response: {}", e.getResponseBody());
}

throw new K8sFrameworkException(e.getResponseBody());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ public K8sServeRunnable run(K8sServeRunnable runnable) throws K8sFrameworkExcept
log.info("create initConfigMap for {}", String.valueOf(initConfigMap.getMetadata().getName()));
coreV1Api.createNamespacedConfigMap(namespace, initConfigMap, null, null, null, null);
}
} catch (ApiException | NullPointerException e) {
} catch (ApiException e) {
log.error("Error with k8s: {}", e.getMessage());
if (log.isTraceEnabled()) {
log.trace("k8s api response: {}", e.getResponseBody());
}

throw new K8sFrameworkException(e.getMessage());
}

Expand Down Expand Up @@ -278,8 +283,8 @@ public V1Service apply(@NotNull V1Service service) throws K8sFrameworkException
return coreV1Api.replaceNamespacedService(serviceName, namespace, service, null, null, null, null);
} catch (ApiException e) {
log.error("Error with k8s: {}", e.getMessage());
if (log.isDebugEnabled()) {
log.debug("k8s api response: {}", e.getResponseBody());
if (log.isTraceEnabled()) {
log.trace("k8s api response: {}", e.getResponseBody());
}

throw new K8sFrameworkException(e.getMessage());
Expand All @@ -296,9 +301,9 @@ public V1Service get(@NotNull V1Service service) throws K8sFrameworkException {

return coreV1Api.readNamespacedService(serviceName, namespace, null);
} catch (ApiException e) {
log.info("Error with k8s: {}", e.getResponseBody());
if (log.isDebugEnabled()) {
log.debug("k8s api response: {}", e.getResponseBody());
log.info("Error with k8s: {}", e.getMessage());
if (log.isTraceEnabled()) {
log.trace("k8s api response: {}", e.getResponseBody());
}

throw new K8sFrameworkException(e.getResponseBody());
Expand All @@ -316,8 +321,8 @@ public V1Service create(V1Service service) throws K8sFrameworkException {
return coreV1Api.createNamespacedService(namespace, service, null, null, null, null);
} catch (ApiException e) {
log.error("Error with k8s: {}", e.getMessage());
if (log.isDebugEnabled()) {
log.debug("k8s api response: {}", e.getResponseBody());
if (log.isTraceEnabled()) {
log.trace("k8s api response: {}", e.getResponseBody());
}

throw new K8sFrameworkException(e.getMessage());
Expand All @@ -336,8 +341,8 @@ public void delete(V1Service service) throws K8sFrameworkException {
coreV1Api.deleteNamespacedService(serviceName, namespace, null, null, null, null, null, null);
} catch (ApiException e) {
log.error("Error with k8s: {}", e.getMessage());
if (log.isDebugEnabled()) {
log.debug("k8s api response: {}", e.getResponseBody());
if (log.isTraceEnabled()) {
log.trace("k8s api response: {}", e.getResponseBody());
}

throw new K8sFrameworkException(e.getMessage());
Expand Down

0 comments on commit 35f0dba

Please sign in to comment.