diff --git a/charts/fleet/templates/deployment.yaml b/charts/fleet/templates/deployment.yaml index f6990f45ce..2b6b0f0160 100644 --- a/charts/fleet/templates/deployment.yaml +++ b/charts/fleet/templates/deployment.yaml @@ -89,9 +89,6 @@ spec: {{- end }} command: - fleetcontroller - {{- if not $.Values.gitops.enabled }} - - --disable-gitops - {{- end }} {{- if . }} - --shard-id - {{ quote . }} diff --git a/internal/cmd/controller/finalizeutil/finalizeutil.go b/internal/cmd/controller/finalize/finalize.go similarity index 84% rename from internal/cmd/controller/finalizeutil/finalizeutil.go rename to internal/cmd/controller/finalize/finalize.go index 35b9f92785..9af3a24879 100644 --- a/internal/cmd/controller/finalizeutil/finalizeutil.go +++ b/internal/cmd/controller/finalize/finalize.go @@ -1,4 +1,4 @@ -package finalizeutil +package finalize import ( "context" @@ -20,6 +20,9 @@ const ( BundleDeploymentFinalizer = "fleet.cattle.io/bundle-deployment-finalizer" ) +// PurgeBundles deletes all bundles related to the given GitRepo namespaced name +// It deletes resources in cascade. Deleting Bundles, its BundleDeployments, and +// the related namespace if Bundle.Spec.DeleteNamespace is set to true. func PurgeBundles(ctx context.Context, c client.Client, gitrepo types.NamespacedName) error { bundles := &v1alpha1.BundleList{} err := c.List(ctx, bundles, client.MatchingLabels{v1alpha1.RepoLabel: gitrepo.Name}, client.InNamespace(gitrepo.Namespace)) @@ -61,6 +64,7 @@ func PurgeBundles(ctx context.Context, c client.Client, gitrepo types.Namespaced return nil } +// PurgeBundleDeployments deletes all BundleDeployments related with the given Bundle namespaced name. func PurgeBundleDeployments(ctx context.Context, c client.Client, bundle types.NamespacedName) error { list := &v1alpha1.BundleDeploymentList{} err := c.List( @@ -101,6 +105,7 @@ func PurgeBundleDeployments(ctx context.Context, c client.Client, bundle types.N return nil } +// PurgeImageScans deletes all ImageScan resources related with the given GitRepo namespaces name. func PurgeImageScans(ctx context.Context, c client.Client, gitrepo types.NamespacedName) error { images := &v1alpha1.ImageScanList{} err := c.List(ctx, images, client.InNamespace(gitrepo.Namespace)) @@ -120,6 +125,9 @@ func PurgeImageScans(ctx context.Context, c client.Client, gitrepo types.Namespa return nil } +// PurgeNamespace deletes the given namespace if deleteNamespace is set to true. +// It ignores the following namespaces, that are considered as default by fleet or kubernetes: +// fleet-local, cattle-fleet-system, fleet-default, cattle-fleet-clusters-system, default func PurgeNamespace(ctx context.Context, c client.Client, deleteNamespace bool, ns string) error { if !deleteNamespace { return nil diff --git a/internal/cmd/controller/gitops/reconciler/gitjob_controller.go b/internal/cmd/controller/gitops/reconciler/gitjob_controller.go index 961aea8fe9..c4222e05cc 100644 --- a/internal/cmd/controller/gitops/reconciler/gitjob_controller.go +++ b/internal/cmd/controller/gitops/reconciler/gitjob_controller.go @@ -11,7 +11,7 @@ import ( "time" "github.com/go-logr/logr" - "github.com/rancher/fleet/internal/cmd/controller/finalizeutil" + "github.com/rancher/fleet/internal/cmd/controller/finalize" "github.com/rancher/fleet/internal/cmd/controller/grutil" "github.com/rancher/fleet/internal/cmd/controller/imagescan" "github.com/rancher/fleet/internal/metrics" @@ -138,7 +138,7 @@ func (r *GitJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr } if !gitrepo.DeletionTimestamp.IsZero() { - if controllerutil.ContainsFinalizer(gitrepo, finalizeutil.GitRepoFinalizer) { + if controllerutil.ContainsFinalizer(gitrepo, finalize.GitRepoFinalizer) { if err := r.cleanupGitRepo(ctx, logger, gitrepo); err != nil { return ctrl.Result{}, err } @@ -147,7 +147,7 @@ func (r *GitJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr return ctrl.Result{}, nil } - if !controllerutil.ContainsFinalizer(gitrepo, finalizeutil.GitRepoFinalizer) { + if !controllerutil.ContainsFinalizer(gitrepo, finalize.GitRepoFinalizer) { err := r.addGitRepoFinalizer(ctx, req.NamespacedName) if client.IgnoreNotFound(err) != nil { return ctrl.Result{}, err @@ -264,14 +264,14 @@ func (r *GitJobReconciler) cleanupGitRepo(ctx context.Context, logger logr.Logge metrics.GitRepoCollector.Delete(gitrepo.Name, gitrepo.Namespace) nsName := types.NamespacedName{Name: gitrepo.Name, Namespace: gitrepo.Namespace} - if err := finalizeutil.PurgeBundles(ctx, r.Client, nsName); err != nil { + if err := finalize.PurgeBundles(ctx, r.Client, nsName); err != nil { return err } // remove the job scheduled by imagescan, if any _ = r.Scheduler.DeleteJob(imagescan.GitCommitKey(gitrepo.Namespace, gitrepo.Name)) - if err := finalizeutil.PurgeImageScans(ctx, r.Client, nsName); err != nil { + if err := finalize.PurgeImageScans(ctx, r.Client, nsName); err != nil { return err } @@ -280,7 +280,7 @@ func (r *GitJobReconciler) cleanupGitRepo(ctx context.Context, logger logr.Logge return err } - controllerutil.RemoveFinalizer(gitrepo, finalizeutil.GitRepoFinalizer) + controllerutil.RemoveFinalizer(gitrepo, finalize.GitRepoFinalizer) return r.Update(ctx, gitrepo) }) @@ -299,7 +299,7 @@ func (r *GitJobReconciler) addGitRepoFinalizer(ctx context.Context, nsName types return err } - controllerutil.AddFinalizer(gitrepo, finalizeutil.GitRepoFinalizer) + controllerutil.AddFinalizer(gitrepo, finalize.GitRepoFinalizer) return r.Update(ctx, gitrepo) }) diff --git a/internal/cmd/controller/operator.go b/internal/cmd/controller/operator.go index bcbdc66e52..19a22af105 100644 --- a/internal/cmd/controller/operator.go +++ b/internal/cmd/controller/operator.go @@ -38,12 +38,10 @@ func start( leaderOpts LeaderElectionOptions, workersOpts ControllerReconcilerWorkers, bindAddresses BindAddresses, - disableGitops bool, disableMetrics bool, shardID string, ) error { setupLog.Info("listening for changes on local cluster", - "disableGitops", disableGitops, "disableMetrics", disableMetrics, ) diff --git a/internal/cmd/controller/reconciler/bundle_controller.go b/internal/cmd/controller/reconciler/bundle_controller.go index 41105dfba5..c9bd83764c 100644 --- a/internal/cmd/controller/reconciler/bundle_controller.go +++ b/internal/cmd/controller/reconciler/bundle_controller.go @@ -5,7 +5,7 @@ package reconciler import ( "context" - "github.com/rancher/fleet/internal/cmd/controller/finalizeutil" + "github.com/rancher/fleet/internal/cmd/controller/finalize" "github.com/rancher/fleet/internal/cmd/controller/summary" "github.com/rancher/fleet/internal/cmd/controller/target" "github.com/rancher/fleet/internal/manifest" @@ -90,7 +90,7 @@ func (r *BundleReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr metrics.BundleCollector.Delete(req.Name, req.Namespace) logger.V(1).Info("Bundle not found, purging bundle deployments") - if err := finalizeutil.PurgeBundleDeployments(ctx, r.Client, req.NamespacedName); err != nil { + if err := finalize.PurgeBundleDeployments(ctx, r.Client, req.NamespacedName); err != nil { // A bundle deployment may have been purged by the GitRepo reconciler, hence we ignore // not-found errors here. return ctrl.Result{}, client.IgnoreNotFound(err) diff --git a/internal/cmd/controller/root.go b/internal/cmd/controller/root.go index fa96b2465d..df94deb8f7 100644 --- a/internal/cmd/controller/root.go +++ b/internal/cmd/controller/root.go @@ -34,7 +34,6 @@ type FleetManager struct { command.DebugConfig Kubeconfig string `usage:"Kubeconfig file"` Namespace string `usage:"namespace to watch" default:"cattle-fleet-system" env:"NAMESPACE"` - DisableGitops bool `usage:"disable gitops components" name:"disable-gitops"` DisableMetrics bool `usage:"disable metrics" name:"disable-metrics"` ShardID string `usage:"only manage resources labeled with a specific shard ID" name:"shard-id"` } @@ -162,7 +161,6 @@ func (f *FleetManager) Run(cmd *cobra.Command, args []string) error { leaderOpts, workersOpts, bindAddresses, - f.DisableGitops, f.DisableMetrics, f.ShardID, ); err != nil {