Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify installation of dependency controllers #46

Merged
merged 2 commits into from
Aug 13, 2024
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
6 changes: 6 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ rules:
- get
- list
- watch
- apiGroups:
- apiextensions.k8s.io
resources:
- customresourcedefinitions
verbs:
- get
- apiGroups:
- batch
resources:
Expand Down
14 changes: 14 additions & 0 deletions internal/controller/upgradeplan_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/suse-edge/upgrade-controller/pkg/release"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -64,6 +65,7 @@ type UpgradePlanReconciler struct {
// +kubebuilder:rbac:groups=batch,resources=jobs/status,verbs=get
// +kubebuilder:rbac:groups=helm.cattle.io,resources=helmcharts,verbs=get;update;list;watch;create
// +kubebuilder:rbac:groups=helm.cattle.io,resources=helmcharts/status,verbs=get
// +kubebuilder:rbac:groups=apiextensions.k8s.io,resources=customresourcedefinitions,verbs=get

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
Expand Down Expand Up @@ -275,6 +277,18 @@ func (r *UpgradePlanReconciler) findUpgradePlanFromJob(ctx context.Context, job

// SetupWithManager sets up the controller with the Manager.
func (r *UpgradePlanReconciler) SetupWithManager(mgr ctrl.Manager) error {
definitionsGetter := clientset.NewForConfigOrDie(mgr.GetConfig()).ApiextensionsV1().CustomResourceDefinitions()

helmChartKind := helmcattlev1.Kind(helmcattlev1.HelmChartResourceName)
if _, err := definitionsGetter.Get(context.Background(), helmChartKind.String(), metav1.GetOptions{}); err != nil {
return fmt.Errorf("verifying Helm Controller installation: %w", err)
}

sucPlanKind := upgradecattlev1.Kind(upgradecattlev1.PlanResourceName)
if _, err := definitionsGetter.Get(context.Background(), sucPlanKind.String(), metav1.GetOptions{}); err != nil {
return fmt.Errorf("verifying System Upgrade Controller installation: %w", err)
}

return ctrl.NewControllerManagedBy(mgr).
For(&lifecyclev1alpha1.UpgradePlan{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Owns(&upgradecattlev1.Plan{}, builder.WithPredicates(predicate.Funcs{
Expand Down