Skip to content

Commit 4229258

Browse files
authored
[Bugfix] Allow missing monitoring CRD (#985)
1 parent 5f283cd commit 4229258

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
44
- (Bugfix) Fix arangosync members state inspection
55
- (Feature) (ACS) Improve Reconciliation Loop
6+
- (Bugfix) Allow missing Monitoring CRD
67

78
## [1.2.12](https://github.com/arangodb/kube-arangodb/tree/1.2.12) (2022-05-10)
89
- (Feature) Add CoreV1 Endpoints Inspector

pkg/deployment/deployment.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ import (
6565
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
6666
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
6767
"github.com/arangodb/kube-arangodb/pkg/util/trigger"
68-
apierrors "k8s.io/apimachinery/pkg/api/errors"
6968
)
7069

7170
// Config holds configuration settings for a Deployment
@@ -593,7 +592,7 @@ func (d *Deployment) lookForServiceMonitorCRD() {
593592
var err error
594593
if d.GetScope().IsNamespaced() {
595594
_, err = d.currentState.ServiceMonitor().V1()
596-
if apierrors.IsForbidden(err) {
595+
if k8sutil.IsForbiddenOrNotFound(err) {
597596
return
598597
}
599598
} else {

pkg/deployment/resources/annotations.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
"github.com/rs/zerolog/log"
3838
core "k8s.io/api/core/v1"
3939
policy "k8s.io/api/policy/v1beta1"
40-
apierrors "k8s.io/apimachinery/pkg/api/errors"
4140
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
4241
)
4342

@@ -240,7 +239,7 @@ func ensurePvcsAnnotations(patch PatchFunc, cachedStatus inspectorInterface.Insp
240239
func ensureServiceMonitorsAnnotations(patch PatchFunc, cachedStatus inspectorInterface.Inspector, kind, name, namespace string, spec api.DeploymentSpec) error {
241240
i, err := cachedStatus.ServiceMonitor().V1()
242241
if err != nil {
243-
if apierrors.IsForbidden(err) {
242+
if k8sutil.IsForbiddenOrNotFound(err) {
244243
return nil
245244
}
246245
return err

pkg/deployment/resources/labels.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ import (
2626
"github.com/arangodb/kube-arangodb/pkg/util/globals"
2727

2828
"github.com/arangodb/kube-arangodb/pkg/util/errors"
29+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
2930
inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector"
3031
monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
3132
core "k8s.io/api/core/v1"
3233
policy "k8s.io/api/policy/v1beta1"
33-
apierrors "k8s.io/apimachinery/pkg/api/errors"
3434
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
3535
"k8s.io/apimachinery/pkg/types"
3636
)
@@ -152,7 +152,7 @@ func (r *Resources) EnsureServiceMonitorsLabels(ctx context.Context, cachedStatu
152152
changed := false
153153
i, err := cachedStatus.ServiceMonitor().V1()
154154
if err != nil {
155-
if apierrors.IsForbidden(err) {
155+
if k8sutil.IsForbiddenOrNotFound(err) {
156156
return nil
157157
}
158158
return err

pkg/util/k8sutil/errors.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,7 @@ func IsNotFound(err error) bool {
4848
func IsInvalid(err error) bool {
4949
return apierrors.IsInvalid(errors.Cause(err))
5050
}
51+
52+
func IsForbiddenOrNotFound(err error) bool {
53+
return apierrors.IsNotFound(err) || apierrors.IsForbidden(err)
54+
}

0 commit comments

Comments
 (0)