Skip to content

Commit

Permalink
[API change] reload (updated) backend creds
Browse files Browse the repository at this point in the history
* part three, prev. commit: 867157b

Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Dec 20, 2024
1 parent 4607598 commit 165c8d3
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
13 changes: 13 additions & 0 deletions ais/prxclu.go
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,19 @@ func (p *proxy) cluputMsg(w http.ResponseWriter, r *http.Request) {
p.xstop(w, r, msg)

case apc.ActReloadBackendCreds:
if msg.Name != "" {
normp := apc.NormalizeProvider(msg.Name)
if !apc.IsCloudProvider(normp) {
p.writeErrf(w, r, "cannot reload %q creds: not a Cloud provider", msg.Name)
return
}
config := cmn.GCO.Get()
if config.Backend.Get(normp) == nil {
p.writeErr(w, r, &cmn.ErrMissingBackend{Provider: msg.Name})
return
}
msg.Name = normp
}
p.reloadCreds(w, r, msg)

// internal
Expand Down
4 changes: 4 additions & 0 deletions ais/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ func (t *target) initBuiltTagged(tstats *stats.Trunner, config *cmn.Config) erro
case err == nil && !configured:
disabled = append(disabled, provider)
case err != nil && configured:
if !cmn.IsErrInitMissingBackend(err) {
// as is
return fmt.Errorf("%s: failed to initialize [%s] backend, err: %v", t, provider, err)
}
notlinked = append(notlinked, provider)
case err != nil && !configured:
_, ok := err.(*cmn.ErrInitBackend) // error type to indicate a _mock_ backend
Expand Down
28 changes: 26 additions & 2 deletions ais/tgtcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,34 @@ func (t *target) daeputMsg(w http.ResponseWriter, r *http.Request) {
errorsOnly := msg.Value.(bool)
t.statsT.ResetStats(errorsOnly)
case apc.ActReloadBackendCreds:
debug.Assert(msg.Name == "", "reloading specific provider not yet supported")
if err := t.initBuiltTagged(t.statsT.(*stats.Trunner), cmn.GCO.Get()); err != nil {
var (
tstats = t.statsT.(*stats.Trunner)
provider = msg.Name
)
if provider == "" { // all
if err := t.initBuiltTagged(t.statsT.(*stats.Trunner), cmn.GCO.Get()); err != nil {
t.writeErr(w, r, err)
}
return
}

// one
var add core.Backend
switch provider {
case apc.AWS:
add, err = backend.NewAWS(t, tstats)
case apc.GCP:
add, err = backend.NewGCP(t, tstats)
case apc.Azure:
add, err = backend.NewAzure(t, tstats)
case apc.OCI:
add, err = backend.NewOCI(t, tstats)
}
if err != nil {
t.writeErr(w, r, err)
return
}
t.backend[provider] = add
case apc.ActStartMaintenance:
if !t.ensureIntraControl(w, r, true /* from primary */) {
return
Expand Down
8 changes: 8 additions & 0 deletions cmn/err.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,14 @@ func (e *ErrMissingBackend) Error() string {
return apc.DisplayProvider(e.Provider) + " backend is missing in the cluster configuration"
}

func IsErrInitMissingBackend(err error) bool {
_, ok := err.(*ErrInitBackend)
if !ok {
_, ok = err.(*ErrMissingBackend)
}
return ok
}

// ErrETL

func NewErrETL(ctx *ETLErrCtx, msg string) *ErrETL {
Expand Down

0 comments on commit 165c8d3

Please sign in to comment.