-
Notifications
You must be signed in to change notification settings - Fork 14
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
Conversation
ecc4f3b
to
968ff88
Compare
8892bb4
to
e0f2c03
Compare
There was a problem hiding this 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.
.github/workflows/tests.yml
Outdated
fetch-depth: 0 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.22' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go-version: '1.22' | |
go-version-file: go.mod |
One less thing to maintain.
.github/workflows/tests.yml
Outdated
uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.22' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 { |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. 😉
There was a problem hiding this comment.
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.
controllers/suite_test.go
Outdated
|
||
func TestAPIs(t *testing.T) { | ||
kubeconfigName = "template-controller-tests.kubeconfig" | ||
kubeconfigPath string |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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{ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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{ |
There was a problem hiding this comment.
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.
Thanks @erikgb :) I fixed the issues you found and pushed it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This PR does multiple things: