diff --git a/CHANGELOG.md b/CHANGELOG.md index c2e8b06e6..0666ed2d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pkg/apis/scheduler/v1alpha1/container/definition.go b/pkg/apis/scheduler/v1alpha1/container/definition.go index bcd7c56a3..3a3b32101 100644 --- a/pkg/apis/scheduler/v1alpha1/container/definition.go +++ b/pkg/apis/scheduler/v1alpha1/container/definition.go @@ -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 } diff --git a/pkg/deployment/deployment_suite_test.go b/pkg/deployment/deployment_suite_test.go index 3be1ce8cc..3c1ad9c1a 100644 --- a/pkg/deployment/deployment_suite_test.go +++ b/pkg/deployment/deployment_suite_test.go @@ -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{ diff --git a/pkg/deployment/reconcile/action_runtime_container_image_update.go b/pkg/deployment/reconcile/action_runtime_container_image_update.go index e7fb768b0..513945a9e 100644 --- a/pkg/deployment/reconcile/action_runtime_container_image_update.go +++ b/pkg/deployment/reconcile/action_runtime_container_image_update.go @@ -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 diff --git a/pkg/deployment/resources/pod_inspector.go b/pkg/deployment/resources/pod_inspector.go index 97c0a990c..dbf6018b3 100644 --- a/pkg/deployment/resources/pod_inspector.go +++ b/pkg/deployment/resources/pod_inspector.go @@ -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()). diff --git a/pkg/deployment/resources/pod_termination.go b/pkg/deployment/resources/pod_termination.go index 1d6272c5a..47e5cbb3a 100644 --- a/pkg/deployment/resources/pod_termination.go +++ b/pkg/deployment/resources/pod_termination.go @@ -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 } diff --git a/pkg/util/k8sutil/images.go b/pkg/util/k8sutil/images.go index 3f0585840..9bbd881bc 100644 --- a/pkg/util/k8sutil/images.go +++ b/pkg/util/k8sutil/images.go @@ -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 } diff --git a/pkg/util/k8sutil/container/container.go b/pkg/util/k8sutil/resources/container.go similarity index 99% rename from pkg/util/k8sutil/container/container.go rename to pkg/util/k8sutil/resources/container.go index db9ba532f..baca99b8b 100644 --- a/pkg/util/k8sutil/container/container.go +++ b/pkg/util/k8sutil/resources/container.go @@ -18,7 +18,7 @@ // Copyright holder is ArangoDB GmbH, Cologne, Germany // -package container +package resources import ( core "k8s.io/api/core/v1"