Skip to content
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
72 changes: 0 additions & 72 deletions internal/controller/function_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
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"

Expand All @@ -45,8 +44,6 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
)

const functionFinalizer = "function.functions.dev/finalizer"

// FunctionReconciler reconciles a Function object
type FunctionReconciler struct {
client.Client
Expand Down Expand Up @@ -120,16 +117,6 @@ func (r *FunctionReconciler) reconcile(ctx context.Context, function *v1alpha1.F
}
defer repo.Cleanup()

if err := r.ensureFinalizer(ctx, function); err != nil {
return fmt.Errorf("setting up finalizers failed: %w", err)
}

if function.GetDeletionTimestamp() != nil {
if err := r.handleDeletion(ctx, function, metadata.Name); err != nil {
return fmt.Errorf("deleting function failed: %w", err)
}
}

if err := r.ensureDeployment(ctx, function, repo, metadata); err != nil {
return fmt.Errorf("deploying function failed: %w", err)
}
Expand Down Expand Up @@ -172,56 +159,6 @@ func (r *FunctionReconciler) prepareSource(ctx context.Context, function *v1alph
return repo, &metadata, nil
}

// ensureFinalizer adds the finalizer to the function if it doesn't exist
func (r *FunctionReconciler) ensureFinalizer(ctx context.Context, function *v1alpha1.Function) error {
if controllerutil.ContainsFinalizer(function, functionFinalizer) {
return nil
}

logger := log.FromContext(ctx)
logger.Info("Adding Finalizer for Function")

if ok := controllerutil.AddFinalizer(function, functionFinalizer); !ok {
return fmt.Errorf("failed to add finalizer for function")
}

if err := r.Update(ctx, function); err != nil {
return fmt.Errorf("failed to add finalizer for function: %w", err)
}

return nil
}

// handleDeletion performs cleanup operations when a function is being deleted
func (r *FunctionReconciler) handleDeletion(ctx context.Context, function *v1alpha1.Function, functionName string) error {
if !controllerutil.ContainsFinalizer(function, functionFinalizer) {
return nil
}

logger := log.FromContext(ctx)
logger.Info("Performing Finalizer Operations for Function before delete CR")

// Mark function as terminating
function.MarkTerminating()

// Perform all operations required before removing the finalizer
if err := r.Finalize(ctx, functionName, function.Namespace); err != nil {
function.MarkFinalizeFailed(err)
return fmt.Errorf("failed to perform finalizer for function: %w", err)
}

logger.Info("Removing Finalizer for Function after successfully perform the operations")
if ok := controllerutil.RemoveFinalizer(function, functionFinalizer); !ok {
return fmt.Errorf("failed to remove finalizer for function")
}

if err := r.Update(ctx, function); err != nil {
return fmt.Errorf("failed to remove finalizer for function: %w", err)
}

return nil
}

// ensureDeployment ensures the function is deployed and up-to-date
func (r *FunctionReconciler) ensureDeployment(ctx context.Context, function *v1alpha1.Function, repo *git.Repository, metadata *funcfn.Function) error {
logger := log.FromContext(ctx)
Expand Down Expand Up @@ -449,12 +386,3 @@ func (r *FunctionReconciler) isMiddlewareLatest(ctx context.Context, metadata *f

return latestMiddleware == functionMiddleware, nil
}

func (r *FunctionReconciler) Finalize(ctx context.Context, name, namespace string) error {
err := r.FuncCliManager.Delete(ctx, name, namespace)
if err != nil {
return fmt.Errorf("failed to finalize function: %w", err)
}

return nil
}
7 changes: 0 additions & 7 deletions internal/controller/function_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"knative.dev/func/pkg/functions"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

functionsdevv1alpha1 "github.com/functions-dev/func-operator/api/v1alpha1"
Expand Down Expand Up @@ -66,12 +65,6 @@ var _ = Describe("Function Controller", func() {
err := k8sClient.Get(ctx, typeNamespacedName, resource)
Expect(err).NotTo(HaveOccurred())

By("Remove finalizer to allow deletion")
if controllerutil.ContainsFinalizer(resource, functionFinalizer) {
controllerutil.RemoveFinalizer(resource, functionFinalizer)
Expect(k8sClient.Update(ctx, resource)).To(Succeed())
}

By("Cleanup the specific resource instance Function")
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())

Expand Down
63 changes: 0 additions & 63 deletions internal/funccli/Manager_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions internal/funccli/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type Manager interface {

Describe(ctx context.Context, name, namespace string) (funcfn.Instance, error)
Deploy(ctx context.Context, repoPath string, namespace string, opts DeployOptions) error
Delete(ctx context.Context, name, namespace string) error

GetCurrentVersion(ctx context.Context) (string, error)
GetLatestMiddlewareVersion(ctx context.Context, runtime, invoke string) (string, error)
Expand Down Expand Up @@ -235,15 +234,6 @@ func (m *managerImpl) Deploy(ctx context.Context, repoPath string, namespace str
return nil
}

func (m *managerImpl) Delete(ctx context.Context, name, namespace string) error {
out, err := m.Run(ctx, "", "delete", "--namespace", namespace, name)
if err != nil {
return fmt.Errorf("failed to delete function: %q. %w", out, err)
}

return nil
}

func (m *managerImpl) GetLatestMiddlewareVersion(ctx context.Context, runtime string, invoke string) (string, error) {
versions := struct {
MiddlewareVersions map[string]map[string]string `json:"middlewareVersions,omitempty"`
Expand Down