chore(pkger): handle edge cases for telegraf configs that manifest from user interaction
closes: #17434pull/18002/head
parent
3eb5af969a
commit
37d44d882d
|
@ -3,7 +3,8 @@
|
|||
### Features
|
||||
|
||||
1. [17934](https://github.com/influxdata/influxdb/pull/17934): Add ability to delete a stack and all the resources associated with it
|
||||
1. [17941](https://github.com/influxdata/influxdb/pull/17941): Encorce dns name compliance on all pkger resources' metadata.name field
|
||||
1. [17941](https://github.com/influxdata/influxdb/pull/17941): Enforce DNS name compliance on all pkger resources' metadata.name field
|
||||
1. [17989](https://github.com/influxdata/influxdb/pull/17989): Add stateful pkg management with stacks
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
|
|
|
@ -1361,6 +1361,42 @@ func TestLauncher_Pkger(t *testing.T) {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("when a user has deleted a telegraf config that was previously created by a stack", func(t *testing.T) {
|
||||
testUserDeletedTelegraf := func(t *testing.T, actionFn func(t *testing.T, stackID influxdb.ID, initialObj pkger.Object, initialSum pkger.Summary)) {
|
||||
t.Helper()
|
||||
|
||||
obj := newTelegrafObject("tele-1", "", "")
|
||||
stackID, cleanup, initialSum := initializeStackPkg(t, newPkg(obj))
|
||||
defer cleanup()
|
||||
|
||||
require.Len(t, initialSum.TelegrafConfigs, 1)
|
||||
require.NotZero(t, initialSum.TelegrafConfigs[0].TelegrafConfig.ID)
|
||||
resourceCheck.mustDeleteTelegrafConfig(t, initialSum.TelegrafConfigs[0].TelegrafConfig.ID)
|
||||
|
||||
actionFn(t, stackID, obj, initialSum)
|
||||
}
|
||||
|
||||
t.Run("should create new resource when attempting to update", func(t *testing.T) {
|
||||
testUserDeletedTelegraf(t, func(t *testing.T, stackID influxdb.ID, initialObj pkger.Object, initialSum pkger.Summary) {
|
||||
pkg := newPkg(initialObj)
|
||||
updateSum, _, err := svc.Apply(ctx, l.Org.ID, l.User.ID, pkg, pkger.ApplyWithStackID(stackID))
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, updateSum.TelegrafConfigs, 1)
|
||||
initial, updated := initialSum.TelegrafConfigs[0].TelegrafConfig, updateSum.TelegrafConfigs[0].TelegrafConfig
|
||||
assert.NotEqual(t, initial.ID, updated.ID)
|
||||
initial.ID, updated.ID = 0, 0
|
||||
assert.Equal(t, initial, updated)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("should not error when attempting to remove", func(t *testing.T) {
|
||||
testUserDeletedTelegraf(t, func(t *testing.T, stackID influxdb.ID, _ pkger.Object, _ pkger.Summary) {
|
||||
testValidRemoval(t, stackID)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -3098,6 +3134,12 @@ func (r resourceChecker) mustGetTelegrafConfig(t *testing.T, getOpt getResourceO
|
|||
return tele
|
||||
}
|
||||
|
||||
func (r resourceChecker) mustDeleteTelegrafConfig(t *testing.T, id influxdb.ID) {
|
||||
t.Helper()
|
||||
|
||||
require.NoError(t, r.tl.TelegrafService(t).DeleteTelegrafConfig(ctx, id))
|
||||
}
|
||||
|
||||
func (r resourceChecker) getVariable(t *testing.T, getOpt getResourceOptFn) (influxdb.Variable, error) {
|
||||
t.Helper()
|
||||
|
||||
|
|
|
@ -2340,13 +2340,16 @@ func (s *Service) applyTelegrafs(ctx context.Context, userID influxdb.ID, teles
|
|||
}
|
||||
|
||||
func (s *Service) applyTelegrafConfig(ctx context.Context, userID influxdb.ID, t *stateTelegraf) (influxdb.TelegrafConfig, error) {
|
||||
switch t.stateStatus {
|
||||
case StateStatusRemove:
|
||||
switch {
|
||||
case IsRemoval(t.stateStatus):
|
||||
if err := s.teleSVC.DeleteTelegrafConfig(ctx, t.ID()); err != nil {
|
||||
if influxdb.ErrorCode(err) == influxdb.ENotFound {
|
||||
return influxdb.TelegrafConfig{}, nil
|
||||
}
|
||||
return influxdb.TelegrafConfig{}, ierrors.Wrap(err, "failed to delete config")
|
||||
}
|
||||
return *t.existing, nil
|
||||
case StateStatusExists:
|
||||
case IsExisting(t.stateStatus) && t.existing != nil:
|
||||
cfg := t.summarize().TelegrafConfig
|
||||
updatedConfig, err := s.teleSVC.UpdateTelegrafConfig(ctx, t.ID(), &cfg, userID)
|
||||
if err != nil {
|
||||
|
@ -2365,6 +2368,10 @@ func (s *Service) applyTelegrafConfig(ctx context.Context, userID influxdb.ID, t
|
|||
|
||||
func (s *Service) rollbackTelegrafConfigs(ctx context.Context, userID influxdb.ID, cfgs []*stateTelegraf) error {
|
||||
rollbackFn := func(t *stateTelegraf) error {
|
||||
if !IsNew(t.stateStatus) && t.existing == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
switch t.stateStatus {
|
||||
case StateStatusRemove:
|
||||
|
|
Loading…
Reference in New Issue