Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
Signed-off-by: Pushpalanka Jayawardhana <pushpalanka.jayawardhana@zalando.de>
  • Loading branch information
Pushpalanka committed Jul 21, 2024
1 parent 6356fbe commit fc89516
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions plugins/bundle/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Plugin struct {
// New returns a new Plugin with the given config.
func New(parsedConfig *Config, manager *plugins.Manager) *Plugin {
initialStatus := map[string]*Status{}

for name := range parsedConfig.Bundles {
initialStatus[name] = &Status{
Name: name,
Expand All @@ -79,17 +80,14 @@ func New(parsedConfig *Config, manager *plugins.Manager) *Plugin {

p := &Plugin{
manager: manager,
config: *parsedConfig,
status: initialStatus,
downloaders: make(map[string]Loader),
etags: make(map[string]string),
ready: false,
logger: manager.Logger(),
}

p.cfgMtx.Lock()
p.config = *parsedConfig
p.cfgMtx.Unlock()

manager.UpdatePluginStatus(Name, &plugins.Status{State: plugins.StateNotReady})
return p
}
Expand Down Expand Up @@ -217,10 +215,7 @@ func (p *Plugin) Reconfigure(ctx context.Context, config interface{}) {
readyNow := p.ready

p.cfgMtx.RLock()
bundles := p.config.Bundles
p.cfgMtx.RUnlock()

for name, source := range bundles {
for name, source := range p.config.Bundles {
_, updated := updatedBundles[name]
_, isNew := newBundles[name]

Expand All @@ -244,6 +239,7 @@ func (p *Plugin) Reconfigure(ctx context.Context, config interface{}) {
readyNow = false
}
}
p.cfgMtx.RUnlock()

if !readyNow {
p.ready = false
Expand Down Expand Up @@ -363,10 +359,7 @@ func (p *Plugin) loadAndActivateBundlesFromDisk(ctx context.Context) {
persistedBundles := map[string]*bundle.Bundle{}

p.cfgMtx.RLock()
bundles := p.config.Bundles
p.cfgMtx.RUnlock()

for name, src := range bundles {
for name, src := range p.config.Bundles {
if p.persistBundle(name) {
b, err := p.loadBundleFromDisk(p.bundlePersistPath, name, src)
if err != nil {
Expand All @@ -382,6 +375,7 @@ func (p *Plugin) loadAndActivateBundlesFromDisk(ctx context.Context) {
persistedBundles[name] = b
}
}
p.cfgMtx.RUnlock()

if len(persistedBundles) == 0 {
return
Expand Down

0 comments on commit fc89516

Please sign in to comment.