diff --git a/CHANGELOG.md b/CHANGELOG.md index 27613495c..c9641de2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ - (Maintenance) Expose Context in OperatorV2 Item Handler - (Feature) Improve K8S Mock for UT - (Feature) (ML) Introduce basic Conditions -- (Improvement) Raise memory requests for init containers to 50mi +- (Improvement) Use same requests/limits for init containers as for main container - (Feature) (ML) Metadata Service Implementation - (Feature) License Manager for ML Deployment - (Feature) (ML) Storage S3 sidecar implementation diff --git a/pkg/deployment/deployment_suite_test.go b/pkg/deployment/deployment_suite_test.go index c0322c16a..fb77d0b1b 100644 --- a/pkg/deployment/deployment_suite_test.go +++ b/pkg/deployment/deployment_suite_test.go @@ -34,6 +34,7 @@ import ( "github.com/stretchr/testify/require" core "k8s.io/api/core/v1" extfake "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake" + "k8s.io/apimachinery/pkg/api/resource" meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/fake" recordfake "k8s.io/client-go/tools/record" @@ -683,7 +684,8 @@ func createTestLifecycleContainer(resources core.ResourceRequirements) core.Cont func createTestAlpineContainer(name string, requireUUID bool) core.Container { binaryPath, _ := os.Executable() var securityContext api.ServerGroupSpecSecurityContext - return k8sutil.ArangodInitContainer("uuid", name, "rocksdb", binaryPath, testImageOperator, requireUUID, securityContext.NewSecurityContext()) + resources := emptyResources + return k8sutil.ArangodInitContainer("uuid", name, "rocksdb", binaryPath, testImageOperator, requireUUID, resources, securityContext.NewSecurityContext()) } func (testCase *testCaseStruct) createTestPodData(deployment *Deployment, group api.ServerGroup, @@ -887,6 +889,17 @@ func addLifecycle(name string, uuidRequired bool, license string, group api.Serv p.Spec.Containers[0].Lifecycle = createTestLifecycle(api.ServerGroupAgents) } + initContainerResources := core.ResourceRequirements{ + Requests: core.ResourceList{ + core.ResourceCPU: resource.MustParse("100m"), + core.ResourceMemory: resource.MustParse("50Mi"), + }, + Limits: core.ResourceList{ + core.ResourceCPU: resource.MustParse("100m"), + core.ResourceMemory: resource.MustParse("50Mi"), + }, + } + if len(p.Spec.Containers) > 0 { if _, ok := k8sutil.GetAnyVolumeMountByName(p.Spec.Containers[0].VolumeMounts, "lifecycle"); !ok { p.Spec.Containers[0].VolumeMounts = append(p.Spec.Containers[0].VolumeMounts, k8sutil.LifecycleVolumeMount()) @@ -898,13 +911,15 @@ func addLifecycle(name string, uuidRequired bool, license string, group api.Serv p.Spec.InitContainers..., ) } + + initContainerResources = *(p.Spec.Containers[0].Resources.DeepCopy()) } if _, ok := k8sutil.GetAnyContainerByName(p.Spec.InitContainers, "uuid"); !ok { binaryPath, _ := os.Executable() p.Spec.InitContainers = append( []core.Container{ - k8sutil.ArangodInitContainer("uuid", name, "rocksdb", binaryPath, testImageOperator, uuidRequired, securityContext.NewSecurityContext()), + k8sutil.ArangodInitContainer("uuid", name, "rocksdb", binaryPath, testImageOperator, uuidRequired, initContainerResources, securityContext.NewSecurityContext()), }, p.Spec.InitContainers..., ) diff --git a/pkg/deployment/resources/pod_creator_arangod.go b/pkg/deployment/resources/pod_creator_arangod.go index 1e06f4edb..e184670a1 100644 --- a/pkg/deployment/resources/pod_creator_arangod.go +++ b/pkg/deployment/resources/pod_creator_arangod.go @@ -469,8 +469,9 @@ func (m *MemberArangoDPod) GetInitContainers(cachedStatus interfaces.Inspector) requireUUID := m.group == api.ServerGroupDBServers && m.status.IsInitialized sc := k8sutil.CreateSecurityContext(m.groupSpec.SecurityContext) + resources := m.GetContainerCreator().GetResourceRequirements() c := k8sutil.ArangodInitContainer(api.ServerGroupReservedInitContainerNameUUID, m.status.ID, engine, executable, - m.resources.context.GetOperatorImage(), requireUUID, sc) + m.resources.context.GetOperatorImage(), requireUUID, resources, sc) initContainers = append(initContainers, c) } @@ -495,8 +496,11 @@ func (m *MemberArangoDPod) GetInitContainers(cachedStatus interfaces.Inspector) switch m.group { case api.ServerGroupAgents, api.ServerGroupDBServers, api.ServerGroupSingle: if features.UpgradeVersionCheckV2().Enabled() { - c := k8sutil.ArangodVersionCheckInitContainer(api.ServerGroupReservedInitContainerNameVersionCheck, executable, m.resources.context.GetOperatorImage(), - m.imageInfo.ArangoDBVersion, m.groupSpec.SecurityContext.NewSecurityContext()) + c := k8sutil.ArangodVersionCheckInitContainer(api.ServerGroupReservedInitContainerNameVersionCheck, executable, + m.resources.context.GetOperatorImage(), + m.imageInfo.ArangoDBVersion, + m.GetContainerCreator().GetResourceRequirements(), + m.groupSpec.SecurityContext.NewSecurityContext()) initContainers = append(initContainers, c) } else if features.UpgradeVersionCheck().Enabled() { upgradeContainer := &ArangoVersionCheckContainer{ diff --git a/pkg/handlers/job/handler.go b/pkg/handlers/job/handler.go index 9542d7fb6..c3d756a15 100644 --- a/pkg/handlers/job/handler.go +++ b/pkg/handlers/job/handler.go @@ -163,8 +163,13 @@ func (h *handler) prepareK8sJob(job *appsApi.ArangoJob) (*batch.Job, error) { return &k8sJob, err } + resources := core.ResourceRequirements{} + if len(job.Spec.JobTemplate.Template.Spec.Containers) > 0 { + resources = job.Spec.JobTemplate.Template.Spec.Containers[0].Resources + } + initContainer := k8sutil.ArangodWaiterInitContainer(api.ServerGroupReservedInitContainerNameWait, deployment.Name, executable, - h.operator.Image(), spec.TLS.IsSecure(), &core.SecurityContext{}) + h.operator.Image(), spec.TLS.IsSecure(), resources, &core.SecurityContext{}) k8sJob.Spec.Template.Spec.InitContainers = append(k8sJob.Spec.Template.Spec.InitContainers, initContainer) diff --git a/pkg/util/k8sutil/pods.go b/pkg/util/k8sutil/pods.go index 2795948f8..abc0a468f 100644 --- a/pkg/util/k8sutil/pods.go +++ b/pkg/util/k8sutil/pods.go @@ -464,7 +464,7 @@ func RocksdbEncryptionReadOnlyVolumeMount() core.VolumeMount { } // ArangodInitContainer creates a container configured to initialize a UUID file. -func ArangodInitContainer(name, id, engine, executable, operatorImage string, requireUUID bool, securityContext *core.SecurityContext) core.Container { +func ArangodInitContainer(name, id, engine, executable, operatorImage string, requireUUID bool, resources core.ResourceRequirements, securityContext *core.SecurityContext) core.Container { uuidFile := filepath.Join(shared.ArangodVolumeMountDir, "UUID") engineFile := filepath.Join(shared.ArangodVolumeMountDir, "ENGINE") var command = []string{ @@ -486,11 +486,11 @@ func ArangodInitContainer(name, id, engine, executable, operatorImage string, re volumes := []core.VolumeMount{ ArangodVolumeMount(), } - return operatorInitContainer(name, operatorImage, command, securityContext, volumes) + return operatorInitContainer(name, operatorImage, command, resources, securityContext, volumes) } // ArangodWaiterInitContainer creates a container configured to wait for specific ArangoDeployment to be ready -func ArangodWaiterInitContainer(name, deploymentName, executable, operatorImage string, isSecured bool, securityContext *core.SecurityContext) core.Container { +func ArangodWaiterInitContainer(name, deploymentName, executable, operatorImage string, isSecured bool, resources core.ResourceRequirements, securityContext *core.SecurityContext) core.Container { var command = []string{ executable, "lifecycle", @@ -503,25 +503,16 @@ func ArangodWaiterInitContainer(name, deploymentName, executable, operatorImage if isSecured { volumes = append(volumes, TlsKeyfileVolumeMount()) } - return operatorInitContainer(name, operatorImage, command, securityContext, volumes) + return operatorInitContainer(name, operatorImage, command, resources, securityContext, volumes) } // createInitContainer creates operator-specific init container -func operatorInitContainer(name, operatorImage string, command []string, securityContext *core.SecurityContext, volumes []core.VolumeMount) core.Container { +func operatorInitContainer(name, operatorImage string, command []string, resources core.ResourceRequirements, securityContext *core.SecurityContext, volumes []core.VolumeMount) core.Container { c := core.Container{ - Name: name, - Image: operatorImage, - Command: command, - Resources: core.ResourceRequirements{ - Requests: core.ResourceList{ - core.ResourceCPU: resource.MustParse("100m"), - core.ResourceMemory: resource.MustParse("50Mi"), - }, - Limits: core.ResourceList{ - core.ResourceCPU: resource.MustParse("100m"), - core.ResourceMemory: resource.MustParse("50Mi"), - }, - }, + Name: name, + Image: operatorImage, + Command: command, + Resources: resources, Env: []core.EnvVar{ { Name: "MY_POD_NAMESPACE", diff --git a/pkg/util/k8sutil/version_check.go b/pkg/util/k8sutil/version_check.go index 0e2e3d595..093d45684 100644 --- a/pkg/util/k8sutil/version_check.go +++ b/pkg/util/k8sutil/version_check.go @@ -32,7 +32,7 @@ import ( ) // ArangodVersionCheckInitContainer creates a container configured to check version. -func ArangodVersionCheckInitContainer(name, executable, operatorImage string, version driver.Version, securityContext *core.SecurityContext) core.Container { +func ArangodVersionCheckInitContainer(name, executable, operatorImage string, version driver.Version, resources core.ResourceRequirements, securityContext *core.SecurityContext) core.Container { versionFile := filepath.Join(shared.ArangodVolumeMountDir, "VERSION-1") var command = []string{ executable, @@ -57,5 +57,5 @@ func ArangodVersionCheckInitContainer(name, executable, operatorImage string, ve volumes := []core.VolumeMount{ ArangodVolumeMount(), } - return operatorInitContainer(name, operatorImage, command, securityContext, volumes) + return operatorInitContainer(name, operatorImage, command, resources, securityContext, volumes) } diff --git a/test.json b/test.json new file mode 100644 index 000000000..7911140d7 --- /dev/null +++ b/test.json @@ -0,0 +1,8 @@ +{ + "bootstrap": "v0.2.0-eab2c9e", + "training": "dev-main-83ffd30", + "prediction": "dev-main-0c0c6e8", + "projects": "dev-main-4366bfe", + "integration": "latest", + "grond": "latest" +}