Skip to content

Commit

Permalink
chore: the monitoring components need to be disabled when installing …
Browse files Browse the repository at this point in the history
…Kubeblocks (#4004)
  • Loading branch information
runsun authored Jun 28, 2023
1 parent c255937 commit 8a67cf6
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 36 deletions.
2 changes: 1 addition & 1 deletion cmd/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const (
podRunningTimeoutFlag = "pod-running-timeout"
defaultPodExecTimeout = 60 * time.Second
grafanaAddonName = "kubeblocks-grafana"
lokiAddonName = "kubeblocks-loki"
lokiAddonName = "kubeblocks-logs"
lokiGrafanaDirect = "container-logs"
localAdd = "127.0.0.1"
)
Expand Down
1 change: 0 additions & 1 deletion cmd/kubeblocks/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ var _ = Describe("backupconfig", func() {
Dynamic: testing.FakeDynamicClient(),
},
Version: version.DefaultKubeBlocksVersion,
Monitor: true,
ValueOpts: values.Options{Values: []string{"snapshot-controller.enabled=true"}},
}
})
Expand Down
17 changes: 0 additions & 17 deletions cmd/kubeblocks/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import (
)

const (
kMonitorParam = "prometheus.enabled=%[1]t,grafana.enabled=%[1]t"
kNodeAffinity = "affinity.nodeAffinity=%s"
kPodAntiAffinity = "affinity.podAntiAffinity=%s"
kTolerations = "tolerations=%s"
Expand All @@ -76,7 +75,6 @@ type Options struct {
type InstallOptions struct {
Options
Version string
Monitor bool
Quiet bool
CreateNamespace bool
Check bool
Expand Down Expand Up @@ -142,7 +140,6 @@ func newInstallCmd(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobr
},
}

cmd.Flags().BoolVar(&o.Monitor, "monitor", true, "Auto install monitoring add-ons including prometheus, grafana and alertmanager-webhook-adaptor")
cmd.Flags().StringVar(&o.Version, "version", version.DefaultKubeBlocksVersion, "KubeBlocks version")
cmd.Flags().BoolVar(&o.CreateNamespace, "create-namespace", false, "Create the namespace if not present")
cmd.Flags().BoolVar(&o.Check, "check", true, "Check kubernetes environment before installation")
Expand Down Expand Up @@ -231,8 +228,6 @@ func (o *InstallOptions) PreCheck() error {

func (o *InstallOptions) Install() error {
var err error
// add monitor parameters
o.ValueOpts.Values = append(o.ValueOpts.Values, fmt.Sprintf(kMonitorParam, o.Monitor))

// add pod anti-affinity
if o.PodAntiAffinity != "" || len(o.TopologyKeys) > 0 {
Expand Down Expand Up @@ -498,18 +493,6 @@ func (o *InstallOptions) printNotes() {
-> Uninstall KubeBlocks:
kbcli kubeblocks uninstall
`)
if o.Monitor {
fmt.Fprint(o.Out, `
-> To view the monitoring add-ons web console:
kbcli dashboard list # list all monitoring web consoles
kbcli dashboard open <name> # open the web console in the default browser
`)
} else {
fmt.Fprint(o.Out, `
Note: Monitoring add-ons are not installed.
Use 'kbcli addon enable <addon-name>' to install them later.
`)
}
}

func (o *InstallOptions) buildChart() *helm.InstallOpts {
Expand Down
6 changes: 1 addition & 5 deletions cmd/kubeblocks/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package kubeblocks

import (
"fmt"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

Expand Down Expand Up @@ -86,12 +84,10 @@ var _ = Describe("kubeblocks install", func() {
Dynamic: testing.FakeDynamicClient(),
},
Version: version.DefaultKubeBlocksVersion,
Monitor: true,
CreateNamespace: true,
}
Expect(o.Install()).Should(HaveOccurred())
Expect(o.ValueOpts.Values).Should(HaveLen(1))
Expect(o.ValueOpts.Values[0]).To(Equal(fmt.Sprintf(kMonitorParam, true)))
Expect(o.ValueOpts.Values).Should(HaveLen(0))
Expect(o.installChart()).Should(HaveOccurred())
o.printNotes()
})
Expand Down
14 changes: 14 additions & 0 deletions cmd/kubeblocks/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ import (
"github.com/apecloud/kubeblocks/internal/cli/util/helm"
)

const (
kbBuiltinLabelKey = "addons.extensions.kubeblocks.io"
kbBuiltinLabelValue = "true"
)

var (
uninstallExample = templates.Examples(`
# uninstall KubeBlocks
Expand Down Expand Up @@ -344,6 +349,15 @@ func checkResources(dynamic dynamic.Interface) error {
}

for _, item := range objList.Items {
labels := item.GetLabels()
if labels == nil {
crs[gvr.Resource] = append(crs[gvr.Resource], item.GetName())
continue
}
// skip builtin resources managed by KubeBlocks
if v, ok := labels[kbBuiltinLabelKey]; ok && v == kbBuiltinLabelValue {
continue
}
crs[gvr.Resource] = append(crs[gvr.Resource], item.GetName())
}
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/kubeblocks/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ func (o *InstallOptions) Upgrade() error {

if !o.Quiet {
fmt.Fprintf(o.Out, "\nKubeBlocks has been upgraded %s SUCCESSFULLY!\n", msg)
// set monitor to true, so that we can print notes with monitor
o.Monitor = true
o.printNotes()
}
return nil
Expand Down
18 changes: 8 additions & 10 deletions cmd/playground/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,25 +449,23 @@ func (o *initOptions) installKubeBlocks(k8sClusterName string) error {
Timeout: o.Timeout,
},
Version: o.kbVersion,
Monitor: true,
Quiet: true,
Check: true,
}

// enable monitor components by default
insOpts.ValueOpts.Values = append(insOpts.ValueOpts.Values,
"prometheus.enabled=true",
"grafana.enabled=true",
"agamotto.enabled=true",
)

if o.cloudProvider == cp.Local {
insOpts.ValueOpts.Values = append(insOpts.ValueOpts.Values,
// use hostpath csi driver to support snapshot
"snapshot-controller.enabled=true",
"csi-hostpath-driver.enabled=true",

// disable the persistent volume of prometheus, if not, the prometheus
// will depend on the hostpath csi driver to create persistent
// volume, but the order of addon installation is not guaranteed which
// will cause the prometheus PVC pending forever.
"prometheus.server.persistentVolume.enabled=false",
"prometheus.server.statefulSet.enabled=false",
"prometheus.alertmanager.persistentVolume.enabled=false",
"prometheus.alertmanager.statefulSet.enabled=false")
)
} else if o.cloudProvider == cp.AWS {
insOpts.ValueOpts.Values = append(insOpts.ValueOpts.Values,
// enable aws-load-balancer-controller addon automatically on playground
Expand Down

0 comments on commit 8a67cf6

Please sign in to comment.