Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick fixes #1398

Merged
merged 4 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/botkube-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,12 @@ func run(ctx context.Context) (err error) {
)
errGroup.Go(func() error {
defer analytics.ReportPanicIfOccurs(logger, analyticsReporter)
return upgradeChecker.Run(ctx)
err := upgradeChecker.Run(ctx)
if err != nil {
// we ignore error to make sure that upgrade checker does not stop the agent
logger.WithError(err).Errorf("Failed to notify about upgrade")
}
return nil
})
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ require (
google.golang.org/protobuf v1.31.0
gopkg.in/yaml.v3 v3.0.1
gotest.tools/v3 v3.5.1
helm.sh/helm/v3 v3.14.1
helm.sh/helm/v3 v3.14.2
k8s.io/api v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/cli-runtime v0.29.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1832,8 +1832,8 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o=
helm.sh/helm/v3 v3.14.1 h1:4AwRLx+wfzlPtvrsbDmWP5PUokGmf9/nAmEdk21vae8=
helm.sh/helm/v3 v3.14.1/go.mod h1:2itvvDv2WSZXTllknfQo6j7u3VVgMAvm8POCDgYH424=
helm.sh/helm/v3 v3.14.2 h1:V71fv+NGZv0icBlr+in1MJXuUIHCiPG1hW9gEBISTIA=
helm.sh/helm/v3 v3.14.2/go.mod h1:2itvvDv2WSZXTllknfQo6j7u3VVgMAvm8POCDgYH424=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
27 changes: 21 additions & 6 deletions internal/analytics/segment_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/kubeshop/botkube/internal/analytics/batched"
"github.com/kubeshop/botkube/pkg/config"
"github.com/kubeshop/botkube/pkg/maputil"
"github.com/kubeshop/botkube/pkg/plugin"
"github.com/kubeshop/botkube/pkg/ptr"
"github.com/kubeshop/botkube/pkg/version"
Expand Down Expand Up @@ -116,11 +117,15 @@ func (r *SegmentReporter) ReportBotEnabled(platform config.CommPlatformIntegrati
// ReportPluginsEnabled reports plugins enabled.
func (r *SegmentReporter) ReportPluginsEnabled(executors map[string]config.Executors, sources map[string]config.Sources) error {
pluginsConfig := make(map[string]interface{})
for _, values := range executors {
r.generatePluginsReport(pluginsConfig, values.Plugins, plugin.TypeExecutor)

executorKeys := maputil.SortKeys(executors)
for i, key := range executorKeys {
r.generatePluginsReport(i, pluginsConfig, executors[key].Plugins, plugin.TypeExecutor)
}
for _, values := range sources {
r.generatePluginsReport(pluginsConfig, values.Plugins, plugin.TypeSource)

sourceKeys := maputil.SortKeys(sources)
for i, key := range sourceKeys {
r.generatePluginsReport(i, pluginsConfig, sources[key].Plugins, plugin.TypeSource)
}
return r.reportEvent("Plugin enabled", pluginsConfig)
}
Expand Down Expand Up @@ -353,12 +358,18 @@ func (r *SegmentReporter) getNodeCount(ctx context.Context, k8sCli kubernetes.In
return workerNodesCount, controlPlaneNodesCount, nil
}

func (r *SegmentReporter) generatePluginsReport(pluginsConfig map[string]interface{}, plugins config.Plugins, pluginType plugin.Type) {
func (r *SegmentReporter) generatePluginsReport(cfgGroupIdx int, pluginsConfig map[string]interface{}, plugins config.Plugins, pluginType plugin.Type) {
for name, pluginValue := range plugins {
if !pluginValue.Enabled {
continue
}
pluginsConfig[name] = pluginReport{

key := name
if _, exists := pluginsConfig[name]; exists {
key = fmt.Sprintf("%s-%d", name, cfgGroupIdx)
}

pluginsConfig[key] = pluginReport{
Name: name,
Type: pluginType,
RBAC: r.getAnonymizedRBAC(pluginValue.Context.RBAC),
Expand All @@ -367,6 +378,10 @@ func (r *SegmentReporter) generatePluginsReport(pluginsConfig map[string]interfa
}

func (r *SegmentReporter) getAnonymizedRBAC(rbac *config.PolicyRule) *config.PolicyRule {
if rbac == nil {
return nil
}

rbac.Group.Prefix = r.anonymizedValue(rbac.Group.Prefix)
for key, name := range rbac.Group.Static.Values {
rbac.Group.Static.Values[key] = r.anonymizedValue(name)
Expand Down
24 changes: 24 additions & 0 deletions internal/analytics/segment_reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ func TestSegmentReporter_ReportPluginsEnabled(t *testing.T) {
},
},
},
"botkube/kubectl_2": {
DisplayName: "kubectl",
Plugins: map[string]config.Plugin{
"botkube/kubectl": {
Enabled: true,
Config: "{}",
Context: config.PluginContext{
RBAC: nil,
},
},
},
},
}, map[string]config.Sources{
"botkube/kubernetes_22yy2": {
DisplayName: "k8s",
Expand Down Expand Up @@ -270,6 +282,18 @@ func TestSegmentReporter_ReportPluginsEnabled(t *testing.T) {
},
},
},
"botkube/kubernetes_2": {
DisplayName: "kubernetes",
Plugins: map[string]config.Plugin{
"botkube/kubernetes": {
Enabled: true,
Config: "{}",
Context: config.PluginContext{
RBAC: nil,
},
},
},
},
})
require.NoError(t, err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
}
},
"botkube/kubectl": {
"Name": "botkube/kubectl",
"Type": "executor",
"RBAC": null
},
"botkube/kubectl-2": {
"Name": "botkube/kubectl",
"Type": "executor",
"RBAC": {
Expand All @@ -50,6 +55,11 @@
}
},
"botkube/kubernetes": {
"Name": "botkube/kubernetes",
"Type": "source",
"RBAC": null
},
"botkube/kubernetes-2": {
"Name": "botkube/kubernetes",
"Type": "source",
"RBAC": {
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/bots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1256,10 +1256,10 @@ func runBotTest(t *testing.T,
command := "list executors"

expectedBody := codeBlock(heredoc.Doc(`
EXECUTOR ENABLED ALIASES RESTARTS STATUS LAST_RESTART
botkube/echo@v0.0.0-latest true e 0/1 Running
botkube/kubectl true k, kc 0/1 Running
botkubeCloud/helm true 0/1 Running`))
EXECUTOR ENABLED ALIASES RESTARTS STATUS LAST_RESTART
botkube/echo true e 0/1 Running
botkube/kubectl true k, kc 0/1 Running
botkubeCloud/helm true 0/1 Running`))

if botDriver.Type() == commplatform.DiscordBot {
// Cloud plugins are not tested on Discord
Expand Down
Loading