1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

[Feature] Move Container utils functions (#1626)

This commit is contained in:
Adam Janikowski 2024-03-22 13:11:56 +01:00 committed by GitHub
parent 6d3100c860
commit 8be3599cd6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 22 additions and 21 deletions

View file

@ -8,6 +8,7 @@
- (Feature) (Scheduler) Introduce Scheduler CRD
- (Feature) Discover Namespace in DebugPackage from K8S
- (Feature) Expose Force CRD Install option
- (Maintenance) Move Container utils functions
## [1.2.39](https://github.com/arangodb/kube-arangodb/tree/1.2.39) (2024-03-11)
- (Feature) Extract Scheduler API

View file

@ -28,7 +28,7 @@ import (
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/container"
kresources "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/resources"
)
type Containers map[string]Container
@ -61,7 +61,7 @@ func (c Containers) Apply(template *core.PodTemplateSpec) error {
}
for k, v := range c {
if id := container.GetContainerIDByName(template.Spec.Containers, k); id >= 0 {
if id := kresources.GetContainerIDByName(template.Spec.Containers, k); id >= 0 {
if err := v.Apply(template, &template.Spec.Containers[id]); err != nil {
return err
}

View file

@ -53,9 +53,9 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/constants"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/container"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/probes"
kresources "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/resources"
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
)
@ -893,7 +893,7 @@ func addLifecycle(name string, uuidRequired bool, license string, group api.Serv
p.Spec.Containers[0].VolumeMounts = append(p.Spec.Containers[0].VolumeMounts, k8sutil.LifecycleVolumeMount())
}
if _, ok := container.GetAnyContainerByName(p.Spec.InitContainers, "init-lifecycle"); !ok {
if _, ok := kresources.GetAnyContainerByName(p.Spec.InitContainers, "init-lifecycle"); !ok {
p.Spec.InitContainers = append(
[]core.Container{createTestLifecycleContainer(emptyResources)},
p.Spec.InitContainers...,
@ -901,7 +901,7 @@ func addLifecycle(name string, uuidRequired bool, license string, group api.Serv
}
}
if _, ok := container.GetAnyContainerByName(p.Spec.InitContainers, "uuid"); !ok {
if _, ok := kresources.GetAnyContainerByName(p.Spec.InitContainers, "uuid"); !ok {
binaryPath, _ := os.Executable()
p.Spec.InitContainers = append(
[]core.Container{

View file

@ -31,7 +31,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/deployment/rotation"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/container"
kresources "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/resources"
)
func newRuntimeContainerImageUpdateAction(action api.Action, actionCtx ActionContext) Action {
@ -286,13 +286,13 @@ func (a actionRuntimeContainerImageUpdate) CheckProgress(ctx context.Context) (b
return true, false, nil
}
cspec, ok := container.GetContainerByName(pod, name)
cspec, ok := kresources.GetContainerByName(pod, name)
if !ok {
a.log.Info("Unable to find container spec")
return true, false, nil
}
cstatus, ok := container.GetContainerStatusByName(pod, name)
cstatus, ok := kresources.GetContainerStatusByName(pod, name)
if !ok {
a.log.Info("Unable to find container status")
return true, false, nil

View file

@ -39,11 +39,11 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/globals"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/container"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/info"
inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector"
podv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors"
kresources "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/resources"
)
var (
@ -61,7 +61,7 @@ const (
)
func (r *Resources) handleRestartedPod(pod *core.Pod, memberStatus *api.MemberStatus, wasTerminated, markAsTerminated *bool) {
containerStatus, exist := container.GetContainerStatusByName(pod, api.ServerGroupReservedContainerNameServer)
containerStatus, exist := kresources.GetContainerStatusByName(pod, api.ServerGroupReservedContainerNameServer)
if exist && containerStatus.State.Terminated != nil {
// do not record termination time again in the code below
*wasTerminated = true
@ -178,11 +178,11 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter
}
if markAsTerminated && memberStatus.Conditions.Update(api.ConditionTypeTerminated, true, "Pod Failed", "") {
if containers := container.GetFailedContainerNames(pod.Status.InitContainerStatuses); len(containers) > 0 {
if containers := kresources.GetFailedContainerNames(pod.Status.InitContainerStatuses); len(containers) > 0 {
for id := range containers {
switch containers[id] {
case api.ServerGroupReservedInitContainerNameVersionCheck:
if c, ok := container.GetAnyContainerStatusByName(pod.Status.InitContainerStatuses, containers[id]); ok {
if c, ok := kresources.GetAnyContainerStatusByName(pod.Status.InitContainerStatuses, containers[id]); ok {
if t := c.State.Terminated; t != nil && t.ExitCode == 11 {
memberStatus.Upgrade = true
updateMemberStatusNeeded = true
@ -192,7 +192,7 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter
memberStatus.Conditions.Update(api.ConditionTypeUpgradeFailed, true, "Upgrade Failed", "")
}
if c, ok := container.GetAnyContainerStatusByName(pod.Status.InitContainerStatuses, containers[id]); ok {
if c, ok := kresources.GetAnyContainerStatusByName(pod.Status.InitContainerStatuses, containers[id]); ok {
if t := c.State.Terminated; t != nil && t.ExitCode != 0 {
log.Str("member", memberStatus.ID).
Str("pod", pod.GetName()).
@ -212,9 +212,9 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter
}
}
if containers := container.GetFailedContainerNames(pod.Status.ContainerStatuses); len(containers) > 0 {
if containers := kresources.GetFailedContainerNames(pod.Status.ContainerStatuses); len(containers) > 0 {
for id := range containers {
if c, ok := container.GetAnyContainerStatusByName(pod.Status.ContainerStatuses, containers[id]); ok {
if c, ok := kresources.GetAnyContainerStatusByName(pod.Status.ContainerStatuses, containers[id]); ok {
if t := c.State.Terminated; t != nil && t.ExitCode != 0 {
log.Str("member", memberStatus.ID).
Str("pod", pod.GetName()).

View file

@ -34,7 +34,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/globals"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/container"
kresources "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/resources"
)
// prepareAgencyPodTermination checks if the given agency pod is allowed to terminate
@ -175,7 +175,7 @@ func (r *Resources) prepareDBServerPodTermination(ctx context.Context, p *core.P
log.Err(err).Debug("Failed to access cluster")
if r.context.GetSpec().Recovery.Get().GetAutoRecover() {
if c, ok := container.GetContainerStatusByName(p, shared.ServerContainerName); ok {
if c, ok := kresources.GetContainerStatusByName(p, shared.ServerContainerName); ok {
if t := c.State.Terminated; t != nil {
return nil
}

View file

@ -27,7 +27,7 @@ import (
schedulerContainerResourcesApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container/resources"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/container"
kresources "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/resources"
)
const (
@ -77,7 +77,7 @@ func GetArangoDBImageIDFromPod(pod *core.Pod, names ...string) (string, error) {
// GetArangoDBImageIDFromContainerStatuses returns the ArangoDB specific image from a container statuses
func GetArangoDBImageIDFromContainerStatuses(containers []core.ContainerStatus, names ...string) (string, bool) {
for _, name := range names {
if id := container.GetContainerStatusIDByName(containers, name); id != -1 {
if id := kresources.GetContainerStatusIDByName(containers, name); id != -1 {
if image := containers[id].ImageID; image != "" {
if disc := ConvertImageID2Image(image); disc != "" {
return disc, true
@ -92,7 +92,7 @@ func GetArangoDBImageIDFromContainerStatuses(containers []core.ContainerStatus,
// GetArangoDBImageFromContainers returns the ArangoDB specific image from a container specs
func GetArangoDBImageFromContainers(containers []core.Container, names ...string) (string, bool) {
for _, name := range names {
if id := container.GetContainerIDByName(containers, name); id != -1 {
if id := kresources.GetContainerIDByName(containers, name); id != -1 {
if image := containers[id].Image; image != "" {
return image, true
}

View file

@ -18,7 +18,7 @@
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package container
package resources
import (
core "k8s.io/api/core/v1"