Skip to content

Commit

Permalink
chore: incorporate comments
Browse files Browse the repository at this point in the history
Signed-off-by: Kumar Mallikarjuna <kumarmallikarjuna.work@gmail.com>
  • Loading branch information
kumar-mallikarjuna committed Jul 3, 2024
1 parent 74bec46 commit 14714d8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
8 changes: 6 additions & 2 deletions pkg/apis/testharness/v1beta1/test_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"k8s.io/client-go/rest"
)

const KubeconfigLoadingLazy = "Lazy"

// Create embedded struct to implement custom DeepCopyInto method
type RestConfig struct {
RC *rest.Config
Expand Down Expand Up @@ -126,8 +128,10 @@ type TestStep struct {
// Kubeconfig to use when applying and asserting for this step.
Kubeconfig string `json:"kubeconfig,omitempty"`

// Loads kubeconfig only when the previous steps have finished.
LazyLoadKubeconfig bool `json:"lazyLoadKubeconfig,omitempty"`
// Specifies the mode for loading Kubeconfig: Eager/Lazy. Defaults to Eager.
// +kubebuilder:default=Eager
// +kubebuilder:validation:Enum=Eager;Lazy
KubeconfigLoading string `json:"kubeconfigLoading,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
16 changes: 9 additions & 7 deletions pkg/test/case.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"k8s.io/client-go/tools/clientcmd"

"github.com/kudobuilder/kuttl/pkg/apis/testharness/v1beta1"
"github.com/kudobuilder/kuttl/pkg/report"
testutils "github.com/kudobuilder/kuttl/pkg/test/utils"
)
Expand Down Expand Up @@ -333,7 +334,7 @@ func (t *Case) Run(test *testing.T, ts *report.Testsuite) {
clients := map[string]client.Client{"": cl}

for _, testStep := range t.Steps {
if clients[testStep.Kubeconfig] != nil || testStep.LazyLoadKubeConfig {
if clients[testStep.Kubeconfig] != nil || testStep.KubeconfigLoading != v1beta1.KubeconfigLoadingLazy {
continue
}

Expand Down Expand Up @@ -370,17 +371,18 @@ func (t *Case) Run(test *testing.T, ts *report.Testsuite) {
tc.Assertions += len(testStep.Asserts)
tc.Assertions += len(testStep.Errors)

if testStep.LazyLoadKubeConfig {
errs := []error{}

if testStep.KubeconfigLoading == v1beta1.KubeconfigLoadingLazy {
cl, err = newClient(testStep.Kubeconfig)(false)
if err != nil {
setupReport.Failure = report.NewFailure(err.Error(), nil)
ts.AddTestcase(setupReport)
test.Fatal(err)
errs = append(errs, fmt.Errorf("failed to lazy-load kubeconfig '%v': %w", testStep.Kubeconfig, err))
} else {
clients[testStep.Kubeconfig] = cl
}
clients[testStep.Kubeconfig] = cl
}

errs := testStep.Run(test, ns.Name)
errs = append(errs, testStep.Run(test, ns.Name)...)
if len(errs) > 0 {
caseErr := fmt.Errorf("failed in step %s", testStep.String())
tc.Failure = report.NewFailure(caseErr.Error(), errs)
Expand Down
10 changes: 5 additions & 5 deletions pkg/test/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ type Step struct {

Timeout int

Kubeconfig string
LazyLoadKubeConfig bool
Client func(forceNew bool) (client.Client, error)
DiscoveryClient func() (discovery.DiscoveryInterface, error)
Kubeconfig string
KubeconfigLoading string
Client func(forceNew bool) (client.Client, error)
DiscoveryClient func() (discovery.DiscoveryInterface, error)

Logger testutils.Logger
}
Expand Down Expand Up @@ -556,7 +556,7 @@ func (s *Step) LoadYAML(file string) error {
exKubeconfig := env.Expand(s.Step.Kubeconfig)
s.Kubeconfig = cleanPath(exKubeconfig, s.Dir)
}
s.LazyLoadKubeConfig = s.Step.LazyLoadKubeconfig
s.KubeconfigLoading = s.Step.KubeconfigLoading
} else {
applies = append(applies, obj)
}
Expand Down

0 comments on commit 14714d8

Please # to comment.