fix(docker/container): container logs viewer error when logging is disabled (#10384)

* fix(docker/container-logs): invalid string breadcrumb

* fix(docker/container): let docker select the logging driver by default on container create

* fix(docker/container-logs): information panel in container logs when logging is disabled

* fix(docker/container): dont include HostConfig.LogConfig if no driver is selected
pull/10401/head
LP B 1 year ago committed by GitHub
parent d678b155ba
commit ada6b31f69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,6 +6,7 @@ import { ListView } from '@/react/docker/containers/ListView';
import { withCurrentUser } from '@/react-tools/withCurrentUser';
import { withReactQuery } from '@/react-tools/withReactQuery';
import { withUIRouter } from '@/react-tools/withUIRouter';
import { LogView } from '@/react/docker/containers/LogView';
export const containersModule = angular
.module('portainer.docker.react.views.containers', [])
@ -13,6 +14,13 @@ export const containersModule = angular
'containersView',
r2a(withUIRouter(withReactQuery(withCurrentUser(ListView))), ['endpoint'])
)
// the view only contains the information panel when logging is disabled
// this is a temporary solution to avoid creating a publicly exposed component
// or an AngularJS component until the logs view is migrated to React
.component(
'containerLogView',
r2a(withUIRouter(withReactQuery(withCurrentUser(LogView))), [])
)
.config(config).name;

@ -75,7 +75,13 @@ angular.module('portainer.docker').controller('ContainerLogsController', [
.then(function success(data) {
var container = data;
$scope.container = container;
const logsEnabled = container.HostConfig && container.HostConfig.LogConfig && container.HostConfig.LogConfig.Type && container.HostConfig.LogConfig.Type !== 'none';
$scope.logsEnabled = logsEnabled;
if (logsEnabled) {
startLogPolling(!container.Config.Tty);
}
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to retrieve container information');

@ -5,14 +5,16 @@
{
label:(container.Name | trimcontainername),
link: 'docker.containers.container',
linkParams:container.Id
linkParams: { id: container.Id }
}, 'Logs']"
>
</page-header>
<container-log-view ng-if="!logsEnabled"></container-log-view>
<log-viewer
data="logs"
ng-if="logs"
ng-if="logs && logsEnabled"
log-collection-change="changeLogCollection"
display-timestamps="state.displayTimestamps"
line-count="state.lineCount"

@ -58,7 +58,7 @@ export function LoggerConfig({
<TextTip color="blue">
Logging driver that will override the default docker daemon driver.
Select Default logging driver if you don&apos;t want to override it.
Supported logging drivers can be found
Supported logging drivers can be found{' '}
<a
href="https://docs.docker.com/engine/admin/logging/overview/#supported-logging-drivers"
target="_blank"
@ -133,6 +133,6 @@ export function validation(): SchemaOf<LogConfig> {
value: string().required('Value is required'),
})
),
type: string().default('none'),
type: string().default(''),
});
}

@ -34,6 +34,11 @@ export function toRequest(
delete config.Entrypoint;
}
// don't include LogConfig object if "Default logging driver" (type === '') is selected
if (values.logConfig.type === '') {
delete config.HostConfig.LogConfig;
}
return config;
function getLogConfig(

@ -39,7 +39,7 @@ export function toViewModel(config: ContainerJSON): Values {
function getLogConfig(value?: HostConfig['LogConfig']): LogConfig {
if (!value || !value.Type) {
return {
type: 'none',
type: '',
options: [],
};
}

@ -0,0 +1,46 @@
import { useCurrentStateAndParams } from '@uirouter/react';
import { useContainer } from '@/react/docker/containers/queries/container';
import { InformationPanel } from '@@/InformationPanel';
import { TextTip } from '@@/Tip/TextTip';
import { Link } from '@@/Link';
export function LogView() {
const {
params: { endpointId: environmentId, id: containerId },
} = useCurrentStateAndParams();
const containerQuery = useContainer(environmentId, containerId);
if (!containerQuery.data || containerQuery.isLoading) {
return null;
}
const logsEnabled =
containerQuery.data.HostConfig?.LogConfig?.Type && // if a portion of the object path doesn't exist, logging is likely disabled
containerQuery.data.HostConfig.LogConfig.Type !== 'none'; // if type === none logging is disabled
return <>{!logsEnabled && <LogsDisabledInfoPanel />}</>;
}
function LogsDisabledInfoPanel() {
const {
params: { id: containerId, nodeName },
} = useCurrentStateAndParams();
return (
<InformationPanel>
<TextTip color="blue">
Logging is disabled for this container. If you want to re-enable
logging, please{' '}
<Link
to="docker.containers.new"
params={{ from: containerId, nodeName }}
>
redeploy your container
</Link>{' '}
and select a logging driver in the &quot;Command & logging&quot; panel.
</TextTip>
</InformationPanel>
);
}

@ -0,0 +1 @@
export { LogView } from './LogView';
Loading…
Cancel
Save