8000 [Bugfix] Fix ArangoRoute Target switch in case of temporary error by ajanikow · Pull Request #1804 · arangodb/kube-arangodb · GitHub
[go: up one dir, main page]

Skip to content

[Bugfix] Fix ArangoRoute Target switch in case of temporary error #1804

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

Merged
merged 1 commit into from
Jan 29, 2025
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 @@ -51,6 +51,7 @@
- (Feature) (ML) Allow to use PlatformStorage
- (Maintenance) Bump Go Image to 1.22.11
- (Feature) Split Helm and KClient
- (Bugfix) Fix ArangoRoute Target switch in case of temporary error

## [1.2.43](https://github.com/arangodb/kube-arangodb/tree/1.2.43) (2024-10-14)
- (Feature) ArangoRoute CRD
Expand Down
6 changes: 3 additions & 3 deletions pkg/handlers/networking/route/handler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,6 @@ package route
import (
"context"

apiErrors "k8s.io/apimachinery/pkg/api/errors"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"

Expand All @@ -34,6 +33,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/operatorV2/event"
"github.com/arangodb/kube-arangodb/pkg/operatorV2/operation"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors"
)

var logger = logging.Global().RegisterAndGetLogger("networking-route-operator", logging.Info)
Expand All @@ -56,7 +56,7 @@ func (h *handler) Handle(ctx context.Context, item operation.Item) error {

object, err := util.WithKubernetesContextTimeoutP2A2(ctx, h.client.NetworkingV1alpha1().ArangoRoutes(item.Namespace).Get, item.Name, meta.GetOptions{})
if err != nil {
if apiErrors.IsNotFound(err) {
if kerrors.IsNotFound(err) {
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/handlers/networking/route/handler_deployment.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,6 @@ package route
import (
"context"

apiErrors "k8s.io/apimachinery/pkg/api/errors"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"

api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
Expand All @@ -32,6 +31,7 @@ import (
operator "github.com/arangodb/kube-arangodb/pkg/operatorV2"
"github.com/arangodb/kube-arangodb/pkg/operatorV2/operation"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors"
)

func (h *handler) HandleArangoDeployment(ctx context.Context, item operation.Item, extension *networkingApi.ArangoRoute, status *networkingApi.ArangoRouteStatus) (bool, error) {
Expand All @@ -43,7 +43,7 @@ func (h *handler) HandleArangoDeployment(ctx context.Context, item operation.Ite

deployment, err := util.WithKubernetesContextTimeoutP2A2(ctx, h.client.DatabaseV1().ArangoDeployments(item.Namespace).Get, name, meta.GetOptions{})
if err != nil {
if apiErrors.IsNotFound(err) {
if kerrors.IsNotFound(err) {
// Condition for Found should be set to false
if util.Or(
status.Conditions.Update(networkingApi.DeploymentFoundCondition, false, "ArangoDeployment not found", "ArangoDeployment not found"),
Expand Down
7 changes: 6 additions & 1 deletion pkg/handlers/networking/route/handler_destination.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,6 +48,11 @@ func (h *handler) HandleArangoDestination(ctx context.Context, item operation.It

func (h *handler) HandleArangoDestinationWithTargets(ctx context.Context, item operation.Item, extension *networkingApi.ArangoRoute, status *networkingApi.ArangoRouteStatus, depl *api.ArangoDeployment) (*operator.Condition, bool, error) {
c, changed, err := h.HandleArangoDestination(ctx, item, extension, status, depl)

if operator.IsTemporary(err) {
return nil, false, err
}

if c == nil && !c.Status && status.Target != nil {
status.Target = nil
changed = true
Expand Down
17 changes: 5 additions & 12 deletions pkg/handlers/networking/route/handler_destination_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"fmt"

core "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"

Expand All @@ -48,19 +49,15 @@ func (h *handler) HandleArangoDestinationEndpoints(ctx context.Context, item ope

s, err := util.WithKubernetesContextTimeoutP2A2(ctx, h.kubeClient.CoreV1().Services(endpoints.GetNamespace(extension)).Get, endpoints.GetName(), meta.GetOptions{})
if err != nil {
if api.IsNotFound(err) {
if kerrors.IsNotFound(err) {
return &operator.Condition{
Status: false,
Reason: "Destination Not Found",
Message: fmt.Sprintf("Service `%s/%s` Not found", endpoints.GetNamespace(extension), endpoints.GetName()),
}, false, nil
}

return &operator.Condition{
Status: false,
Reason: "Destination Not Found",
Message: fmt.Sprintf("Unknown error for service `%s/%s`: %s", endpoints.GetNamespace(extension), endpoints.GetName(), err.Error()),
}, false, nil
return nil, false, operator.Temporary(err, "Unable to get service")
}

if !endpoints.Equals(s) {
Expand All @@ -73,19 +70,15 @@ func (h *handler) HandleArangoDestinationEndpoints(ctx context.Context, item ope

e, err := util.WithKubernetesContextTimeoutP2A2(ctx, h.kubeClient.CoreV1().Endpoints(endpoints.GetNamespace(extension)).Get, endpoints.GetName(), meta.GetOptions{})
if err != nil {
if api.IsNotFound(err) {
if kerrors.IsNotFound(err) {
return &operator.Condition{
Status: false,
Reason: "Destination Not Found",
Message: fmt.Sprintf("Endpoints `%s/%s` Not found", endpoints.GetNamespace(extension), endpoints.GetName()),
}, false, nil
}

return &operator.Condition{
Status: false,
Reason: "Destination Not Found",
Message: fmt.Sprintf("Unknown error for endpoints `%s/%s`: %s", endpoints.GetNamespace(extension), endpoints.GetName(), err.Error()),
}, false, nil
return nil, false, operator.Temporary(err, "Unable to get endpoints")
}

// Discover port name - empty names are allowed
Expand Down
9 changes: 3 additions & 6 deletions pkg/handlers/networking/route/handler_destination_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
operator "github.com/arangodb/kube-arangodb/pkg/operatorV2"
"github.com/arangodb/kube-arangodb/pkg/operatorV2/operation"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors"
)

func (h *handler) HandleArangoDestinationService(ctx context.Context, item operation.Item, extension *networkingApi.ArangoRoute, status *networkingApi.ArangoRouteStatus, deployment *api.ArangoDeployment, dest *networkingApi.ArangoRouteSpecDestination, svc *networkingApi.ArangoRouteSpecDestinationService) (*operator.Condition, bool, error) {
Expand All @@ -48,19 +49,15 @@ func (h *handler) HandleArangoDestinationService(ctx context.Context, item opera

s, err := util.WithKubernetesContextTimeoutP2A2(ctx, h.kubeClient.CoreV1().Services(svc.GetNamespace(extension)).Get, svc.GetName(), meta.GetOptions{})
if err != nil {
if api.IsNotFound(err) {
if kerrors.IsNotFound(err) {
return &operator.Condition{
Status: false,
Reason: "Destination Not Found",
Message: fmt.Sprintf("Service `%s/%s` Not found", svc.GetNamespace(extension), svc.GetName()),
}, false, nil
}

return &operator.Condition{
Status: false,
Reason: "Destination Not Found",
Message: fmt.Sprintf("Unknown error for service `%s/%s`: %s", svc.GetNamespace(extension), svc.GetName(), err.Error()),
}, false, nil
return nil, false, operator.Temporary(err, "Unable to get service")
}

if !svc.Equals(s) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -72,7 +72,7 @@ func Test_Handler_Destination_Service_Missing(t *testing.T) {
c, ok := extension.Status.Conditions.Get(networkingApi.DestinationValidCondition)
require.True(t, ok)
require.EqualValues(t, c.Reason, "Destination Not Found")
require.EqualValues(t, c.Message, "Unknown error for service `fake/deployment`: services \"deployment\" not found")
require.EqualValues(t, c.Message, "Service `fake/deployment` Not found")
}

func Test_Handler_Destination_Service_Valid(t *testing.T) {
Expand Down
14 changes: 7 additions & 7 deletions pkg/operatorV2/errors_reconcile.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2023-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,11 @@

package operator

import "fmt"
import (
"fmt"

"github.com/arangodb/kube-arangodb/pkg/util/errors"
)

func Reconcile(msg string, args ...interface{}) error {
return reconcile{
Expand All @@ -37,11 +41,7 @@ func (r reconcile) Error() string {
}

func IsReconcile(err error) bool {
if err == nil {
return false
}

if _, ok := err.(reconcile); ok {
if _, ok := errors.ExtractCause[reconcile](err); ok {
return true
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/operatorV2/errors_stop.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2023-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,11 @@

package operator

import "fmt"
import (
"fmt"

"github.com/arangodb/kube-arangodb/pkg/util/errors"
)

func Stop(msg string, args ...interface{}) error {
return stop{
Expand All @@ -37,11 +41,7 @@ func (r stop) Error() string {
}

func IsStop(err error) bool {
if err == nil {
return false
}

if _, ok := err.(stop); ok {
if _, ok := errors.ExtractCause[stop](err); ok {
return true
}

Expand Down
61 changes: 61 additions & 0 deletions pkg/operatorV2/errors_temporary.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// DISCLAIMER
//
// Copyright 2023-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package operator

import (
"github.com/arangodb/kube-arangodb/pkg/util/errors"
)

func Temporary(cause error, msg string, args ...interface{}) error {
if cause == nil {
return temporary{
cause: errors.Errorf(msg, args...),
}
}

return temporary{
cause: errors.Wrapf(cause, msg, args...),
}
}

type temporary struct {
cause error
}

func (t temporary) Error() string {
return t.cause.Error()
}

func (t temporary) Temporary() bool {
return true
}

func (t temporary) Cause() error {
return t.cause
}

func IsTemporary(err error) bool {
if _, ok := errors.ExtractCause[temporary](err); ok {
return true
}

return false
}
22 changes: 2 additions & 20 deletions pkg/util/errors/errors.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -55,7 +55,7 @@ func ExtractCause[T error](err error) (T, bool) {
var d T

if err == nil {
return d, true
return d, false
}

var v T
Expand All @@ -70,24 +70,6 @@ func ExtractCause[T error](err error) (T, bool) {
return d, false
}

func ExtractCauseHelper[T error](err error, extr func(err error) (T, bool)) (T, bool) {
var d T

if err == nil {
return d, true
}

if v, ok := extr(err); ok {
return v, true
}

if err := CauseWithNil(err); err != nil {
return ExtractCauseHelper[T](err, extr)
}

return d, false
}

func New(message string) error {
return errors.New(message)
}
Expand Down
Loading
0