Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactoring] Extract Resource Helpers #1517

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- (Feature) License Manager for ML Deployment
- (Feature) (ML) Storage S3 sidecar implementation
- (Feature) TLS CA Secret Key
- (Refactoring) Extract Resource Helpers

## [1.2.35](https://github.com/arangodb/kube-arangodb/tree/1.2.35) (2023-11-06)
- (Maintenance) Update go-driver to v1.6.0, update IsNotFound() checks
Expand Down
11 changes: 6 additions & 5 deletions pkg/deployment/deployment_core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/apis/shared"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/resources"
)

func TestEnsurePod_ArangoDB_Core(t *testing.T) {
Expand Down Expand Up @@ -542,7 +543,7 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) {
Image: testImage,
Command: createTestCommandForDBServer(firstDBServerStatus.ID, false, false, false),
Ports: createTestPorts(api.ServerGroupDBServers),
Resources: k8sutil.ExtractPodAcceptedResourceRequirement(resourcesUnfiltered),
Resources: resources.ExtractPodAcceptedResourceRequirement(resourcesUnfiltered),
VolumeMounts: []core.VolumeMount{
k8sutil.ArangodVolumeMount(),
},
Expand Down Expand Up @@ -599,7 +600,7 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) {
Image: testImage,
Command: createTestCommandForDBServer(firstDBServerStatus.ID, false, false, false),
Ports: createTestPorts(api.ServerGroupDBServers),
Resources: k8sutil.ExtractPodAcceptedResourceRequirement(resourcesUnfiltered),
Resources: resources.ExtractPodAcceptedResourceRequirement(resourcesUnfiltered),
VolumeMounts: []core.VolumeMount{
k8sutil.ArangodVolumeMount(),
},
Expand Down Expand Up @@ -659,7 +660,7 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) {
Image: testImage,
Command: createTestCommandForDBServer(firstDBServerStatus.ID, false, false, false),
Ports: createTestPorts(api.ServerGroupDBServers),
Resources: k8sutil.ExtractPodAcceptedResourceRequirement(resourcesUnfiltered),
Resources: resources.ExtractPodAcceptedResourceRequirement(resourcesUnfiltered),
VolumeMounts: []core.VolumeMount{
k8sutil.ArangodVolumeMount(),
},
Expand Down Expand Up @@ -1193,7 +1194,7 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) {
ImagePullPolicy: core.PullIfNotPresent,
SecurityContext: securityContext.NewSecurityContext(),
},
testArangodbInternalExporterContainer(false, true, k8sutil.ExtractPodAcceptedResourceRequirement(resourcesUnfiltered)),
testArangodbInternalExporterContainer(false, true, resources.ExtractPodAcceptedResourceRequirement(resourcesUnfiltered)),
},
RestartPolicy: core.RestartPolicyNever,
TerminationGracePeriodSeconds: &defaultDBServerTerminationTimeout,
Expand Down Expand Up @@ -1248,7 +1249,7 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) {
k8sutil.LifecycleVolume(),
},
InitContainers: []core.Container{
createTestLifecycleContainer(k8sutil.ExtractPodAcceptedResourceRequirement(resourcesUnfiltered)),
createTestLifecycleContainer(resources.ExtractPodAcceptedResourceRequirement(resourcesUnfiltered)),
},
Containers: []core.Container{
{
Expand Down
7 changes: 4 additions & 3 deletions pkg/deployment/deployment_pod_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
resources2 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/resources"
)

type envFunc func() []core.EnvVar
Expand Down Expand Up @@ -134,7 +135,7 @@ func TestEnsurePod_ArangoDB_Resources(t *testing.T) {
Image: testImage,
Command: createTestCommandForDBServer(firstDBServerStatus.ID, false, false, false),
Ports: createTestPorts(api.ServerGroupAgents),
Resources: k8sutil.ExtractPodAcceptedResourceRequirement(resourcesUnfiltered),
Resources: resources2.ExtractPodAcceptedResourceRequirement(resourcesUnfiltered),
VolumeMounts: []core.VolumeMount{
k8sutil.ArangodVolumeMount(),
},
Expand Down Expand Up @@ -194,7 +195,7 @@ func TestEnsurePod_ArangoDB_Resources(t *testing.T) {
Image: testImage,
Command: createTestCommandForDBServer(firstDBServerStatus.ID, false, false, false),
Ports: createTestPorts(api.ServerGroupAgents),
Resources: k8sutil.ExtractPodAcceptedResourceRequirement(resourcesUnfiltered),
Resources: resources2.ExtractPodAcceptedResourceRequirement(resourcesUnfiltered),
VolumeMounts: []core.VolumeMount{
k8sutil.ArangodVolumeMount(),
},
Expand Down Expand Up @@ -252,7 +253,7 @@ func TestEnsurePod_ArangoDB_Resources(t *testing.T) {
Image: testImage,
Command: createTestCommandForDBServer(firstDBServerStatus.ID, false, false, false),
Ports: createTestPorts(api.ServerGroupAgents),
Resources: k8sutil.ExtractPodAcceptedResourceRequirement(resourcesUnfiltered),
Resources: resources2.ExtractPodAcceptedResourceRequirement(resourcesUnfiltered),
VolumeMounts: []core.VolumeMount{
k8sutil.ArangodVolumeMount(),
},
Expand Down
5 changes: 3 additions & 2 deletions pkg/deployment/deployment_pod_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/constants"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/resources"
)

func TestEnsurePod_Sync_Error(t *testing.T) {
Expand Down Expand Up @@ -1304,7 +1305,7 @@ func TestEnsurePod_Sync_Worker(t *testing.T) {
},
ImagePullPolicy: core.PullIfNotPresent,
Lifecycle: createTestLifecycle(api.ServerGroupSyncMasters),
Resources: k8sutil.ExtractPodAcceptedResourceRequirement(resourcesUnfiltered),
Resources: resources.ExtractPodAcceptedResourceRequirement(resourcesUnfiltered),
SecurityContext: securityContext.NewSecurityContext(),
VolumeMounts: []core.VolumeMount{
k8sutil.LifecycleVolumeMount(),
Expand Down Expand Up @@ -1399,7 +1400,7 @@ func TestEnsurePod_Sync_Worker(t *testing.T) {
},
ImagePullPolicy: core.PullIfNotPresent,
Lifecycle: createTestLifecycle(api.ServerGroupSyncMasters),
Resources: k8sutil.ExtractPodAcceptedResourceRequirement(resourcesUnfiltered),
Resources: resources.ExtractPodAcceptedResourceRequirement(resourcesUnfiltered),
SecurityContext: securityContext.NewSecurityContext(),
VolumeMounts: []core.VolumeMount{
k8sutil.LifecycleVolumeMount(),
Expand Down
5 changes: 3 additions & 2 deletions pkg/deployment/resources/internal_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ import (
"github.com/arangodb/kube-arangodb/pkg/apis/shared"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/probes"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/resources"
)

// ArangodbInternalExporterContainer creates metrics container based on internal exporter
func ArangodbInternalExporterContainer(image string, args []string, livenessProbe *probes.HTTPProbeConfig,
resources core.ResourceRequirements, spec api.DeploymentSpec, groupSpec api.ServerGroupSpec) (core.Container, error) {
res core.ResourceRequirements, spec api.DeploymentSpec, groupSpec api.ServerGroupSpec) (core.Container, error) {

exePath := k8sutil.LifecycleBinary()

Expand All @@ -54,7 +55,7 @@ func ArangodbInternalExporterContainer(image string, args []string, livenessProb
Protocol: core.ProtocolTCP,
},
},
Resources: k8sutil.ExtractPodAcceptedResourceRequirement(resources),
Resources: resources.ExtractPodAcceptedResourceRequirement(res),
SecurityContext: k8sutil.CreateSecurityContext(groupSpec.SecurityContext),
ImagePullPolicy: core.PullIfNotPresent,
VolumeMounts: []core.VolumeMount{k8sutil.LifecycleVolumeMount()},
Expand Down
5 changes: 3 additions & 2 deletions pkg/deployment/resources/pod_creator_arangod.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/constants"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/interfaces"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/resources"
)

const (
Expand Down Expand Up @@ -284,7 +285,7 @@ func (a *ArangoDContainer) GetEnvs() ([]core.EnvVar, []core.EnvFromSource) {
}

func (a *ArangoDContainer) GetResourceRequirements() core.ResourceRequirements {
return k8sutil.ExtractPodAcceptedResourceRequirement(a.arangoMember.Spec.Overrides.GetResources(&a.groupSpec))
return resources.ExtractPodAcceptedResourceRequirement(a.arangoMember.Spec.Overrides.GetResources(&a.groupSpec))
}

func (a *ArangoDContainer) GetLifecycle() (*core.Lifecycle, error) {
Expand Down Expand Up @@ -516,7 +517,7 @@ func (m *MemberArangoDPod) GetInitContainers(cachedStatus interfaces.Inspector)
}
}

return applyInitContainersResourceResources(initContainers, k8sutil.ExtractPodInitContainerAcceptedResourceRequirement(m.GetContainerCreator().GetResourceRequirements())), nil
return applyInitContainersResourceResources(initContainers, resources.ExtractPodInitContainerAcceptedResourceRequirement(m.GetContainerCreator().GetResourceRequirements())), nil
}

func (m *MemberArangoDPod) GetFinalizers() []string {
Expand Down
5 changes: 3 additions & 2 deletions pkg/deployment/resources/pod_creator_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/globals"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/interfaces"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/resources"
)

const (
Expand Down Expand Up @@ -152,7 +153,7 @@ func (a *ArangoSyncContainer) GetProbes() (*core.Probe, *core.Probe, *core.Probe
}

func (a *ArangoSyncContainer) GetResourceRequirements() core.ResourceRequirements {
return k8sutil.ExtractPodAcceptedResourceRequirement(a.arangoMember.Spec.Overrides.GetResources(&a.groupSpec))
return resources.ExtractPodAcceptedResourceRequirement(a.arangoMember.Spec.Overrides.GetResources(&a.groupSpec))
}

func (a *ArangoSyncContainer) GetLifecycle() (*core.Lifecycle, error) {
Expand Down Expand Up @@ -308,7 +309,7 @@ func (m *MemberSyncPod) GetInitContainers(cachedStatus interfaces.Inspector) ([]
initContainers = append(initContainers, c)
}

return applyInitContainersResourceResources(initContainers, k8sutil.ExtractPodInitContainerAcceptedResourceRequirement(m.GetContainerCreator().GetResourceRequirements())), nil
return applyInitContainersResourceResources(initContainers, resources.ExtractPodInitContainerAcceptedResourceRequirement(m.GetContainerCreator().GetResourceRequirements())), nil
}

func (m *MemberSyncPod) GetFinalizers() []string {
Expand Down
4 changes: 2 additions & 2 deletions pkg/deployment/resources/pod_init_containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/deployment/features"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/resources"
)

// applyInitContainersResourceResources updates passed init containers to ensure that all resources are set (if such feature is enabled)
Expand All @@ -40,7 +40,7 @@ func applyInitContainersResourceResources(initContainers []core.Container, mainC
continue
}

k8sutil.ApplyContainerResourceRequirements(&initContainers[i], mainContainerResources)
resources.ApplyContainerResourceRequirements(&initContainers[i], mainContainerResources)
}
return initContainers
}
3 changes: 2 additions & 1 deletion pkg/util/k8sutil/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
core "k8s.io/api/core/v1"

"github.com/arangodb/kube-arangodb/pkg/util/constants"
resources2 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/resources"
)

const (
Expand Down Expand Up @@ -69,7 +70,7 @@ func InitLifecycleContainer(image, binaryPath string, resources *core.ResourceRe
}

if resources != nil {
c.Resources = ExtractPodAcceptedResourceRequirement(*resources)
c.Resources = resources2.ExtractPodAcceptedResourceRequirement(*resources)
}
return c, nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/util/k8sutil/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/errors"
persistentvolumeclaimv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors"
resources2 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/resources"
)

// IsPersistentVolumeClaimMarkedForDeletion returns true if the pvc has been marked for deletion.
Expand Down Expand Up @@ -60,7 +61,7 @@ func IsPersistentVolumeClaimResizing(pvc *core.PersistentVolumeClaim) bool {

// ExtractStorageResourceRequirement filters resource requirements for Pods.
func ExtractStorageResourceRequirement(resources core.ResourceRequirements) core.ResourceRequirements {
filterStorage := NewPodResourceListFilter(core.ResourceStorage, "iops")
filterStorage := resources2.NewPodResourceListFilter(core.ResourceStorage, "iops")

return core.ResourceRequirements{
Limits: filterStorage(resources.Limits),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package k8sutil
package resources

import (
core "k8s.io/api/core/v1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package k8sutil
package resources

import (
"fmt"
Expand Down