Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add pet namespace if necessary #60

Merged
merged 1 commit into from
Oct 13, 2023
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
2 changes: 2 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:
with:
go-version-file: go.mod
cache-dependency-path: go.sum
- name: Create test cluster
run: make kind-cluster
- name: Run tests
run: make tests
- name: Upload Report to Codecov
Expand Down
2 changes: 2 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package client

import (
"k8s.io/apimachinery/pkg/runtime"
_ "k8s.io/client-go/plugin/pkg/client/auth" // package needed for auth providers like GCP
"k8s.io/client-go/rest"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -9,6 +10,7 @@ import (
type Client interface {
ctrlclient.Reader
ctrlclient.Writer
IsObjectNamespaced(obj runtime.Object) (bool, error)
}

func New(cfg *rest.Config) (Client, error) {
Expand Down
16 changes: 13 additions & 3 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,30 @@ func runTest(t *testing.T, cfg *rest.Config, test discovery.Test) {
step := test.Spec.Steps[i]
t.Run(fmt.Sprintf("step-%d", i+1), func(t *testing.T) {
t.Helper()
executeStep(t, test.BasePath, step, c)
executeStep(t, test.BasePath, namespace.Name, step, c)
})
}
}

func executeStep(t *testing.T, basePath string, step v1alpha1.TestStepSpec, c client.Client) {
func executeStep(t *testing.T, basePath string, namespace string, step v1alpha1.TestStepSpec, c client.Client) {
t.Helper()
for _, apply := range step.Apply {
resources, err := resource.Load(filepath.Join(basePath, apply.File))
if err != nil {
t.Fatal(err)
}
for i := range resources {
_, err := client.CreateOrUpdate(context.Background(), c, &resources[i])
resource := &resources[i]
if resource.GetNamespace() == "" {
namespaced, err := c.IsObjectNamespaced(resource)
if err != nil {
t.Fatal(err)
}
if namespaced {
resource.SetNamespace(namespace)
}
}
_, err := client.CreateOrUpdate(context.Background(), c, resource)
if err != nil {
t.Fatal(err)
}
Expand Down
1 change: 0 additions & 1 deletion testdata/tests/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: chainsaw-quick-start
namespace: default
data:
foo: bar
Loading