Skip to content

Commit

Permalink
fix(clusters): prevent Karpenter on a prod cluster (#1664)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctjhoa authored Sep 12, 2024
1 parent 9cf9839 commit 5d89625
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { KubernetesEnum } from 'qovery-typescript-axios'
import { createContext, useContext, useState } from 'react'
import { type Dispatch, type SetStateAction, createContext, useContext, useState } from 'react'
import { Navigate, Route, Routes, useNavigate, useParams } from 'react-router-dom'
import { match } from 'ts-pattern'
import { AssistantTrigger } from '@qovery/shared/assistant/feature'
Expand All @@ -17,17 +17,17 @@ import { ROUTER_CLUSTER_CREATION } from '../../router/router'

export interface ClusterContainerCreateContextInterface {
currentStep: number
setCurrentStep: (step: number) => void
setCurrentStep: Dispatch<SetStateAction<number>>
generalData: ClusterGeneralData | undefined
setGeneralData: (data: ClusterGeneralData) => void
setGeneralData: Dispatch<SetStateAction<ClusterGeneralData | undefined>>
resourcesData: ClusterResourcesData | undefined
setResourcesData: (data: ClusterResourcesData) => void
setResourcesData: Dispatch<SetStateAction<ClusterResourcesData | undefined>>
featuresData: ClusterFeaturesData | undefined
setFeaturesData: (data: ClusterFeaturesData | undefined) => void
setFeaturesData: Dispatch<SetStateAction<ClusterFeaturesData | undefined>>
remoteData: ClusterRemoteData | undefined
setRemoteData: (data: ClusterRemoteData) => void
setRemoteData: Dispatch<SetStateAction<ClusterRemoteData | undefined>>
kubeconfigData: ClusterKubeconfigData | undefined
setKubeconfigData: (data: ClusterKubeconfigData) => void
setKubeconfigData: Dispatch<SetStateAction<ClusterKubeconfigData | undefined>>
}

export const ClusterContainerCreateContext = createContext<ClusterContainerCreateContextInterface | undefined>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FormProvider, useForm } from 'react-hook-form'
import { useNavigate, useParams } from 'react-router-dom'
import { match } from 'ts-pattern'
import { useCloudProviderCredentials, useCloudProviders } from '@qovery/domains/cloud-providers/feature'
import { type ClusterGeneralData } from '@qovery/shared/interfaces'
import { type ClusterGeneralData, type ClusterResourcesData } from '@qovery/shared/interfaces'
import {
CLUSTERS_CREATION_FEATURES_URL,
CLUSTERS_CREATION_KUBECONFIG_URL,
Expand Down Expand Up @@ -37,6 +37,20 @@ export function StepGeneralFeature() {
}, [setCurrentStep])

const onSubmit = methods.handleSubmit((data) => {
if (data.production) {
setResourcesData((data) => ({
cluster_type: data?.cluster_type ?? '',
disk_size: data?.disk_size ?? 50,
instance_type: data?.instance_type ?? '',
nodes: data?.nodes ?? [3, 10],
karpenter: {
enabled: false,
default_service_architecture: 'AMD64',
disk_size_in_gib: '50',
spot_enabled: false,
},
}))
}
if (credentials.length > 0) {
// necessary to get the name of credentials
const currentCredentials = credentials?.filter((item) => item.id === data['credentials'])[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,44 +84,46 @@ export function ClusterResourcesSettings(props: ClusterResourcesSettingsProps) {
</div>
)}
</BlockContent>
{props.cloudProvider === 'AWS' && watchClusterType === KubernetesEnum.MANAGED && (
<Controller
name="karpenter.enabled"
defaultValue={false}
control={control}
render={({ field }) => (
<div className="relative flex flex-col gap-2 overflow-hidden rounded border border-neutral-250 bg-neutral-100 p-4">
<InputToggle
className="max-w-[70%]"
name={field.name}
value={field.value}
onChange={(e) => {
if (props.fromDetail) {
const diskSize = watchDiskSize >= 50 ? watchDiskSize.toString() : '50'
setValue('karpenter.disk_size_in_gib', diskSize)
const architecture = watchInstanceType.includes('AMD') ? 'AMD64' : 'ARM64'
setValue('karpenter.default_service_architecture', architecture)
}
{((!props.fromDetail && !props.isProduction) || props.fromDetail) &&
props.cloudProvider === 'AWS' &&
watchClusterType === KubernetesEnum.MANAGED && (
<Controller
name="karpenter.enabled"
defaultValue={false}
control={control}
render={({ field }) => (
<div className="relative flex flex-col gap-2 overflow-hidden rounded border border-neutral-250 bg-neutral-100 p-4">
<InputToggle
className="max-w-[70%]"
name={field.name}
value={field.value}
onChange={(e) => {
if (props.fromDetail) {
const diskSize = watchDiskSize >= 50 ? watchDiskSize.toString() : '50'
setValue('karpenter.disk_size_in_gib', diskSize)
const architecture = watchInstanceType.includes('AMD') ? 'AMD64' : 'ARM64'
setValue('karpenter.default_service_architecture', architecture)
}

field.onChange(e)
}}
title="Reduce your costs by enabling Karpenter (Beta)"
description="Karpenter simplifies Kubernetes infrastructure with the right nodes at the right time."
forceAlignTop
disabled={props.fromDetail ? props.isProduction || props.hasAlreadyKarpenter : false}
small
/>
<ExternalLink
className="ml-11"
href="https://hub.qovery.com/docs/using-qovery/configuration/clusters/#managing-your-clusters-with-qovery"
>
Documentation link
</ExternalLink>
<KarpenterImage className="absolute right-0 top-0" />
</div>
)}
/>
)}
field.onChange(e)
}}
title="Reduce your costs by enabling Karpenter (Beta)"
description="Karpenter simplifies Kubernetes infrastructure with the right nodes at the right time."
forceAlignTop
disabled={props.fromDetail ? props.isProduction || props.hasAlreadyKarpenter : false}
small
/>
<ExternalLink
className="ml-11"
href="https://hub.qovery.com/docs/using-qovery/configuration/clusters/#managing-your-clusters-with-qovery"
>
Documentation link
</ExternalLink>
<KarpenterImage className="absolute right-0 top-0" />
</div>
)}
/>
)}

{watchKarpenter && (
<Callout.Root color="yellow">
Expand Down

0 comments on commit 5d89625

Please sign in to comment.