diff --git a/CHANGELOG.md b/CHANGELOG.md index 2935936cf..0f42e7ea4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A) - (Bugfix) Fix arangosync members state inspection - (Feature) (ACS) Improve Reconciliation Loop +- (Bugfix) Allow missing Monitoring CRD ## [1.2.12](https://github.com/arangodb/kube-arangodb/tree/1.2.12) (2022-05-10) - (Feature) Add CoreV1 Endpoints Inspector diff --git a/pkg/deployment/deployment.go b/pkg/deployment/deployment.go index 52baba813..99919ef1d 100644 --- a/pkg/deployment/deployment.go +++ b/pkg/deployment/deployment.go @@ -65,7 +65,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" "github.com/arangodb/kube-arangodb/pkg/util/kclient" "github.com/arangodb/kube-arangodb/pkg/util/trigger" - apierrors "k8s.io/apimachinery/pkg/api/errors" ) // Config holds configuration settings for a Deployment @@ -593,7 +592,7 @@ func (d *Deployment) lookForServiceMonitorCRD() { var err error if d.GetScope().IsNamespaced() { _, err = d.currentState.ServiceMonitor().V1() - if apierrors.IsForbidden(err) { + if k8sutil.IsForbiddenOrNotFound(err) { return } } else { diff --git a/pkg/deployment/resources/annotations.go b/pkg/deployment/resources/annotations.go index 1f3b077e8..1478c7464 100644 --- a/pkg/deployment/resources/annotations.go +++ b/pkg/deployment/resources/annotations.go @@ -37,7 +37,6 @@ import ( "github.com/rs/zerolog/log" core "k8s.io/api/core/v1" policy "k8s.io/api/policy/v1beta1" - apierrors "k8s.io/apimachinery/pkg/api/errors" meta "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -240,7 +239,7 @@ func ensurePvcsAnnotations(patch PatchFunc, cachedStatus inspectorInterface.Insp func ensureServiceMonitorsAnnotations(patch PatchFunc, cachedStatus inspectorInterface.Inspector, kind, name, namespace string, spec api.DeploymentSpec) error { i, err := cachedStatus.ServiceMonitor().V1() if err != nil { - if apierrors.IsForbidden(err) { + if k8sutil.IsForbiddenOrNotFound(err) { return nil } return err diff --git a/pkg/deployment/resources/labels.go b/pkg/deployment/resources/labels.go index 163520be1..9dffd976f 100644 --- a/pkg/deployment/resources/labels.go +++ b/pkg/deployment/resources/labels.go @@ -26,11 +26,11 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/errors" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" core "k8s.io/api/core/v1" policy "k8s.io/api/policy/v1beta1" - apierrors "k8s.io/apimachinery/pkg/api/errors" meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" ) @@ -152,7 +152,7 @@ func (r *Resources) EnsureServiceMonitorsLabels(ctx context.Context, cachedStatu changed := false i, err := cachedStatus.ServiceMonitor().V1() if err != nil { - if apierrors.IsForbidden(err) { + if k8sutil.IsForbiddenOrNotFound(err) { return nil } return err diff --git a/pkg/util/k8sutil/errors.go b/pkg/util/k8sutil/errors.go index 496aa44ad..291c6db7a 100644 --- a/pkg/util/k8sutil/errors.go +++ b/pkg/util/k8sutil/errors.go @@ -48,3 +48,7 @@ func IsNotFound(err error) bool { func IsInvalid(err error) bool { return apierrors.IsInvalid(errors.Cause(err)) } + +func IsForbiddenOrNotFound(err error) bool { + return apierrors.IsNotFound(err) || apierrors.IsForbidden(err) +}