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

Add controller tests and CI #97

Merged
merged 12 commits into from
Jul 9, 2024
Merged

Add controller tests and CI #97

merged 12 commits into from
Jul 9, 2024

Conversation

codablock
Copy link
Contributor

@codablock codablock commented Jul 8, 2024

This PR does multiple things:

  1. Add some initial controller tests for ObjectTemplate. More will come via additional PRs.
  2. Add workflows to run tests and multiple other checks.

@codablock codablock force-pushed the feat-tests branch 2 times, most recently from ecc4f3b to 968ff88 Compare July 8, 2024 20:26
@codablock codablock changed the title WIP: Add initial tests for ObjectTemplate WIP: Add controller tests, CI and switch docker base image to wolfi-base Jul 8, 2024
@codablock codablock force-pushed the feat-tests branch 2 times, most recently from 8892bb4 to e0f2c03 Compare July 8, 2024 21:34
@codablock codablock changed the title WIP: Add controller tests, CI and switch docker base image to wolfi-base Add controller tests, CI and switch docker base image to wolfi-base Jul 8, 2024
@codablock codablock changed the title Add controller tests, CI and switch docker base image to wolfi-base Add controller tests and CI Jul 8, 2024
Copy link
Contributor

@erikgb erikgb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice @codablock! This is a huge improvement! I've added a few comments/suggestions, but mostly in the nits category.

fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: '1.22'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
go-version: '1.22'
go-version-file: go.mod

One less thing to maintain.

uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
go-version: '1.22'
go-version-file: go.mod

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func buildTestConfigMap(name string, namespace string, data map[string]string) *unstructured.Unstructured {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move all constructor helpers to the end of the file to keep focus on the tests. Or to a separate Go file.

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"math/rand/v2"
client2 "sigs.k8s.io/controller-runtime/pkg/client"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
client2 "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client"

Is this import alias really needed? If yes, I think you should find a better name. 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was not needed actually. For some reason gingko caused naming conflicts in the past due to the local import. But I really can't remember the details.


func TestAPIs(t *testing.T) {
kubeconfigName = "template-controller-tests.kubeconfig"
kubeconfigPath string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the kubeconfig used for? Do we need it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used it to debug RBAC issues, but I can actually remove it again

for k, v := range data {
m[k] = v
}
return &unstructured.Unstructured{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why Unstructured? I prefer type-safety.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Using typed objects now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, turns out the reason was simple: ObjectTemplate's template entries work with unstructured objects and there is no way around this. I'll at least use typed objects now and then convert them to unstructured.

for k, v := range data {
m[k] = v
}
return &unstructured.Unstructured{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why Unstructured? I prefer type-safety.

@codablock
Copy link
Contributor Author

Thanks @erikgb :) I fixed the issues you found and pushed it.

Copy link
Contributor

@erikgb erikgb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@codablock codablock merged commit 242968f into main Jul 9, 2024
2 checks passed
@codablock codablock deleted the feat-tests branch July 9, 2024 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants