Skip to content

Commit 9433fc6

Browse files
committed
add checks for image access mode to poll
1 parent 8650b33 commit 9433fc6

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

internal/pkg/rpa/main.go

+25-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"io/ioutil"
1212
"net/http"
1313
"os"
14-
"strconv"
1514
"time"
1615

1716
log "github.com/sirupsen/logrus"
@@ -49,11 +48,11 @@ func (a *App) apiRequest(method, url string, data io.Reader) ([]byte, int) {
4948
log.Fatal(err)
5049
}
5150

52-
log.WithFields(log.Fields{
53-
"method": method,
54-
"statusCode": strconv.Itoa(resp.StatusCode),
55-
"body": string(body),
56-
}).Debug(url)
51+
// log.WithFields(log.Fields{
52+
// "method": method,
53+
// "statusCode": strconv.Itoa(resp.StatusCode),
54+
// "body": string(body),
55+
// }).Debug(url)
5756

5857
return body, resp.StatusCode
5958
}
@@ -262,6 +261,8 @@ func (a *App) pollImageAccessEnabled(groupID int, stateDesired bool) {
262261
groupCopiesSettings := a.getGroupCopiesSettings(groupID)
263262
copySettings := a.getRequestedCopy(groupCopiesSettings)
264263
for copySettings.ImageAccessInformation.ImageAccessEnabled != stateDesired {
264+
log.Debug("current image access enabled: ", copySettings.ImageAccessInformation.ImageAccessEnabled)
265+
log.Debug("current image logged access mode: ", copySettings.ImageAccessInformation.ImageInformation.Mode)
265266
time.Sleep(time.Duration(pollDelay) * time.Second)
266267
groupCopiesSettings = a.getGroupCopiesSettings(groupID)
267268
copySettings = a.getRequestedCopy(groupCopiesSettings)
@@ -271,6 +272,24 @@ func (a *App) pollImageAccessEnabled(groupID int, stateDesired bool) {
271272
}
272273
pollCount++
273274
}
275+
if stateDesired == true {
276+
// if the desired state is to have image access == true, we should also
277+
// ensure that logged access is also set before continuing.
278+
for copySettings.ImageAccessInformation.ImageInformation.Mode != "LOGGED_ACCESS" {
279+
log.Debug("current image access enabled: ", copySettings.ImageAccessInformation.ImageAccessEnabled)
280+
log.Debug("current image logged access mode: ", copySettings.ImageAccessInformation.ImageInformation.Mode)
281+
time.Sleep(time.Duration(pollDelay) * time.Second)
282+
groupCopiesSettings = a.getGroupCopiesSettings(groupID)
283+
copySettings = a.getRequestedCopy(groupCopiesSettings)
284+
if pollCount > pollMax {
285+
fmt.Println("Maximum poll count reached while waiting for logged access")
286+
break
287+
}
288+
pollCount++
289+
}
290+
}
291+
log.Debug("current image access enabled: ", copySettings.ImageAccessInformation.ImageAccessEnabled)
292+
log.Debug("current image logged access mode: ", copySettings.ImageAccessInformation.ImageInformation.Mode)
274293
}
275294

276295
func (a *App) directAccess(t Task) error {

internal/pkg/rpa/model.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,13 @@ type ClusterUID struct {
103103

104104
// ImageAccessInformation holds the boolean imageAccessEnabled within groupCopiesSettings
105105
type ImageAccessInformation struct {
106-
ImageAccessEnabled bool `json:"imageAccessEnabled"`
106+
ImageAccessEnabled bool `json:"imageAccessEnabled"`
107+
ImageInformation ImageInformation `json:"imageInformation"`
108+
}
109+
110+
// ImageInformation holds the image information found within ImageAccessInformation
111+
type ImageInformation struct {
112+
Mode string `json:"mode"`
107113
}
108114

109115
// RoleInfo holds the 'ACTIVE/REPLICA' json string roleInfo within groupCopiesSettings

0 commit comments

Comments
 (0)