Skip to content

Commit

Permalink
add checks for image access mode to poll
Browse files Browse the repository at this point in the history
  • Loading branch information
bcambl committed Jul 7, 2020
1 parent 8650b33 commit 9433fc6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
31 changes: 25 additions & 6 deletions internal/pkg/rpa/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"io/ioutil"
"net/http"
"os"
"strconv"
"time"

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

log.WithFields(log.Fields{
"method": method,
"statusCode": strconv.Itoa(resp.StatusCode),
"body": string(body),
}).Debug(url)
// log.WithFields(log.Fields{
// "method": method,
// "statusCode": strconv.Itoa(resp.StatusCode),
// "body": string(body),
// }).Debug(url)

return body, resp.StatusCode
}
Expand Down Expand Up @@ -262,6 +261,8 @@ func (a *App) pollImageAccessEnabled(groupID int, stateDesired bool) {
groupCopiesSettings := a.getGroupCopiesSettings(groupID)
copySettings := a.getRequestedCopy(groupCopiesSettings)
for copySettings.ImageAccessInformation.ImageAccessEnabled != stateDesired {
log.Debug("current image access enabled: ", copySettings.ImageAccessInformation.ImageAccessEnabled)
log.Debug("current image logged access mode: ", copySettings.ImageAccessInformation.ImageInformation.Mode)
time.Sleep(time.Duration(pollDelay) * time.Second)
groupCopiesSettings = a.getGroupCopiesSettings(groupID)
copySettings = a.getRequestedCopy(groupCopiesSettings)
Expand All @@ -271,6 +272,24 @@ func (a *App) pollImageAccessEnabled(groupID int, stateDesired bool) {
}
pollCount++
}
if stateDesired == true {
// if the desired state is to have image access == true, we should also
// ensure that logged access is also set before continuing.
for copySettings.ImageAccessInformation.ImageInformation.Mode != "LOGGED_ACCESS" {
log.Debug("current image access enabled: ", copySettings.ImageAccessInformation.ImageAccessEnabled)
log.Debug("current image logged access mode: ", copySettings.ImageAccessInformation.ImageInformation.Mode)
time.Sleep(time.Duration(pollDelay) * time.Second)
groupCopiesSettings = a.getGroupCopiesSettings(groupID)
copySettings = a.getRequestedCopy(groupCopiesSettings)
if pollCount > pollMax {
fmt.Println("Maximum poll count reached while waiting for logged access")
break
}
pollCount++
}
}
log.Debug("current image access enabled: ", copySettings.ImageAccessInformation.ImageAccessEnabled)
log.Debug("current image logged access mode: ", copySettings.ImageAccessInformation.ImageInformation.Mode)
}

func (a *App) directAccess(t Task) error {
Expand Down
8 changes: 7 additions & 1 deletion internal/pkg/rpa/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ type ClusterUID struct {

// ImageAccessInformation holds the boolean imageAccessEnabled within groupCopiesSettings
type ImageAccessInformation struct {
ImageAccessEnabled bool `json:"imageAccessEnabled"`
ImageAccessEnabled bool `json:"imageAccessEnabled"`
ImageInformation ImageInformation `json:"imageInformation"`
}

// ImageInformation holds the image information found within ImageAccessInformation
type ImageInformation struct {
Mode string `json:"mode"`
}

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

0 comments on commit 9433fc6

Please sign in to comment.