Skip to content
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
46 changes: 33 additions & 13 deletions internal/controller/ceilometer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,10 @@ func (r *CeilometerReconciler) generateServiceConfig(
"TransportURL": string(transportURLSecret.Data["transport_url"]),
"CeilometerPassword": string(ceilometerPasswordSecret.Data["CeilometerPassword"]),
"TLS": false, // Default to false. Change to true later if TLS enabled
"SwiftRole": false, //
"SwiftRole": false,
"ManilaEnabled": false,
"DesignateEnabled": false,
"OctaviaEnabled": false,
"Timeout": instance.Spec.APITimeout,
"Region": keystoneAPI.GetRegion(),
}
Expand Down Expand Up @@ -1355,6 +1358,17 @@ func (r *CeilometerReconciler) generateServiceConfig(
templateParameters["SwiftRole"] = true
}

// If Manila/Designate/Octavia endpoints exist, add their meters to polling
if r.endpointExists(ctx, h, "manilav2", instance.Namespace, h.GetLogger()) {
templateParameters["ManilaEnabled"] = true
}
if r.endpointExists(ctx, h, "designate", instance.Namespace, h.GetLogger()) {
templateParameters["DesignateEnabled"] = true
}
if r.endpointExists(ctx, h, "octavia", instance.Namespace, h.GetLogger()) {
templateParameters["OctaviaEnabled"] = true
}

// Add NotificationsURL if configured
// Always get the separate notification secret since we always create separate TransportURLs
if instance.Status.NotificationsURLSecret != nil && *instance.Status.NotificationsURLSecret != "" {
Expand Down Expand Up @@ -1831,17 +1845,6 @@ func (r *CeilometerReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
return nil
}

// Reconcile every time a keystoneendpoint is modified
keystoneEndpointsWatchFn := func(_ context.Context, o client.Object) []reconcile.Request {
result := []reconcile.Request{}
name := client.ObjectKey{
Namespace: o.GetNamespace(),
Name: ceilometer.ServiceName,
}
result = append(result, reconcile.Request{NamespacedName: name})
return result
}

galeraWatchFn := func(_ context.Context, o client.Object) []reconcile.Request {
result := []reconcile.Request{}

Expand Down Expand Up @@ -2017,7 +2020,7 @@ func (r *CeilometerReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
).
Watches(
&keystonev1.KeystoneEndpoint{},
handler.EnqueueRequestsFromMapFunc(keystoneEndpointsWatchFn),
handler.EnqueueRequestsFromMapFunc(r.findObjectForSrc),
).
Watches(
&mariadbv1.Galera{},
Expand Down Expand Up @@ -2097,6 +2100,23 @@ func (r *CeilometerReconciler) findObjectForSrc(ctx context.Context, src client.
return requests
}

func (r *CeilometerReconciler) endpointExists(
ctx context.Context,
h *helper.Helper,
endpointName string,
namespace string,
log logr.Logger,
) bool {
_, err := keystonev1.GetKeystoneEndpointWithName(ctx, h, endpointName, namespace)
if err != nil {
if !k8s_errors.IsNotFound(err) {
log.Error(err, fmt.Sprintf("Failed to check for KeystoneEndpoint/%s, assuming not present", endpointName))
}
return false
}
return true
}

func (r CeilometerReconciler) roleExists(
ctx context.Context,
helper *helper.Helper,
Expand Down
9 changes: 9 additions & 0 deletions templates/ceilometercentral/config/polling.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ sources:
{{- if .SwiftRole }}
- storage.*
{{- end }}
{{- if .ManilaEnabled }}
- manila.*
{{- end }}
{{- if .DesignateEnabled }}
- dns.*
{{- end }}
{{- if .OctaviaEnabled }}
- loadbalancer.*
{{- end }}
10 changes: 10 additions & 0 deletions test/kuttl/tests/ceilometer/04-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 300
commands:
- script: >
oc get secret ceilometer-config-data -n $NAMESPACE -o jsonpath='{.data.polling\.yaml\.j2}' | base64 -d | grep 'manila\.\*'
- script: >
oc get secret ceilometer-config-data -n $NAMESPACE -o jsonpath='{.data.polling\.yaml\.j2}' | base64 -d | grep 'dns\.\*'
- script: >
oc get secret ceilometer-config-data -n $NAMESPACE -o jsonpath='{.data.polling\.yaml\.j2}' | base64 -d | grep 'loadbalancer\.\*'
33 changes: 33 additions & 0 deletions test/kuttl/tests/ceilometer/04-conditional-polling.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
apiVersion: keystone.openstack.org/v1beta1
kind: KeystoneEndpoint
metadata:
name: manilav2
labels:
service: manilav2
spec:
serviceName: manilav2
endpoints:
internal: http://manila-internal.openstack.svc:8786/v2
---
apiVersion: keystone.openstack.org/v1beta1
kind: KeystoneEndpoint
metadata:
name: designate
labels:
service: designate
spec:
serviceName: designate
endpoints:
internal: http://designate-internal.openstack.svc:9001
---
apiVersion: keystone.openstack.org/v1beta1
kind: KeystoneEndpoint
metadata:
name: octavia
labels:
service: octavia
spec:
serviceName: octavia
endpoints:
internal: http://octavia-internal.openstack.svc:9876