Skip to content

Commit eaf5860

Browse files
authored
refactor: kube utils (#1689)
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
1 parent c339906 commit eaf5860

File tree

7 files changed

+15
-21
lines changed

7 files changed

+15
-21
lines changed

pkg/client/pet.go

-11
This file was deleted.

pkg/runner/processors/test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/kyverno/chainsaw/pkg/runner/summary"
2525
"github.com/kyverno/chainsaw/pkg/runner/timeout"
2626
"github.com/kyverno/chainsaw/pkg/testing"
27+
"github.com/kyverno/chainsaw/pkg/utils/kube"
2728
"github.com/kyverno/pkg/ext/output/color"
2829
corev1 "k8s.io/api/core/v1"
2930
"k8s.io/apimachinery/pkg/api/errors"
@@ -133,14 +134,14 @@ func (p *testProcessor) Run(ctx context.Context, bindings binding.Bindings, nspa
133134
if nspacer == nil || p.test.Test.Spec.Namespace != "" {
134135
var ns corev1.Namespace
135136
if p.test.Test.Spec.Namespace != "" {
136-
ns = client.Namespace(p.test.Test.Spec.Namespace)
137+
ns = kube.Namespace(p.test.Test.Spec.Namespace)
137138
} else {
138-
ns = client.PetNamespace()
139+
ns = kube.PetNamespace()
139140
}
140141
namespace = &ns
141142
}
142143
if namespace != nil {
143-
object := client.ToUnstructured(namespace)
144+
object := kube.ToUnstructured(namespace)
144145
bindings = apibindings.RegisterNamedBinding(ctx, bindings, "namespace", object.GetName())
145146
if p.test.Test.Spec.NamespaceTemplate != nil && p.test.Test.Spec.NamespaceTemplate.Value != nil {
146147
template := v1alpha1.Any{

pkg/runner/processors/tests.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/kyverno/chainsaw/pkg/runner/summary"
2525
"github.com/kyverno/chainsaw/pkg/runner/timeout"
2626
"github.com/kyverno/chainsaw/pkg/testing"
27+
"github.com/kyverno/chainsaw/pkg/utils/kube"
2728
"github.com/kyverno/pkg/ext/output/color"
2829
"k8s.io/apimachinery/pkg/api/errors"
2930
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -84,8 +85,8 @@ func (p *testsProcessor) Run(ctx context.Context, bindings binding.Bindings) {
8485
bindings = apibindings.RegisterClusterBindings(ctx, bindings, clusterConfig, clusterClient)
8586
if clusterClient != nil {
8687
if p.config.Namespace.Name != "" {
87-
namespace := client.Namespace(p.config.Namespace.Name)
88-
object := client.ToUnstructured(&namespace)
88+
namespace := kube.Namespace(p.config.Namespace.Name)
89+
object := kube.ToUnstructured(&namespace)
8990
bindings = apibindings.RegisterNamedBinding(ctx, bindings, "namespace", object.GetName())
9091
if p.config.Namespace.Template != nil && p.config.Namespace.Template.Value != nil {
9192
template := v1alpha1.Any{

pkg/client/namespace.go renamed to pkg/utils/kube/namespace.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
package client
1+
package kube
22

33
import (
4+
"fmt"
5+
6+
petname "github.com/dustinkirkland/golang-petname"
47
corev1 "k8s.io/api/core/v1"
58
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
69
)
@@ -18,5 +21,5 @@ func Namespace(name string) corev1.Namespace {
1821
}
1922

2023
func PetNamespace() corev1.Namespace {
21-
return Namespace(Pet())
24+
return Namespace(fmt.Sprintf("chainsaw-%s", petname.Generate(2, "-")))
2225
}

pkg/client/namespace_test.go renamed to pkg/utils/kube/namespace_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package client
1+
package kube
22

33
import (
44
"testing"

pkg/client/unstructured.go renamed to pkg/utils/kube/unstructured.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package client
1+
package kube
22

33
import (
44
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"

pkg/client/unstructured_test.go renamed to pkg/utils/kube/unstructured_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package client
1+
package kube
22

33
import (
44
"testing"

0 commit comments

Comments
 (0)