fix: windows container capability [EE-5814] (#11764)

pull/11766/head
Steven Kang 2024-05-03 10:56:34 +12:00 committed by GitHub
parent 14a365045d
commit e75e6cb7f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 10 deletions

View File

@ -20,7 +20,7 @@ import { TextTip } from '@@/Tip/TextTip';
import { HelpLink } from '@@/HelpLink';
import { useContainers } from '../queries/containers';
import { useSystemLimits } from '../../proxy/queries/useInfo';
import { useSystemLimits, useIsWindows } from '../../proxy/queries/useInfo';
import { useCreateOrReplaceMutation } from './useCreateMutation';
import { useValidation } from './validation';
@ -48,6 +48,7 @@ export function CreateView() {
function CreateForm() {
const environmentId = useEnvironmentId();
const router = useRouter();
const isWindows = useIsWindows(environmentId);
const { trackEvent } = useAnalytics();
const isAdminQuery = useIsEdgeAdmin();
const { authorized: isEnvironmentAdmin } = useIsEnvironmentAdmin({
@ -57,7 +58,8 @@ function CreateForm() {
const mutation = useCreateOrReplaceMutation();
const initialValuesQuery = useInitialValues(
mutation.isLoading || mutation.isSuccess
mutation.isLoading || mutation.isSuccess,
isWindows
);
const registriesQuery = useEnvironmentRegistries(environmentId);
@ -84,9 +86,11 @@ function CreateForm() {
const environment = envQuery.data;
// if windows, hide capabilities. this is because capadd and capdel are not supported on windows
const hideCapabilities =
!environment.SecuritySettings.allowContainerCapabilitiesForRegularUsers &&
!isEnvironmentAdmin;
(!environment.SecuritySettings.allowContainerCapabilitiesForRegularUsers &&
!isEnvironmentAdmin) ||
isWindows;
const {
isDuplicating = false,

View File

@ -5,9 +5,10 @@ import { DockerContainer } from '../../types';
import { CONTAINER_MODE, Values } from './types';
export function getDefaultViewModel() {
export function getDefaultViewModel(isWindows: boolean) {
const networkMode = isWindows ? 'nat' : 'bridge';
return {
networkMode: 'bridge',
networkMode,
hostname: '',
domain: '',
macAddress: '',

View File

@ -57,7 +57,7 @@ export interface Values extends BaseFormValues {
env: EnvVarValues;
}
export function useInitialValues(submitting: boolean) {
export function useInitialValues(submitting: boolean, isWindows: boolean) {
const {
params: { nodeName, from },
} = useCurrentStateAndParams();
@ -86,7 +86,7 @@ export function useInitialValues(submitting: boolean) {
if (!from) {
return {
initialValues: defaultValues(isPureAdmin, user.Id, nodeName),
initialValues: defaultValues(isPureAdmin, user.Id, nodeName, isWindows),
};
}
@ -151,12 +151,13 @@ export function useInitialValues(submitting: boolean) {
function defaultValues(
isPureAdmin: boolean,
currentUserId: UserId,
nodeName: string
nodeName: string,
isWindows: boolean
): Values {
return {
commands: commandsTabUtils.getDefaultViewModel(),
volumes: volumesTabUtils.getDefaultViewModel(),
network: networkTabUtils.getDefaultViewModel(),
network: networkTabUtils.getDefaultViewModel(isWindows), // windows containers should default to the nat network, not the bridge
labels: labelsTabUtils.getDefaultViewModel(),
restartPolicy: restartPolicyTabUtils.getDefaultViewModel(),
resources: resourcesTabUtils.getDefaultViewModel(),

View File

@ -34,6 +34,14 @@ export function useInfo<TSelect = SystemInfo>(
);
}
export function useIsWindows(environmentId: EnvironmentId) {
const query = useInfo(environmentId, {
select: (info) => info.OSType === 'windows',
});
return !!query.data;
}
export function useIsStandAlone(environmentId: EnvironmentId) {
const query = useInfo(environmentId, {
select: (info) => !info.Swarm?.NodeID,