reorg: marking loadbalancer errors as debug

This commit is contained in:
Dario Tranchitella
2022-05-29 16:41:39 +00:00
parent 6b452ccd40
commit 8be787adc5
6 changed files with 42 additions and 5 deletions
+4 -3
View File
@@ -5,12 +5,13 @@ package v1alpha1
import (
"context"
"fmt"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
kamajierrors "github.com/clastix/kamaji/internal/errors"
)
func (in *TenantControlPlane) GetAddress(ctx context.Context, client client.Client) (string, error) {
@@ -29,7 +30,7 @@ func (in *TenantControlPlane) GetAddress(ctx context.Context, client client.Clie
case svc.Spec.Type == corev1.ServiceTypeLoadBalancer:
loadBalancerStatus = svc.Status.LoadBalancer
if len(loadBalancerStatus.Ingress) == 0 {
return "", fmt.Errorf("cannot retrieve the TenantControlPlane address, Service resource is not yet exposed as LoadBalancer")
return "", kamajierrors.NonExposedLoadBalancerError{}
}
for _, lb := range loadBalancerStatus.Ingress {
@@ -39,5 +40,5 @@ func (in *TenantControlPlane) GetAddress(ctx context.Context, client client.Clie
}
}
return "", fmt.Errorf("the actual resource doesn't have yet a valid IP address")
return "", kamajierrors.MissingValidIPError{}
}
@@ -21,7 +21,7 @@ spec:
labels:
tenant.clastix.io: test
kind.clastix.io: service
serviceType: ClusterIP
serviceType: LoadBalancer
ingress:
enabled: true
hostname: kamaji.local
@@ -21,6 +21,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"
kamajiv1alpha1 "github.com/clastix/kamaji/api/v1alpha1"
kamajierrors "github.com/clastix/kamaji/internal/errors"
"github.com/clastix/kamaji/internal/resources"
)
@@ -259,6 +260,12 @@ func (r *TenantControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.R
for _, resource := range registeredResources {
result, err := resources.Handle(ctx, resource, tenantControlPlane)
if err != nil {
if kamajierrors.ShouldReconcileErrorBeIgnored(err) {
log.V(1).Info("sentinel error, enqueuing back request", "error", err.Error())
return ctrl.Result{Requeue: true}, nil
}
return ctrl.Result{}, err
}
+4 -1
View File
@@ -10,6 +10,10 @@ nodes:
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
## required for Cluster API local development
extraMounts:
- hostPath: /var/run/docker.sock
containerPath: /var/run/docker.sock
extraPortMappings:
## expose port 80 of the node to port 80 on the host
- containerPort: 80
@@ -27,4 +31,3 @@ nodes:
- containerPort: 6443
hostPort: 8443
protocol: TCP
+16
View File
@@ -0,0 +1,16 @@
// Copyright 2022 Clastix Labs
// SPDX-License-Identifier: Apache-2.0
package errors
type NonExposedLoadBalancerError struct{}
func (n NonExposedLoadBalancerError) Error() string {
return "cannot retrieve the TenantControlPlane address, Service resource is not yet exposed as LoadBalancer"
}
type MissingValidIPError struct{}
func (m MissingValidIPError) Error() string {
return "the actual resource doesn't have yet a valid IP address"
}
+10
View File
@@ -0,0 +1,10 @@
// Copyright 2022 Clastix Labs
// SPDX-License-Identifier: Apache-2.0
package errors
import "github.com/pkg/errors"
func ShouldReconcileErrorBeIgnored(err error) bool {
return errors.As(err, &NonExposedLoadBalancerError{}) || errors.As(err, &MissingValidIPError{})
}