-
Notifications
You must be signed in to change notification settings - Fork 70
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
srlinux: Use controller-runtime dynamic client instead of a generated clientset #326
Conversation
A fake client exists from controller-runtime client -- https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/client/fake?utm_source=godoc This allows to write unit tests for the CRs in question. Example - https://github.com/elastic/cloud-on-k8s/blob/main/pkg/controller/apmserver/controller_test.go |
Pull Request Test Coverage Report for Build 4441135746
💛 - Coveralls |
Hi @alexmasi @marcushines I have also updated the srlinux example topology and startup file to feature srlinux 22.11.2 version and recent kind/kne versions.
Additionally, I verified that all OC services work based on the updated example topology. I would appreciate your comments and presubmit testing (granted you align the manifests to the new versions) |
topo/node/srl/srl_test.go
Outdated
@@ -62,6 +64,11 @@ func (f *fakeWatch) ResultChan() <-chan watch.Event { | |||
} | |||
|
|||
func TestNew(t *testing.T) { |
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.
func setUp() func() {
origSrlinuxClient := newSrlinuxClient
newSrlinuxClient = func(_ *rest.Config) (ctrlclient.Client, error) {
return nil, nil
}
return func() {
newSrlLinuxClient = origSrLinuxClient
}
then your tests
defer setUp()()
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.
@marcushines I used a different name, but kept the logic. Interesting way of doing setup/teardown, huh.
3cdf0c1
to
cbde803
Compare
Hi @alexmasi I updated the manifest, would be cool to see if we can run a presubmit using this branch |
@@ -2361,9 +2401,6 @@ | |||
} | |||
}, | |||
"srl_nokia-network-instance:network-instance": [ | |||
{ | |||
"name": "DEFAULT" | |||
}, |
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 like this line to be reverted, helps align this topo with the featureprofiles defaults
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.
done a5ecb13
topo/node/srl/srl.go
Outdated
if err != nil { | ||
return err | ||
} | ||
n.ControllerClient.Delete(ctx, &srlinuxv1.Srlinux{ObjectMeta: metav1.ObjectMeta{Name: n.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.
check err?
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.
done 3190719
go.mod
Outdated
@@ -21,7 +21,7 @@ require ( | |||
github.com/scrapli/scrapligocfg v1.0.0 | |||
github.com/spf13/cobra v1.6.1 | |||
github.com/spf13/pflag v1.0.5 | |||
github.com/srl-labs/srl-controller v0.4.6 | |||
github.com/srl-labs/srl-controller v0.4.7-0.20230311230716-e1c96973d463 |
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.
the container is v0.5.0 and the corresponding lib is v0.4.7, is that intended?
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.
yes, just for testing inside this PR.
If tests are ok I will take both as 0.5.0
I spoke to Marcus and I will regenerate the manifests to use :latest
container tag, so that manifest stays more-or-less static
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.
yeah I tested on my machine, good to switch to 0.5.0
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.
done
/gcbrun |
- args: | ||
- --health-probe-bind-address=:8081 | ||
- --metrics-bind-address=127.0.0.1:8080 | ||
- --leader-elect | ||
command: | ||
- /manager | ||
image: ghcr.io/srl-labs/srl-controller:0.4.6 | ||
image: ghcr.io/srl-labs/srl-controller:latest |
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.
move this to 0.5.0
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.
done
go.mod
Outdated
@@ -21,7 +21,7 @@ require ( | |||
github.com/scrapli/scrapligocfg v1.0.0 | |||
github.com/spf13/cobra v1.6.1 | |||
github.com/spf13/pflag v1.0.5 | |||
github.com/srl-labs/srl-controller v0.4.6 | |||
github.com/srl-labs/srl-controller v0.4.7-0.20230311230716-e1c96973d463 |
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.
yeah I tested on my machine, good to switch to 0.5.0
@@ -10,7 +10,7 @@ nodes: { | |||
vendor: NOKIA | |||
model: "ixr6e" | |||
config:{ | |||
image: "ghcr.io/nokia/srlinux:22.6.4" | |||
image: "ghcr.io/nokia/srlinux:22.11.2" |
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.
just remove this line so it defaults to the :latest tag (also in the other nokia examples as well)
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.
done, I added a comment about this behavior if that's ok. 6443adf
Okay testing 0.4.7-xxxxxx commit with 0.5.0-rc worked on my machine. The presubmit in its current state will not pass, I am working on a better presubmit to test things like this Once the versions are 0.5.0 and the comments are addressed I will get this merged |
/gcbrun |
Hi all,
It seems it is considered to be a common (good?) practice nowadays to use an API client provided by the controller-runtime package that allows users to work with both structured and unstructured objects while removing the need to generate clientsets [1] [2] [3] [4].
In this PR I am removing srl-controller clientset in favor of the controller-runtime client. Currently I put controller-runtime client under the Node struct, but if this approach will be considered good by the kne team it definitely makes sense to initialize a controller once for all node implementations. Each node implementation just needs to register its own schema with the client to make it all work.
This PR works with the tip of the branch that nokia works on in parallel - srl-labs/srl-controller#31.
Looking forward to your review comments about this approach.
/cc @marcushines
[1] -- https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.14.5/pkg/client
[2] -- https://hackernoon.com/platforms-on-k8s-with-golang-watch-any-crd-0v2o3z1q#h-interacting-with-cr-ds-the-new-way
[3] -- kubernetes-sigs/kubebuilder#1152 (comment)
[4] -- https://medium.com/@timebertt/kubernetes-controllers-at-scale-clients-caches-conflicts-patches-explained-aa0f7a8b4332#053d