Skip to content

Commit

Permalink
link consoleplugin deployment lifecycle with topolocy configmap lifec…
Browse files Browse the repository at this point in the history
…ycle

Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
  • Loading branch information
eguzki committed Oct 7, 2024
1 parent 616d470 commit e5bcefd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
33 changes: 32 additions & 1 deletion controllers/consoleplugin_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/kuadrant/policy-machinery/machinery"

"github.com/kuadrant/kuadrant-operator/pkg/library/reconcilers"
"github.com/kuadrant/kuadrant-operator/pkg/library/utils"
"github.com/kuadrant/kuadrant-operator/pkg/log"
"github.com/kuadrant/kuadrant-operator/pkg/openshift"
"github.com/kuadrant/kuadrant-operator/pkg/openshift/consoleplugin"
Expand Down Expand Up @@ -49,17 +50,38 @@ func (r *ConsolePluginReconciler) Subscription() *controller.Subscription {
ReconcileFunc: r.Run,
Events: []controller.ResourceEventMatcher{
{Kind: ptr.To(openshift.ConsolePluginGVK.GroupKind())},

Check warning on line 52 in controllers/consoleplugin_reconciler.go

View check run for this annotation

Codecov / codecov/patch

controllers/consoleplugin_reconciler.go#L48-L52

Added lines #L48 - L52 were not covered by tests
{
Kind: ptr.To(ConfigMapGroupKind),
ObjectNamespace: r.namespace,
ObjectName: TopologyConfigMapName,
EventType: ptr.To(controller.CreateEvent),
},

Check warning on line 58 in controllers/consoleplugin_reconciler.go

View check run for this annotation

Codecov / codecov/patch

controllers/consoleplugin_reconciler.go#L54-L58

Added lines #L54 - L58 were not covered by tests
{
Kind: ptr.To(ConfigMapGroupKind),
ObjectNamespace: r.namespace,
ObjectName: TopologyConfigMapName,
EventType: ptr.To(controller.DeleteEvent),
},
},

Check warning on line 65 in controllers/consoleplugin_reconciler.go

View check run for this annotation

Codecov / codecov/patch

controllers/consoleplugin_reconciler.go#L60-L65

Added lines #L60 - L65 were not covered by tests
}
}

func (r *ConsolePluginReconciler) Run(eventCtx context.Context, _ []controller.ResourceEvent, _ *machinery.Topology, _ error, _ *sync.Map) error {
func (r *ConsolePluginReconciler) Run(eventCtx context.Context, _ []controller.ResourceEvent, topology *machinery.Topology, _ error, _ *sync.Map) error {
logger := r.Logger()
logger.V(1).Info("task started")
ctx := logr.NewContext(eventCtx, logger)

Check warning on line 72 in controllers/consoleplugin_reconciler.go

View check run for this annotation

Codecov / codecov/patch

controllers/consoleplugin_reconciler.go#L69-L72

Added lines #L69 - L72 were not covered by tests

existingTopologyConfigMaps := topology.Objects().Items(func(object machinery.Object) bool {
return object.GetName() == TopologyConfigMapName && object.GetNamespace() == r.namespace && object.GroupVersionKind().Kind == ConfigMapGroupKind.Kind
})

Check warning on line 76 in controllers/consoleplugin_reconciler.go

View check run for this annotation

Codecov / codecov/patch

controllers/consoleplugin_reconciler.go#L74-L76

Added lines #L74 - L76 were not covered by tests

topologyExists := len(existingTopologyConfigMaps) > 0

Check warning on line 78 in controllers/consoleplugin_reconciler.go

View check run for this annotation

Codecov / codecov/patch

controllers/consoleplugin_reconciler.go#L78

Added line #L78 was not covered by tests

// Service
service := consoleplugin.Service(r.namespace)
if !topologyExists {
utils.TagObjectToDelete(service)

Check warning on line 83 in controllers/consoleplugin_reconciler.go

View check run for this annotation

Codecov / codecov/patch

controllers/consoleplugin_reconciler.go#L81-L83

Added lines #L81 - L83 were not covered by tests
}
err := r.ReconcileResource(ctx, &corev1.Service{}, service, reconcilers.CreateOnlyMutator)
if err != nil {
logger.Error(err, "reconciling service")
Expand All @@ -70,6 +92,9 @@ func (r *ConsolePluginReconciler) Run(eventCtx context.Context, _ []controller.R
deployment := consoleplugin.Deployment(r.namespace, ConsolePluginImageURL)
deploymentMutators := make([]reconcilers.DeploymentMutateFn, 0)
deploymentMutators = append(deploymentMutators, reconcilers.DeploymentImageMutator)
if !topologyExists {
utils.TagObjectToDelete(deployment)

Check warning on line 96 in controllers/consoleplugin_reconciler.go

View check run for this annotation

Codecov / codecov/patch

controllers/consoleplugin_reconciler.go#L92-L96

Added lines #L92 - L96 were not covered by tests
}
err = r.ReconcileResource(ctx, &appsv1.Deployment{}, deployment, reconcilers.DeploymentMutator(deploymentMutators...))
if err != nil {
logger.Error(err, "reconciling deployment")
Expand All @@ -78,6 +103,9 @@ func (r *ConsolePluginReconciler) Run(eventCtx context.Context, _ []controller.R

// Nginx ConfigMap
nginxConfigMap := consoleplugin.NginxConfigMap(r.namespace)
if !topologyExists {
utils.TagObjectToDelete(nginxConfigMap)

Check warning on line 107 in controllers/consoleplugin_reconciler.go

View check run for this annotation

Codecov / codecov/patch

controllers/consoleplugin_reconciler.go#L105-L107

Added lines #L105 - L107 were not covered by tests
}
err = r.ReconcileResource(ctx, &corev1.ConfigMap{}, nginxConfigMap, reconcilers.CreateOnlyMutator)
if err != nil {
logger.Error(err, "reconciling nginx configmap")
Expand All @@ -86,6 +114,9 @@ func (r *ConsolePluginReconciler) Run(eventCtx context.Context, _ []controller.R

// ConsolePlugin
consolePlugin := consoleplugin.ConsolePlugin(r.namespace)
if !topologyExists {
utils.TagObjectToDelete(consolePlugin)

Check warning on line 118 in controllers/consoleplugin_reconciler.go

View check run for this annotation

Codecov / codecov/patch

controllers/consoleplugin_reconciler.go#L116-L118

Added lines #L116 - L118 were not covered by tests
}
err = r.ReconcileResource(ctx, &consolev1.ConsolePlugin{}, consolePlugin, reconcilers.CreateOnlyMutator)
if err != nil {
logger.Error(err, "reconciling consoleplugin")
Expand Down
1 change: 0 additions & 1 deletion controllers/state_of_the_world.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ func NewPolicyMachineryController(manager ctrlruntime.Manager, client *dynamic.D
&consolev1.ConsolePlugin{}, openshift.ConsolePluginsResource, metav1.NamespaceAll,
controller.FilterResourcesByLabel[*consolev1.ConsolePlugin](fmt.Sprintf("%s=%s", consoleplugin.AppLabelKey, consoleplugin.AppLabelValue)))),
controller.WithObjectKinds(openshift.ConsolePluginGVK.GroupKind()),
// TODO: add object links
)

Check warning on line 148 in controllers/state_of_the_world.go

View check run for this annotation

Codecov / codecov/patch

controllers/state_of_the_world.go#L143-L148

Added lines #L143 - L148 were not covered by tests
}

Expand Down
6 changes: 5 additions & 1 deletion controllers/topology_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import (
"github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant"
)

const (
TopologyConfigMapName = "topology"
)

type TopologyReconciler struct {
Client *dynamic.DynamicClient
Namespace string
Expand All @@ -32,7 +36,7 @@ func (r *TopologyReconciler) Reconcile(ctx context.Context, _ []controller.Resou

cm := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "topology",
Name: TopologyConfigMapName,
Namespace: r.Namespace,
Labels: map[string]string{kuadrant.TopologyLabel: "true"},
},
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ require (
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/openshift/api v0.0.0-20240926211938-f89ab92f1597 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
Expand Down

0 comments on commit e5bcefd

Please sign in to comment.