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

Add monitoring and alerting resources #978

Merged
merged 5 commits into from
Dec 8, 2020
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: 5 additions & 2 deletions cmd/hyperconverged-cluster-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ import (
"context"
"flag"
"fmt"
"os"
"runtime"

"github.com/kubevirt/hyperconverged-cluster-operator/pkg/apis"
"github.com/kubevirt/hyperconverged-cluster-operator/pkg/controller"
"github.com/kubevirt/hyperconverged-cluster-operator/pkg/controller/operands"
"github.com/spf13/pflag"
"os"
"runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"

monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
networkaddons "github.com/kubevirt/cluster-network-addons-operator/pkg/apis"
hcov1beta1 "github.com/kubevirt/hyperconverged-cluster-operator/pkg/apis/hco/v1beta1"
hcoutil "github.com/kubevirt/hyperconverged-cluster-operator/pkg/util"
Expand Down Expand Up @@ -152,6 +154,7 @@ func main() {
admissionregistrationv1.AddToScheme,
consolev1.AddToScheme,
openshiftconfigv1.AddToScheme,
monitoringv1.AddToScheme,
} {
if err := f(mgr.GetScheme()); err != nil {
log.Error(err, "Failed to add to scheme")
Expand Down
4 changes: 2 additions & 2 deletions deploy/cluster_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ rules:
- monitoring.coreos.com
resources:
- servicemonitors
- prometheusrules
verbs:
- get
- create
- '*'
- apiGroups:
- operators.coreos.com
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@ spec:
- monitoring.coreos.com
resources:
- servicemonitors
- prometheusrules
verbs:
- get
- create
- '*'
- apiGroups:
- operators.coreos.com
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@ spec:
- monitoring.coreos.com
resources:
- servicemonitors
- prometheusrules
verbs:
- get
- create
- '*'
- apiGroups:
- operators.coreos.com
resources:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.15

require (
github.com/blang/semver v3.5.1+incompatible
github.com/coreos/prometheus-operator v0.38.1-0.20200424145508-7e176fda06cc
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/go-kit/kit v0.10.0 // indirect
github.com/go-logfmt/logfmt v0.5.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions pkg/components/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,10 @@ func GetClusterPermissions() []rbacv1.PolicyRule {
},
Resources: []string{
"servicemonitors",
"prometheusrules",
},
Verbs: []string{
"get",
"create",
"*",
},
},
{
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/commonTestUtils/testUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package commonTestUtils

import (
"context"

monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
networkaddons "github.com/kubevirt/cluster-network-addons-operator/pkg/apis"
"github.com/kubevirt/hyperconverged-cluster-operator/pkg/apis"
sspopv1 "github.com/kubevirt/kubevirt-ssp-operator/pkg/apis"
Expand Down Expand Up @@ -105,6 +107,7 @@ func GetScheme() *runtime.Scheme {
sspopv1.AddToScheme,
vmimportv1beta1.AddToScheme,
consolev1.AddToScheme,
monitoringv1.AddToScheme,
} {
Expect(f(s)).To(BeNil())
}
Expand Down
20 changes: 15 additions & 5 deletions pkg/controller/hyperconverged/hyperconverged_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
"sigs.k8s.io/controller-runtime/pkg/source"

monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
networkaddonsv1 "github.com/kubevirt/cluster-network-addons-operator/pkg/apis/networkaddonsoperator/v1"
hcov1beta1 "github.com/kubevirt/hyperconverged-cluster-operator/pkg/apis/hco/v1beta1"
"github.com/kubevirt/hyperconverged-cluster-operator/pkg/controller/common"
Expand Down Expand Up @@ -74,7 +75,7 @@ var JSONPatchAnnotationNames = []string{
// Add creates a new HyperConverged Controller and adds it to the Manager. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
func Add(mgr manager.Manager, ci hcoutil.ClusterInfo) error {
return add(mgr, newReconciler(mgr, ci))
return add(mgr, newReconciler(mgr, ci), ci)
}

// newReconciler returns a new reconcile.Reconciler
Expand All @@ -99,7 +100,7 @@ func newReconciler(mgr manager.Manager, ci hcoutil.ClusterInfo) reconcile.Reconc
}

// add adds a new Controller to mgr with r as the reconcile.Reconciler
func add(mgr manager.Manager, r reconcile.Reconciler) error {
func add(mgr manager.Manager, r reconcile.Reconciler, ci hcoutil.ClusterInfo) error {
// Create a new controller
c, err := controller.New("hyperconverged-controller", mgr, controller.Options{Reconciler: r})
if err != nil {
Expand All @@ -120,8 +121,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
return err
}

// Watch secondary resources
for _, resource := range []runtime.Object{
secondaryResources := []runtime.Object{
&kubevirtv1.KubeVirt{},
&cdiv1beta1.CDI{},
&networkaddonsv1.NetworkAddonsConfig{},
Expand All @@ -131,7 +131,17 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
&sspv1.KubevirtMetricsAggregation{},
&schedulingv1.PriorityClass{},
&vmimportv1beta1.VMImportConfig{},
} {
}
if ci.IsOpenshift() {
secondaryResources = append(secondaryResources, []runtime.Object{
&corev1.Service{},
&monitoringv1.ServiceMonitor{},
&monitoringv1.PrometheusRule{},
}...)
}

// Watch secondary resources
for _, resource := range secondaryResources {
msg := fmt.Sprintf("Reconciling for %T", resource)
err = c.Watch(&source.Kind{Type: resource}, &handler.EnqueueRequestsFromMapFunc{
ToRequests: handler.ToRequestsFunc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ var _ = Describe("HyperconvergedController", func() {
).To(BeNil())

Expect(foundResource.Status.RelatedObjects).ToNot(BeNil())
Expect(len(foundResource.Status.RelatedObjects)).Should(Equal(15))
Expect(len(foundResource.Status.RelatedObjects)).Should(Equal(18))
Expect(foundResource.ObjectMeta.Finalizers).Should(Equal([]string{FinalizerName}))

// Now, delete HCO
Expand Down
13 changes: 12 additions & 1 deletion pkg/controller/hyperconverged/testUtils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package hyperconverged
import (
"context"
"fmt"
"os"

monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
"github.com/go-logr/logr"
networkaddonsv1 "github.com/kubevirt/cluster-network-addons-operator/pkg/apis/networkaddonsoperator/v1"
hcov1beta1 "github.com/kubevirt/hyperconverged-cluster-operator/pkg/apis/hco/v1beta1"
Expand All @@ -20,7 +23,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
kubevirtv1 "kubevirt.io/client-go/api/v1"
cdiv1beta1 "kubevirt.io/containerized-data-importer/pkg/apis/core/v1beta1"
"os"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

Expand Down Expand Up @@ -71,6 +73,9 @@ type BasicExpected struct {
vmi *vmimportv1beta1.VMImportConfig
kvMtAg *sspv1.KubevirtMetricsAggregation
imsConfig *corev1.ConfigMap
mService *corev1.Service
serviceMonitor *monitoringv1.ServiceMonitor
promRule *monitoringv1.PrometheusRule
}

func (be BasicExpected) toArray() []runtime.Object {
Expand All @@ -90,6 +95,9 @@ func (be BasicExpected) toArray() []runtime.Object {
be.vmi,
be.kvMtAg,
be.imsConfig,
be.mService,
be.serviceMonitor,
be.promRule,
}
}

Expand Down Expand Up @@ -124,6 +132,9 @@ func getBasicDeployment() *BasicExpected {
res.hco = hco

res.pc = operands.NewKubeVirtPriorityClass(hco)
res.mService = operands.NewMetricsService(hco, namespace)
res.serviceMonitor = operands.NewServiceMonitor(hco, namespace)
res.promRule = operands.NewPrometheusRule(hco, namespace)
// These are all of the objects that we expect to "find" in the client because
// we already created them in a previous reconcile.
expectedKVConfig := operands.NewKubeVirtConfigForCR(hco, namespace)
Expand Down
Loading