Skip to content

Commit

Permalink
[arkmq-org#900] Retry to detect OpenShift on failures
Browse files Browse the repository at this point in the history
  • Loading branch information
brusdev committed Apr 24, 2024
1 parent a66698b commit a44c87c
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions pkg/utils/common/auto_detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,21 @@ limitations under the License.
package common

import (
"time"

"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
"sigs.k8s.io/controller-runtime/pkg/manager"
)

const (
// defaultRetries is the number of times a resource discovery is retried
defaultRetries = 10

//defaultRetryInterval is the interval to wait before retring a resource discovery
defaultRetryInterval = 3 * time.Second
)

type AutoDetector struct {
dc discovery.DiscoveryInterface
}
Expand All @@ -37,12 +47,23 @@ func NewAutoDetect(mgr manager.Manager) (*AutoDetector, error) {

func (b *AutoDetector) DetectOpenshift() error {
stateManager := GetStateManager()
isOpenshift, err := discovery.IsResourceEnabled(b.dc,
schema.GroupVersionResource{
Group: "operator.openshift.io",
Version: "v1",
Resource: "openshiftapiservers",
})

var err error
var isOpenshift bool
for i := 0; i < defaultRetries; i++ {
isOpenshift, err = discovery.IsResourceEnabled(b.dc,
schema.GroupVersionResource{
Group: "operator.openshift.io",
Version: "v1",
Resource: "openshiftapiservers",
})

if err == nil {
break
}

time.Sleep(defaultRetryInterval)
}

if err != nil {
return err
Expand Down

0 comments on commit a44c87c

Please sign in to comment.