Skip to content

Commit

Permalink
fix: when deploy emqx enterprise, default load emqx_modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Rory-Z committed Jun 7, 2022
1 parent 0b8ed7b commit 19cf603
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion apis/apps/v1beta1/emqxbroker_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (r *EmqxBroker) Default() {
plugins := &v1beta2.Plugins{
Items: r.Spec.Plugins,
}
plugins.Default()
plugins.Default(&v1beta2.EmqxBroker{})
if r.Spec.TelegrafTemplate != nil {
_, index := plugins.Lookup("emqx_prometheus")
if index == -1 {
Expand Down
2 changes: 1 addition & 1 deletion apis/apps/v1beta1/emqxenterprise_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (r *EmqxEnterprise) Default() {
plugins := &v1beta2.Plugins{
Items: r.Spec.Plugins,
}
plugins.Default()
plugins.Default(&v1beta2.EmqxEnterprise{})
r.Spec.Plugins = plugins.Items

modules := &v1beta2.EmqxEnterpriseModulesList{
Expand Down
2 changes: 1 addition & 1 deletion apis/apps/v1beta2/emqxbroker_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (r *EmqxBroker) Default() {
plugins := &Plugins{
Items: r.Spec.EmqxTemplate.Plugins,
}
plugins.Default()
plugins.Default(r)
r.Spec.EmqxTemplate.Plugins = plugins.Items

modules := &EmqxBrokerModulesList{
Expand Down
2 changes: 1 addition & 1 deletion apis/apps/v1beta2/emqxenterprise_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (r *EmqxEnterprise) Default() {
plugins := &Plugins{
Items: r.Spec.EmqxTemplate.Plugins,
}
plugins.Default()
plugins.Default(r)
r.Spec.EmqxTemplate.Plugins = plugins.Items

modules := &EmqxEnterpriseModulesList{
Expand Down
6 changes: 5 additions & 1 deletion apis/apps/v1beta2/plugins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestPluginsDefault(t *testing.T) {
},
}

plugins.Default()
plugins.Default(&v1beta2.EmqxEnterprise{})
assert.ElementsMatch(t, plugins.Items,
[]v1beta2.Plugin{
{
Expand All @@ -36,6 +36,10 @@ func TestPluginsDefault(t *testing.T) {
Name: "emqx_management",
Enable: true,
},
{
Name: "emqx_modules",
Enable: true,
},
},
)
}
Expand Down
18 changes: 12 additions & 6 deletions apis/apps/v1beta2/plugins_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type Plugins struct {
Items []Plugin
}

func (p *Plugins) Default() {
defultPlugins := []Plugin{
func (p *Plugins) Default(emqx Emqx) {
defaultPlugins := []Plugin{
{
Name: "emqx_management",
Enable: true,
Expand All @@ -41,12 +41,18 @@ func (p *Plugins) Default() {
},
}
if p.Items == nil {
p.Items = defultPlugins
p.Items = defaultPlugins
} else {
if _, index := p.Lookup("emqx_management"); index == -1 {
p.Items = append(p.Items, Plugin{Name: "emqx_management", Enable: true})
}
}
_, index := p.Lookup("emqx_management")
if index == -1 {
p.Items = append(p.Items, Plugin{Name: "emqx_management", Enable: true})
if _, ok := emqx.(*EmqxEnterprise); ok {
if _, index := p.Lookup("emqx_modules"); index == -1 {
p.Items = append(p.Items, Plugin{Name: "emqx_modules", Enable: true})
}
}

}

func (p *Plugins) Lookup(name string) (*Plugin, int) {
Expand Down

0 comments on commit 19cf603

Please sign in to comment.