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
Updates informer pkg to use TransformFunc() #25604
Conversation
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.
Thanks for the PR! A few comments to address below.
nodeInterface := k8s.ConvertToNode(k8sNode) | ||
typesNode := nodeInterface.(*k8sTypes.Node) | ||
k8sNodeParsed := k8s.ParseNode(typesNode, source.Unspec) |
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.
Note: This transformation was removed since #25282 updated GetK8sNode()
to return a slim node instead of a k8s node.
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.
Thanks! Changes LGTM
Just a couple of nits inline. Could you please also extend the commit message with the context around this change?
@giorio94 thanks for the /approval. I updated the PR description and commit 44598e0 resolves your nits. |
if transformer != nil { | ||
var err error | ||
if obj, err = transformer(d.Object); err != nil { | ||
return 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.
What's the behavior of the informer when we return an error here?
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 informer will not process the object. For example, the clustermesh-apiserver creates an informer that transforms k8s nodes to cilium nodes. If TransformToCiliumNode()
returns an error, the provided object is not created/updated. We could set RetryOnError
to re-enqueue the object. Thoughts?
@christarazi and others, is there anything else needed to merge this PR? |
Commit c2078e9 rebases due to merge conflicts from #25049. |
/test |
Removes ConvertFunc in favor of k8s upstream TransformFunc for object transformation. Informers are now created with TransformFunc instead of ConvertFunc to mutate certain resources in K8s Caches. Renames ConvertXXX functions to TransformXXX. Adds tests to improve test coverage of transformer functions. Signed-off-by: Daneyon Hansen <daneyon.hansen@solo.io>
Commit 0b535aa rebases to resolve a merge conflict. |
/test Job 'Cilium-PR-K8s-1.26-kernel-net-next' failed: Click to show.Test Name
Failure Output
Jenkins URL: https://jenkins.cilium.io/job/Cilium-PR-K8s-1.26-kernel-net-next/527/ If it is a flake and a GitHub issue doesn't already exist to track it, comment Then please upload the Jenkins artifacts to that issue. |
@christarazi thanks for kicking off the tests. The /home/jenkins/workspace/Cilium-PR-K8s-1.26-kernel-net-next/src/github.com/cilium/cilium/test/ginkgo-ext/scopes.go:515
Unexpected missed tail call
Expected
<int>: 1
to be ==
<int>: 0
/home/jenkins/workspace/Cilium-PR-K8s-1.26-kernel-net-next/src/github.com/cilium/cilium/test/k8s/updates.go:129 It appears the upgrade was unsuccessful (^ calls 22:18:19 STEP: Cilium is not ready yet: connectivity health is failing: Cluster connectivity is unhealthy on 'cilium-rwcn6': Exitcode: 1
Err: exit status 1
Stdout:
Stderr:
Defaulted container "cilium-agent" out of: cilium-agent, config (init), mount-cgroup (init), apply-sysctl-overwrites (init), mount-bpf-fs (init), clean-cilium-state (init), install-cni-binaries (init)
Error: Cannot get status/probe: Put "[http://%2Fvar%2Frun%2Fcilium%2Fhealth.sock/v1beta/status/probe":](http://%2Fvar%2Frun%2Fcilium%2Fhealth.sock/v1beta/status/probe) dial unix /var/run/cilium/health.sock: connect: no such file or directory
command terminated with exit code 1 I don't believe this is related to the PR so I wanted to get your input on how to proceed. |
It's flake #24514. |
Let's see if the next test run can pass without flakes. |
/test |
@christarazi when you have a moment, can you please advise me on how to move this PR forward? |
@danehans once the reviews are all approved from relevant code owner areas and the required CI tests are all passing, the maintainer's little helper marks the PR ready-to-merge like above. Someone then comes through and does last sanity checks and merges the PR. Thanks for the contribution! |
Hi all! Are we sure this is fine, and tested that it indeed works for the I would expect with the current version of client-go, the object type inside When applying this patch (the one below), I would expect it to pass, but it does not. Looks like pre this PR, this would work as expected, and the test would pass. diff --git a/pkg/k8s/factory_functions_test.go b/pkg/k8s/factory_functions_test.go
index 9478107618..8f0dfa720b 100644
--- a/pkg/k8s/factory_functions_test.go
+++ b/pkg/k8s/factory_functions_test.go
@@ -1271,6 +1271,24 @@ func (s *K8sSuite) Test_TransformToCCNP(c *C) {
},
expected: true,
},
+ {
+ name: "delete final state unknown transformation v2",
+ args: args{
+ obj: cache.DeletedFinalStateUnknown{
+ Key: "foo",
+ Obj: &types.SlimCNP{
+ CiliumNetworkPolicy: &v2.CiliumNetworkPolicy{},
+ },
+ },
+ },
+ want: cache.DeletedFinalStateUnknown{
+ Key: "foo",
+ Obj: &types.SlimCNP{
+ CiliumNetworkPolicy: &v2.CiliumNetworkPolicy{},
+ },
+ },
+ expected: true,
+ },
{
name: "delete final state unknown transformation",
args: args{ With this PR we get the following err;
When applying the following diff the tests pass again; diff --git a/pkg/k8s/factory_functions.go b/pkg/k8s/factory_functions.go
index 58a6cef2ef..9e8225634b 100644
--- a/pkg/k8s/factory_functions.go
+++ b/pkg/k8s/factory_functions.go
@@ -573,6 +573,11 @@ func TransformToCCNP(obj interface{}) (interface{}, error) {
},
}, nil
case cache.DeletedFinalStateUnknown:
+ _, isSlim := concreteObj.Obj.(*types.SlimCNP)
+ if isSlim {
+ return concreteObj, nil
+ }
+
ccnp, ok := concreteObj.Obj.(*cilium_v2.CiliumClusterwideNetworkPolicy)
if !ok {
return nil, fmt.Errorf("unknown object type %T", concreteObj.Obj) Ooor am I missing something..? been a few weeks since I was deep into this |
Also, feel free to ping me on PRs around this part of client-go, given I re(wrote) some of it a few months ago to fix some policy leaks we saw in cilium 😄 |
@odinuge thanks for the feedback. I think I see the issue that you describe. With this PR, If Should we allow unexpected objects to be returned to the caller or should all |
Thanks for looking into this @danehans! Yeah, the old godocs were pretty ambiguous, and the k8s behavior in I think it all boils down to this; cilium/pkg/k8s/informer/informer.go Lines 99 to 102 in a82f0fc
There, we always call the transform funcs, just like I should also have been explicit that my comment applies equally to all those transformer functions that return a different type than they receive; not only the CCNP one. 😄 Should we maybe open a new issue to track this? What do you think @danehans? If you to implement a fix here, I'm happy to review! 😄 (tho. I'm heading out of the office for the next two weeks 🌴 🇳🇴 ) |
The code above that you reference is within a |
But for eg CCNPs, we do want to convert the objects, so we have to add the/an converter func to the informer for that (and the other) resources.
We will continue to need it. When we switch to use the client-go deltaFifo transformer config, we should be able to rewrite the converter funcs to return the input value directly, together with no error, when the input is of the type |
I assigned myself #26240 and will push a PR to fix it. |
Thanks @danehans! |
ConvertFunc
in favor of TransformFunc for object transformation. Informers are now created withTransformFunc
instead ofConvertFunc
to mutate certain resources in K8s Caches.pkg/k8s/init_test.go
to improve test coverage of transformer functions.Fixes: #24923