Skip to content

Commit

Permalink
always deploy the outdated VMI workload alert
Browse files Browse the repository at this point in the history
the motivation is to eliminate redundant kubevirt deployment
calculations and re-deployment.

The alternative to this approach is to inject/remove the alert in virt-operator
reconciler logic but I think it will add a boiler-plate code.

Signed-off-by: enp0s3 <ibezukh@redhat.com>
  • Loading branch information
enp0s3 committed Jun 27, 2023
1 parent d89207b commit 3cb24b0
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 39 deletions.
2 changes: 1 addition & 1 deletion hack/prom-rule-ci/rule-spec-dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func main() {

targetFile := os.Args[1]

promRuleSpec := components.NewPrometheusRuleSpec("ci", true)
promRuleSpec := components.NewPrometheusRuleSpec("ci")
b, err := json.Marshal(promRuleSpec)
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/virt-operator/kubevirt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ func (k *KubeVirtTestData) addAllWithExclusionMap(config *util.KubeVirtDeploymen
all = append(all, crd)
}
// cr
all = append(all, components.NewPrometheusRuleCR(config.GetNamespace(), config.WorkloadUpdatesEnabled()))
all = append(all, components.NewPrometheusRuleCR(config.GetNamespace()))
// sccs
all = append(all, components.NewKubeVirtControllerSCC(NAMESPACE))
all = append(all, components.NewKubeVirtHandlerSCC(NAMESPACE))
Expand Down
6 changes: 2 additions & 4 deletions pkg/virt-operator/resource/apply/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ var _ = Describe("Apply Prometheus", func() {
var kv *v1.KubeVirt
var stores util.Stores

config := getConfig("fake-registry", "v9.9.9")

BeforeEach(func() {
ctrl = gomock.NewController(GinkgoT())
kvInterface := kubecli.NewMockKubeVirtInterface(ctrl)
Expand Down Expand Up @@ -132,7 +130,7 @@ var _ = Describe("Apply Prometheus", func() {

It("should not patch PrometheusRules on sync when they are equal", func() {

pr := components.NewPrometheusRuleCR("namespace", config.WorkloadUpdatesEnabled())
pr := components.NewPrometheusRuleCR("namespace")

version, imageRegistry, id := getTargetVersionRegistryID(kv)
injectOperatorMetadata(kv, &pr.ObjectMeta, version, imageRegistry, id, true)
Expand All @@ -151,7 +149,7 @@ var _ = Describe("Apply Prometheus", func() {

It("should patch PrometheusRules on sync when they are equal", func() {

pr := components.NewPrometheusRuleCR("namespace", config.WorkloadUpdatesEnabled())
pr := components.NewPrometheusRuleCR("namespace")

version, imageRegistry, id := getTargetVersionRegistryID(kv)
injectOperatorMetadata(kv, &pr.ObjectMeta, version, imageRegistry, id, true)
Expand Down
32 changes: 14 additions & 18 deletions pkg/virt-operator/resource/generate/components/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func NewServiceMonitorCR(namespace string, monitorNamespace string, insecureSkip
}

// NewPrometheusRuleCR returns a PrometheusRule with a group of alerts for the KubeVirt deployment.
func NewPrometheusRuleCR(namespace string, workloadUpdatesEnabled bool) *v1.PrometheusRule {
func NewPrometheusRuleCR(namespace string) *v1.PrometheusRule {
return &v1.PrometheusRule{
TypeMeta: v12.TypeMeta{
APIVersion: v12.SchemeGroupVersion.String(),
Expand All @@ -83,12 +83,12 @@ func NewPrometheusRuleCR(namespace string, workloadUpdatesEnabled bool) *v1.Prom
"k8s-app": "kubevirt",
},
},
Spec: *NewPrometheusRuleSpec(namespace, workloadUpdatesEnabled),
Spec: *NewPrometheusRuleSpec(namespace),
}
}

// NewPrometheusRuleSpec makes a prometheus rule spec for kubevirt
func NewPrometheusRuleSpec(ns string, workloadUpdatesEnabled bool) *v1.PrometheusRuleSpec {
func NewPrometheusRuleSpec(ns string) *v1.PrometheusRuleSpec {
getRestCallsFailedWarning := func(failingCallsPercentage int, component, duration string) string {
const restCallsFailWarningTemplate = "More than %d%% of the rest calls failed in %s for the last %s"
return fmt.Sprintf(restCallsFailWarningTemplate, failingCallsPercentage, component, duration)
Expand Down Expand Up @@ -494,20 +494,7 @@ func NewPrometheusRuleSpec(ns string, workloadUpdatesEnabled bool) *v1.Prometheu
operatorHealthImpactLabelKey: "none",
},
},
}...)

ruleSpec := &v1.PrometheusRuleSpec{
Groups: []v1.RuleGroup{
{
Name: "kubevirt.rules",
Rules: kubevirtRules,
},
},
}

if workloadUpdatesEnabled {
ruleSpec.Groups[0].Rules = append(ruleSpec.Groups[0].Rules, v1.Rule{

{
Alert: "OutdatedVirtualMachineInstanceWorkloads",
Expr: intstr.FromString("kubevirt_vmi_outdated_count != 0"),
For: "1440m",
Expand All @@ -519,7 +506,16 @@ func NewPrometheusRuleSpec(ns string, workloadUpdatesEnabled bool) *v1.Prometheu
severityAlertLabelKey: "warning",
operatorHealthImpactLabelKey: "none",
},
})
},
}...)

ruleSpec := &v1.PrometheusRuleSpec{
Groups: []v1.RuleGroup{
{
Name: "kubevirt.rules",
Rules: kubevirtRules,
},
},
}

for _, group := range ruleSpec.Groups {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var _ = Describe("Prometheus", func() {
})

It("should use the default runbook URL template when no ENV Variable is set", func() {
promRule := NewPrometheusRuleCR("mynamespace", true)
promRule := NewPrometheusRuleCR("mynamespace")

for _, group := range promRule.Spec.Groups {
for _, rule := range group.Rules {
Expand All @@ -35,7 +35,7 @@ var _ = Describe("Prometheus", func() {
desiredRunbookURLTemplate := "desired/runbookURL/template/%s"
os.Setenv(runbookURLTemplateEnv, desiredRunbookURLTemplate)

promRule := NewPrometheusRuleCR("mynamespace", true)
promRule := NewPrometheusRuleCR("mynamespace")

for _, group := range promRule.Spec.Groups {
for _, rule := range group.Rules {
Expand Down
3 changes: 1 addition & 2 deletions pkg/virt-operator/resource/generate/install/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,10 @@ func GenerateCurrentInstallStrategy(config *operatorutil.KubeVirtDeploymentConfi
if serviceMonitorNamespace == "" {
serviceMonitorNamespace = monitorNamespace
}
workloadUpdatesEnabled := config.WorkloadUpdatesEnabled()

rbaclist = append(rbaclist, rbac.GetAllServiceMonitor(config.GetNamespace(), monitorNamespace, monitorServiceAccount)...)
strategy.serviceMonitors = append(strategy.serviceMonitors, components.NewServiceMonitorCR(config.GetNamespace(), serviceMonitorNamespace, true))
strategy.prometheusRules = append(strategy.prometheusRules, components.NewPrometheusRuleCR(config.GetNamespace(), workloadUpdatesEnabled))
strategy.prometheusRules = append(strategy.prometheusRules, components.NewPrometheusRuleCR(config.GetNamespace()))
} else {
glog.Warningf("failed to create ServiceMonitor resources because couldn't find ServiceAccount %v in any monitoring namespaces : %v", monitorServiceAccount, strings.Join(config.GetPotentialMonitorNamespaces(), ", "))
}
Expand Down
11 changes: 0 additions & 11 deletions pkg/virt-operator/util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ const (
// lookup key in AdditionalProperties
AdditionalPropertiesMonitorServiceAccount = "MonitorAccount"

// lookup key in AdditionalProperties
AdditionalPropertiesWorkloadUpdatesEnabled = "WorkloadUpdatesEnabled"

// lookup key in AdditionalProperties
AdditionalPropertiesMigrationNetwork = "MigrationNetwork"

Expand Down Expand Up @@ -205,9 +202,6 @@ func GetTargetConfigFromKV(kv *v1.KubeVirt) *KubeVirtDeploymentConfig {

func GetTargetConfigFromKVWithEnvVarManager(kv *v1.KubeVirt, envVarManager EnvVarManager) *KubeVirtDeploymentConfig {
additionalProperties := getKVMapFromSpec(kv.Spec)
if len(kv.Spec.WorkloadUpdateStrategy.WorkloadUpdateMethods) > 0 {
additionalProperties[AdditionalPropertiesWorkloadUpdatesEnabled] = ""
}
if kv.Spec.Configuration.MigrationConfiguration != nil &&
kv.Spec.Configuration.MigrationConfiguration.Network != nil {
additionalProperties[AdditionalPropertiesMigrationNetwork] = *kv.Spec.Configuration.MigrationConfiguration.Network
Expand Down Expand Up @@ -607,11 +601,6 @@ func (c *KubeVirtDeploymentConfig) GetImagePullSecrets() []k8sv1.LocalObjectRefe
return data
}

func (c *KubeVirtDeploymentConfig) WorkloadUpdatesEnabled() bool {
_, enabled := c.AdditionalProperties[AdditionalPropertiesWorkloadUpdatesEnabled]
return enabled
}

func (c *KubeVirtDeploymentConfig) PersistentReservationEnabled() bool {
_, enabled := c.AdditionalProperties[AdditionalPropertiesPersistentReservationEnabled]
return enabled
Expand Down

0 comments on commit 3cb24b0

Please sign in to comment.