Skip to content

Commit

Permalink
feat: avoid importing kubectl deps when using ApplysetApplier
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwenma committed May 3, 2023
1 parent c3c2bb8 commit 2eb6c43
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pkg/patterns/declarative/pkg/applier/applylib.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build without_kubectl_deps
// +build without_kubectl_deps

package applier

import (
Expand All @@ -13,6 +16,8 @@ import (
"sigs.k8s.io/kubebuilder-declarative-pattern/applylib/applyset"
)

var DefaultApplier = NewApplySetApplier(metav1.PatchOptions{}, metav1.DeleteOptions{}, ApplysetOptions{})

type ApplysetOptions struct {
Tooling string
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/patterns/declarative/pkg/applier/direct.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !without_kubectl_deps
// +build !without_kubectl_deps

package applier

import (
Expand All @@ -6,7 +9,9 @@ import (
"os"
"strings"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubectl/pkg/util/prune"
"sigs.k8s.io/kubebuilder-declarative-pattern/applylib/applyset"

"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -23,6 +28,11 @@ import (
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/declarative/pkg/manifest"
)

var DefaultApplier = NewDirectApplier()
var NewParentRef = func(meta.RESTMapper, runtime.Object, string, string) (applyset.Parent, error) {
return nil, nil
}

type DirectApplier struct {
inner directApplierSite
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/patterns/declarative/pkg/applier/exec.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !without_kubectl_deps
// +build !without_kubectl_deps

/*
Copyright 2018 The Kubernetes Authors.
Expand Down
2 changes: 1 addition & 1 deletion pkg/patterns/declarative/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (e *ErrorResult) Error() string {
}

// For mocking
var defaultApplier = applier.NewDirectApplier()
var defaultApplier = applier.DefaultApplier

func (r *Reconciler) Init(mgr manager.Manager, prototype DeclarativeObject, opts ...ReconcilerOption) error {
r.prototype = prototype
Expand Down
3 changes: 3 additions & 0 deletions pkg/test/testreconciler/simpletest/controller_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build without_kubectl_deps
// +build without_kubectl_deps

package simpletest

import (
Expand Down

0 comments on commit 2eb6c43

Please sign in to comment.