-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable CAPI UI extension installation
Signed-off-by: Danil-Grigorev <[email protected]>
- Loading branch information
1 parent
5adeb47
commit 28ead87
Showing
9 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
capi: | ||
enabled: true | ||
fullnameOverride: capi | ||
rancherTurtles: | ||
image: controller | ||
imageVersion: v0.0.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
|
||
- [14. Turtles UI installation](#title) | ||
- [Context](#context) | ||
- [Decision](#decision) | ||
- [Consequences](#consequences) | ||
|
||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
|
||
# Turtles UI installation | ||
|
||
- Status: proposed | ||
- Date: 2025-02-17 | ||
- Authors: @Danil-Grigorev | ||
- Deciders: @alexander-demicev @furkatgofurov7 @salasberryfin @anmazzotti @mjura @yiannistri | ||
|
||
## Context | ||
|
||
Turtles UI [extension][] provides UI functionality for the Turtles backend. Current installation procedure involves set of mandatory steps described in documentation, which involves: | ||
- [Installing rancher turtles][turtles-install] chart via dashboard | ||
- [Installing UI][ui-install] extension via dashboard | ||
|
||
This process is more complicated then a combined and automated installation, and may also lead to issues like: | ||
- Missed UI extension installation step | ||
- Installation of incompatible version of UI extension and Rancher Turles (involving CAPI version) | ||
- Invalid combination of Turtles and UI versions in case of Turtles chart upgrade | ||
|
||
[extension]: https://github.com/rancher/capi-ui-extension | ||
[turtles-install]: https://turtles.docs.rancher.com/turtles/stable/en/getting-started/install-rancher-turtles/using_rancher_dashboard.html#_installation | ||
[ui-install]: https://turtles.docs.rancher.com/turtles/stable/en/getting-started/install-rancher-turtles/using_rancher_dashboard.html#_capi_ui_extension_installation | ||
|
||
## Decision | ||
|
||
The proposed solution is to install UI extension chart as a `Helm` dependency for the Turtles `Helm` chart. This will leverage `questions.yaml` [integration][] to allow users to configure extension settings or disable UI chart installation. | ||
|
||
UI extensions use `cattle-ui-plugin-system` namespace. Turtles will leverage a new controller, which will be able to asyncroniously move the `UIPlugin` resource to the namespace, once it is available and Rancher chart is installed. | ||
|
||
Turtles chart will manage the lifecycle of UI extension by setting ownership references on the `UIPlugin` resource, to ensure automatic deletion on chart removal. | ||
|
||
[integration]: https://ranchermanager.docs.rancher.com/how-to-guides/new-user-guides/helm-charts-in-rancher/create-apps#questionsyml | ||
|
||
## Consequences | ||
|
||
- UI extension will be managed by Turtles chart | ||
- Existing UI extension installation will be adopted by Turtles chart upgrade | ||
- UI extension version will be seamlessly updated with Turtles chart upgrade |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
Copyright © 2023 - 2024 SUSE LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package controllers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
rbacv1 "k8s.io/api/rbac/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apimachinery/pkg/types" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/controller" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
"sigs.k8s.io/controller-runtime/pkg/predicate" | ||
) | ||
|
||
// UIPluginReconciler reconciles a UIPlugin object. | ||
type UIPluginReconciler struct { | ||
client.Client | ||
*runtime.Scheme | ||
UncachedClient client.Client | ||
} | ||
|
||
// SetupWithManager sets up the controller with the Manager. | ||
func (r *UIPluginReconciler) SetupWithManager(_ context.Context, mgr ctrl.Manager, _ controller.Options) error { | ||
uiPlugin := &metav1.PartialObjectMetadata{} | ||
uiPlugin.SetGroupVersionKind(schema.GroupVersionKind{ | ||
Group: "catalog.cattle.io", | ||
Version: "v1", | ||
Kind: "UIPlugin", | ||
}) | ||
|
||
if err := ctrl.NewControllerManagedBy(mgr). | ||
Named("ui-plugin"). | ||
For(uiPlugin). | ||
WithEventFilter(predicate.NewPredicateFuncs(func(plugin client.Object) bool { | ||
return plugin.GetNamespace() == os.Getenv("POD_NAMESPACE") | ||
})). | ||
Complete(r); err != nil { | ||
return fmt.Errorf("creating UIPlugin controller: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
//+kubebuilder:rbac:groups=catalog.cattle.io,resources=uiplugins,verbs=get;list;watch;create;patch;delete | ||
//+kubebuilder:rbac:groups=rbac.authorization.k8s.io,resourceNames=rancher-turtles-manager-role,resources=clusterroles,verbs=get;list | ||
|
||
// Reconcile moves the UIPlugin into cattle-ui-plugin-system namespace. | ||
func (r *UIPluginReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
log := log.FromContext(ctx) | ||
|
||
plugin := &unstructured.Unstructured{} | ||
plugin.SetKind("UIPlugin") | ||
plugin.SetAPIVersion("catalog.cattle.io/v1") | ||
|
||
if err := r.Client.Get(ctx, req.NamespacedName, plugin); err != nil { | ||
log.Error(err, "Unable to get UIPlugin") | ||
|
||
return ctrl.Result{}, client.IgnoreNotFound(err) | ||
} | ||
|
||
if plugin.GetDeletionTimestamp() != nil { | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
role := &rbacv1.ClusterRole{} | ||
if err := r.UncachedClient.Get(ctx, types.NamespacedName{ | ||
Name: "rancher-turtles-manager-role", | ||
}, role); err != nil { | ||
log.Error(err, "Unable to get turtles clusterRole") | ||
|
||
return ctrl.Result{}, err | ||
} | ||
|
||
destination := &unstructured.Unstructured{} | ||
destination.SetGroupVersionKind(plugin.GroupVersionKind()) | ||
destination.SetName(plugin.GetName()) | ||
destination.SetNamespace("cattle-ui-plugin-system") | ||
destination.Object["spec"] = plugin.Object["spec"] | ||
|
||
if err := controllerutil.SetOwnerReference(role, destination, r.Scheme); err != nil { | ||
log.Error(err, "Unable to set ClusterRole owner on UIPlugin") | ||
|
||
return ctrl.Result{}, err | ||
} | ||
|
||
if err := r.Patch(ctx, destination, client.Apply, []client.PatchOption{ | ||
client.ForceOwnership, | ||
client.FieldOwner("ui-plugin-controller"), | ||
}...); err != nil { | ||
log.Error(err, "Unable to patch UIPlugin") | ||
|
||
return ctrl.Result{}, err | ||
} | ||
|
||
if err := r.Delete(ctx, plugin); err != nil { | ||
log.Error(err, "Unable to cleanup source UIPlugin") | ||
|
||
return ctrl.Result{}, err | ||
} | ||
|
||
return ctrl.Result{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters