Skip to content

Commit

Permalink
Merge branch 'release-0.17' into automated-backport-of-submariner-io#898
Browse files Browse the repository at this point in the history
-upstream-release-0.17
  • Loading branch information
tpantelis authored May 6, 2024
2 parents 0dab936 + 84fdf58 commit 3dbb3be
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ linters-settings:
- opinionated
- performance
- style
disabled-checks:
- ifElseChain
- unnamedResult
gocyclo:
min-complexity: 15
goheader:
Expand Down
13 changes: 13 additions & 0 deletions pkg/resource/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,16 @@ func IsNotFoundErr(err error) bool {

return false
}

func IsMissingNamespaceErr(err error) (bool, string) {
if !apierrors.IsNotFound(err) {
return false, ""
}

var status apierrors.APIStatus
_ = errors.As(err, &status)

d := status.Status().Details

return d != nil && d.Kind == "namespaces" && d.Group == "", d.Name
}
28 changes: 28 additions & 0 deletions pkg/resource/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,31 @@ var _ = Describe("IsNotFoundErr", func() {
})
})
})

var _ = Describe("IsMissingNamespaceErr", func() {
When("the error isn't NotFound", func() {
It("should return false", func() {
ok, _ := resource.IsMissingNamespaceErr(apierrors.NewBadRequest(""))
Expect(ok).To(BeFalse())
})
})

When("the error details specify a namespace", func() {
It("should return true and the name", func() {
ok, name := resource.IsMissingNamespaceErr(apierrors.NewNotFound(schema.GroupResource{
Resource: "namespaces",
}, "missing-ns"))
Expect(ok).To(BeTrue())
Expect(name).To(Equal("missing-ns"))
})
})

When("the error details does not specify a namespace", func() {
It("should return false", func() {
ok, _ := resource.IsMissingNamespaceErr(apierrors.NewNotFound(schema.GroupResource{
Resource: "pods",
}, "missing"))
Expect(ok).To(BeFalse())
})
})
})

0 comments on commit 3dbb3be

Please sign in to comment.