Skip to content

Commit

Permalink
[watches] Fix watches declarations for CR update
Browse files Browse the repository at this point in the history
This change fixes the Watches declarations to comply with the new
controller-runtime standards.

Signed-off-by: Brendan Shephard <[email protected]>
  • Loading branch information
bshephar committed Feb 14, 2024
1 parent fc17c6b commit ae12e6b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 50 deletions.
9 changes: 4 additions & 5 deletions controllers/heat_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

heat "github.com/openstack-k8s-operators/heat-operator/pkg/heat"
heatapi "github.com/openstack-k8s-operators/heat-operator/pkg/heatapi"
Expand Down Expand Up @@ -245,7 +244,7 @@ func (r *HeatReconciler) SetupWithManager(mgr ctrl.Manager) error {
return err
}

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

// get all Heat CRs
Expand Down Expand Up @@ -287,17 +286,17 @@ func (r *HeatReconciler) SetupWithManager(mgr ctrl.Manager) error {
Owns(&corev1.ServiceAccount{}).
Owns(&rbacv1.Role{}).
Owns(&rbacv1.RoleBinding{}).
Watches(&source.Kind{Type: &memcachedv1.Memcached{}},
Watches(&memcachedv1.Memcached{},
handler.EnqueueRequestsFromMapFunc(memcachedFn)).
Watches(
&source.Kind{Type: &corev1.Secret{}},
&corev1.Secret{},
handler.EnqueueRequestsFromMapFunc(r.findObjectsForSrc),
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}),
).
Complete(r)
}

func (r *HeatReconciler) findObjectsForSrc(src client.Object) []reconcile.Request {
func (r *HeatReconciler) findObjectsForSrc(ctx context.Context, src client.Object) []reconcile.Request {
requests := []reconcile.Request{}

l := log.FromContext(context.Background()).WithName("Controllers").WithName("Heat")
Expand Down
30 changes: 13 additions & 17 deletions controllers/heatapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/go-logr/logr"
heatv1beta1 "github.com/openstack-k8s-operators/heat-operator/api/v1beta1"
Expand Down Expand Up @@ -66,15 +65,13 @@ type HeatAPIReconciler struct {
Kclient kubernetes.Interface
}

var (
keystoneServices = []map[string]string{
{
"type": heat.ServiceType,
"name": heat.ServiceName,
"desc": "Heat API service",
},
}
)
var keystoneServices = []map[string]string{
{
"type": heat.ServiceType,
"name": heat.ServiceName,
"desc": "Heat API service",
},
}

// +kubebuilder:rbac:groups=heat.openstack.org,resources=heatapis,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=heat.openstack.org,resources=heatapis/status,verbs=get;update;patch
Expand Down Expand Up @@ -182,7 +179,6 @@ func (r *HeatAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re

// SetupWithManager sets up the controller with the Manager.
func (r *HeatAPIReconciler) SetupWithManager(mgr ctrl.Manager) error {

// index passwordSecretField
if err := mgr.GetFieldIndexer().IndexField(context.Background(), &heatv1beta1.HeatAPI{}, passwordSecretField, func(rawObj client.Object) []string {
// Extract the secret name from the spec, if one is provided
Expand Down Expand Up @@ -243,7 +239,7 @@ func (r *HeatAPIReconciler) SetupWithManager(mgr ctrl.Manager) error {
return err
}

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

apis := &heatv1beta1.HeatAPIList{}
Expand Down Expand Up @@ -283,17 +279,17 @@ func (r *HeatAPIReconciler) SetupWithManager(mgr ctrl.Manager) error {
Owns(&appsv1.Deployment{}).
Owns(&corev1.Service{}).
// watch the config CMs we don't own
Watches(&source.Kind{Type: &corev1.ConfigMap{}},
Watches(&corev1.ConfigMap{},
handler.EnqueueRequestsFromMapFunc(configMapFn)).
Watches(
&source.Kind{Type: &corev1.Secret{}},
&corev1.Secret{},
handler.EnqueueRequestsFromMapFunc(r.findObjectsForSrc),
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}),
).
Complete(r)
}

func (r *HeatAPIReconciler) findObjectsForSrc(src client.Object) []reconcile.Request {
func (r *HeatAPIReconciler) findObjectsForSrc(ctx context.Context, src client.Object) []reconcile.Request {
requests := []reconcile.Request{}

l := log.FromContext(context.Background()).WithName("Controllers").WithName("HeatAPI")
Expand Down Expand Up @@ -607,8 +603,8 @@ func (r *HeatAPIReconciler) reconcileNormal(ctx context.Context, instance *heatv
parentHeatName := heat.GetOwningHeatName(instance)

configMaps := []string{
fmt.Sprintf("%s-scripts", parentHeatName), //ScriptsConfigMap
fmt.Sprintf("%s-config-data", parentHeatName), //ConfigMap
fmt.Sprintf("%s-scripts", parentHeatName), // ScriptsConfigMap
fmt.Sprintf("%s-config-data", parentHeatName), // ConfigMap
}

_, err = configmap.GetConfigMaps(ctx, helper, instance, configMaps, instance.Namespace, &configMapVars)
Expand Down
30 changes: 13 additions & 17 deletions controllers/heatcfnapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/go-logr/logr"
heatv1beta1 "github.com/openstack-k8s-operators/heat-operator/api/v1beta1"
Expand Down Expand Up @@ -66,15 +65,13 @@ type HeatCfnAPIReconciler struct {
Kclient kubernetes.Interface
}

var (
keystoneCfnServices = []map[string]string{
{
"type": heat.CfnServiceType,
"name": heat.CfnServiceName,
"desc": "Heat Cloudformation API service",
},
}
)
var keystoneCfnServices = []map[string]string{
{
"type": heat.CfnServiceType,
"name": heat.CfnServiceName,
"desc": "Heat Cloudformation API service",
},
}

// +kubebuilder:rbac:groups=heat.openstack.org,resources=heatcfnapis,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=heat.openstack.org,resources=heatcfnapis/status,verbs=get;update;patch
Expand Down Expand Up @@ -186,7 +183,6 @@ func (r *HeatCfnAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request)

// SetupWithManager sets up the controller with the Manager.
func (r *HeatCfnAPIReconciler) SetupWithManager(mgr ctrl.Manager) error {

// index passwordSecretField
if err := mgr.GetFieldIndexer().IndexField(context.Background(), &heatv1beta1.HeatCfnAPI{}, passwordSecretField, func(rawObj client.Object) []string {
// Extract the secret name from the spec, if one is provided
Expand Down Expand Up @@ -247,7 +243,7 @@ func (r *HeatCfnAPIReconciler) SetupWithManager(mgr ctrl.Manager) error {
return err
}

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

apis := &heatv1beta1.HeatCfnAPIList{}
Expand Down Expand Up @@ -287,17 +283,17 @@ func (r *HeatCfnAPIReconciler) SetupWithManager(mgr ctrl.Manager) error {
Owns(&appsv1.Deployment{}).
Owns(&corev1.Service{}).
// watch the config CMs we don't own
Watches(&source.Kind{Type: &corev1.ConfigMap{}},
Watches(&corev1.ConfigMap{},
handler.EnqueueRequestsFromMapFunc(configMapFn)).
Watches(
&source.Kind{Type: &corev1.Secret{}},
&corev1.Secret{},
handler.EnqueueRequestsFromMapFunc(r.findObjectsForSrc),
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}),
).
Complete(r)
}

func (r *HeatCfnAPIReconciler) findObjectsForSrc(src client.Object) []reconcile.Request {
func (r *HeatCfnAPIReconciler) findObjectsForSrc(ctx context.Context, src client.Object) []reconcile.Request {
requests := []reconcile.Request{}

l := log.FromContext(context.Background()).WithName("Controllers").WithName("HeatCfnAPI")
Expand Down Expand Up @@ -611,8 +607,8 @@ func (r *HeatCfnAPIReconciler) reconcileNormal(ctx context.Context, instance *he
parentHeatName := heat.GetOwningHeatName(instance)

configMaps := []string{
fmt.Sprintf("%s-scripts", parentHeatName), //ScriptsConfigMap
fmt.Sprintf("%s-config-data", parentHeatName), //ConfigMap
fmt.Sprintf("%s-scripts", parentHeatName), // ScriptsConfigMap
fmt.Sprintf("%s-config-data", parentHeatName), // ConfigMap
}

_, err = configmap.GetConfigMaps(ctx, helper, instance, configMaps, instance.Namespace, &configMapVars)
Expand Down
19 changes: 8 additions & 11 deletions controllers/heatengine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/go-logr/logr"
heatv1beta1 "github.com/openstack-k8s-operators/heat-operator/api/v1beta1"
Expand Down Expand Up @@ -157,7 +156,6 @@ func (r *HeatEngineReconciler) Reconcile(ctx context.Context, req ctrl.Request)

// SetupWithManager sets up the controller with the Manager.
func (r *HeatEngineReconciler) SetupWithManager(mgr ctrl.Manager) error {

// index passwordSecretField
if err := mgr.GetFieldIndexer().IndexField(context.Background(), &heatv1beta1.HeatEngine{}, passwordSecretField, func(rawObj client.Object) []string {
// Extract the secret name from the spec, if one is provided
Expand Down Expand Up @@ -194,7 +192,7 @@ func (r *HeatEngineReconciler) SetupWithManager(mgr ctrl.Manager) error {
return err
}

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

engines := &heatv1beta1.HeatEngineList{}
Expand All @@ -218,7 +216,6 @@ func (r *HeatEngineReconciler) SetupWithManager(mgr ctrl.Manager) error {
r.Log.Info(fmt.Sprintf("ConfigMap object %s and CR %s marked with label: %s", o.GetName(), cr.Name, l))
result = append(result, reconcile.Request{NamespacedName: name})
}

}
}
if len(result) > 0 {
Expand All @@ -230,17 +227,17 @@ func (r *HeatEngineReconciler) SetupWithManager(mgr ctrl.Manager) error {
For(&heatv1beta1.HeatEngine{}).
Owns(&corev1.ConfigMap{}).
Owns(&appsv1.Deployment{}).
Watches(&source.Kind{Type: &corev1.ConfigMap{}},
Watches(&corev1.ConfigMap{},
handler.EnqueueRequestsFromMapFunc(configMapFn)).
Watches(
&source.Kind{Type: &corev1.Secret{}},
&corev1.Secret{},
handler.EnqueueRequestsFromMapFunc(r.findObjectsForSrc),
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}),
).
Complete(r)
}

func (r *HeatEngineReconciler) findObjectsForSrc(src client.Object) []reconcile.Request {
func (r *HeatEngineReconciler) findObjectsForSrc(ctx context.Context, src client.Object) []reconcile.Request {
requests := []reconcile.Request{}

l := log.FromContext(context.Background()).WithName("Controllers").WithName("HeatEngine")
Expand Down Expand Up @@ -299,8 +296,8 @@ func (r *HeatEngineReconciler) reconcileInit(
func (r *HeatEngineReconciler) reconcileNormal(
ctx context.Context,
instance *heatv1beta1.HeatEngine,
helper *helper.Helper) (ctrl.Result, error) {

helper *helper.Helper,
) (ctrl.Result, error) {
r.Log.Info("Reconciling Heat Engine")

// TODO(bshephar) Write the reconcile logic for Heat engine. Let's just create
Expand Down Expand Up @@ -363,8 +360,8 @@ func (r *HeatEngineReconciler) reconcileNormal(
parentHeatName := heat.GetOwningHeatName(instance)

configMaps := []string{
fmt.Sprintf("%s-scripts", parentHeatName), //ScriptsConfigMap
fmt.Sprintf("%s-config-data", parentHeatName), //ConfigMap
fmt.Sprintf("%s-scripts", parentHeatName), // ScriptsConfigMap
fmt.Sprintf("%s-config-data", parentHeatName), // ConfigMap
}

_, err = configmap.GetConfigMaps(ctx, helper, instance, configMaps, instance.Namespace, &configMapVars)
Expand Down

0 comments on commit ae12e6b

Please sign in to comment.