-
Notifications
You must be signed in to change notification settings - Fork 32
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
refactor: tls policy status to state of the world tasks #885
Draft
KevFan
wants to merge
1
commit into
Kuadrant:main
Choose a base branch
from
KevFan:issues/824
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package controllers | ||
|
||
import ( | ||
certmanagerv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1" | ||
"github.com/kuadrant/policy-machinery/controller" | ||
"github.com/kuadrant/policy-machinery/machinery" | ||
"github.com/samber/lo" | ||
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" | ||
) | ||
|
||
func LinkGatewayToCertificateFunc(objs controller.Store) machinery.LinkFunc { | ||
gateways := lo.Map(objs.FilterByGroupKind(machinery.GatewayGroupKind), controller.ObjectAs[*gwapiv1.Gateway]) | ||
|
||
return machinery.LinkFunc{ | ||
From: machinery.GatewayGroupKind, | ||
To: CertManagerCertificateKind, | ||
Func: func(child machinery.Object) []machinery.Object { | ||
o := child.(*controller.RuntimeObject) | ||
cert := o.Object.(*certmanagerv1.Certificate) | ||
|
||
gateway, ok := lo.Find(gateways, func(item *gwapiv1.Gateway) bool { | ||
for _, l := range item.Spec.Listeners { | ||
if l.TLS != nil && l.TLS.CertificateRefs != nil { | ||
for _, certRef := range l.TLS.CertificateRefs { | ||
certRefNS := "" | ||
if certRef.Namespace == nil { | ||
certRefNS = item.GetNamespace() | ||
} else { | ||
certRefNS = string(*certRef.Namespace) | ||
} | ||
if certRefNS == cert.GetNamespace() && string(certRef.Name) == cert.GetName() { | ||
return true | ||
} | ||
} | ||
} | ||
} | ||
|
||
return false | ||
}) | ||
|
||
if ok { | ||
return []machinery.Object{&machinery.Gateway{Gateway: gateway}} | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
} | ||
|
||
func LinkGatewayToIssuerFunc(objs controller.Store) machinery.LinkFunc { | ||
gateways := lo.Map(objs.FilterByGroupKind(machinery.GatewayGroupKind), controller.ObjectAs[*gwapiv1.Gateway]) | ||
|
||
return machinery.LinkFunc{ | ||
From: machinery.GatewayGroupKind, | ||
To: CertManagerIssuerKind, | ||
Func: func(child machinery.Object) []machinery.Object { | ||
o := child.(*controller.RuntimeObject) | ||
issuer := o.Object.(*certmanagerv1.Issuer) | ||
|
||
// TODO: Refine | ||
gateway, ok := lo.Find(gateways, func(item *gwapiv1.Gateway) bool { | ||
return item.GetNamespace() == issuer.GetNamespace() | ||
}) | ||
|
||
if ok { | ||
return []machinery.Object{&machinery.Gateway{Gateway: gateway}} | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
} | ||
|
||
func LinkGatewayToClusterIssuerFunc(objs controller.Store) machinery.LinkFunc { | ||
gateways := lo.Map(objs.FilterByGroupKind(machinery.GatewayGroupKind), controller.ObjectAs[machinery.Object]) | ||
|
||
return machinery.LinkFunc{ | ||
From: machinery.GatewayGroupKind, | ||
To: CertManagerClusterIssuerKind, | ||
Func: func(child machinery.Object) []machinery.Object { | ||
o := child.(*controller.RuntimeObject) | ||
_ = o.Object.(*certmanagerv1.ClusterIssuer) | ||
return gateways | ||
}, | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hmmm... We may expect more of these, and not only with this particular resource.
This is because, as a pattern, we check the presence of the resource in the topology, and not with the API server. But more importantly, because, even though it's "state of the world" reconciliation and therefore the controller already knows about all resources that exist (because it lists them all), the library watching for changes to the cache writes to the subscription channel resource by resource.
I think we should consider fixing this in the Policy Machinery instead, because now it may be defeating the purpose of "state of the world". We may be able to make the call to
cache.Replace
truly atomic – assuming it won't break with the granularity of multiple event types. I have a couple of ideas.