-
Notifications
You must be signed in to change notification settings - Fork 33
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
feat: check dependency for state of the world reconciler #870
Merged
Merged
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,15 @@ import ( | |
"fmt" | ||
"strings" | ||
|
||
certmanagerv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1" | ||
egv1alpha1 "github.com/envoyproxy/gateway/api/v1alpha1" | ||
"github.com/go-logr/logr" | ||
"github.com/google/go-cmp/cmp" | ||
"github.com/kuadrant/policy-machinery/controller" | ||
"github.com/kuadrant/policy-machinery/machinery" | ||
istioclientgoextensionv1alpha1 "istio.io/client-go/pkg/apis/extensions/v1alpha1" | ||
istioclientnetworkingv1alpha3 "istio.io/client-go/pkg/apis/networking/v1alpha3" | ||
istioclientgosecurityv1beta1 "istio.io/client-go/pkg/apis/security/v1beta1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
|
@@ -20,6 +25,9 @@ import ( | |
kuadrantv1alpha1 "github.com/kuadrant/kuadrant-operator/api/v1alpha1" | ||
kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1" | ||
kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2" | ||
"github.com/kuadrant/kuadrant-operator/pkg/envoygateway" | ||
"github.com/kuadrant/kuadrant-operator/pkg/istio" | ||
kuadrantgatewayapi "github.com/kuadrant/kuadrant-operator/pkg/library/gatewayapi" | ||
"github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant" | ||
) | ||
|
||
|
@@ -36,9 +44,6 @@ func NewPolicyMachineryController(manager ctrlruntime.Manager, client *dynamic.D | |
controller.WithLogger(logger), | ||
controller.WithClient(client), | ||
controller.WithRunnable("kuadrant watcher", controller.Watch(&kuadrantv1beta1.Kuadrant{}, kuadrantv1beta1.KuadrantResource, metav1.NamespaceAll)), | ||
controller.WithRunnable("gatewayclass watcher", controller.Watch(&gwapiv1.GatewayClass{}, controller.GatewayClassesResource, metav1.NamespaceAll)), | ||
controller.WithRunnable("gateway watcher", controller.Watch(&gwapiv1.Gateway{}, controller.GatewaysResource, metav1.NamespaceAll)), | ||
controller.WithRunnable("httproute watcher", controller.Watch(&gwapiv1.HTTPRoute{}, controller.HTTPRoutesResource, metav1.NamespaceAll)), | ||
controller.WithRunnable("dnspolicy watcher", controller.Watch(&kuadrantv1alpha1.DNSPolicy{}, kuadrantv1alpha1.DNSPoliciesResource, metav1.NamespaceAll)), | ||
controller.WithRunnable("tlspolicy watcher", controller.Watch(&kuadrantv1alpha1.TLSPolicy{}, kuadrantv1alpha1.TLSPoliciesResource, metav1.NamespaceAll)), | ||
controller.WithRunnable("authpolicy watcher", controller.Watch(&kuadrantv1beta2.AuthPolicy{}, kuadrantv1beta2.AuthPoliciesResource, metav1.NamespaceAll)), | ||
|
@@ -59,6 +64,71 @@ func NewPolicyMachineryController(manager ctrlruntime.Manager, client *dynamic.D | |
controller.WithReconcile(buildReconciler(client)), | ||
} | ||
|
||
ok, err := kuadrantgatewayapi.IsGatewayAPIInstalled(manager.GetRESTMapper()) | ||
if err != nil || !ok { | ||
logger.Info("gateway api is not installed, skipping watches and reconcilers", "err", err) | ||
} else { | ||
controllerOpts = append(controllerOpts, | ||
controller.WithRunnable("gatewayclass watcher", controller.Watch(&gwapiv1.GatewayClass{}, controller.GatewayClassesResource, metav1.NamespaceAll)), | ||
controller.WithRunnable("gateway watcher", controller.Watch(&gwapiv1.Gateway{}, controller.GatewaysResource, metav1.NamespaceAll)), | ||
controller.WithRunnable("httproute watcher", controller.Watch(&gwapiv1.HTTPRoute{}, controller.HTTPRoutesResource, metav1.NamespaceAll)), | ||
) | ||
} | ||
|
||
ok, err = envoygateway.IsEnvoyGatewayInstalled(manager.GetRESTMapper()) | ||
if err != nil || !ok { | ||
logger.Info("envoygateway is not installed, skipping related watches and reconcilers", "err", err) | ||
} else { | ||
controllerOpts = append(controllerOpts, | ||
controller.WithRunnable("envoypatchpolicy watcher", controller.Watch(&egv1alpha1.EnvoyPatchPolicy{}, envoygateway.EnvoyPatchPoliciesResource, metav1.NamespaceAll)), | ||
controller.WithRunnable("envoyextensionpolicy watcher", controller.Watch(&egv1alpha1.EnvoyExtensionPolicy{}, envoygateway.EnvoyExtensionPoliciesResource, metav1.NamespaceAll)), | ||
controller.WithRunnable("envoysecuritypolicy watcher", controller.Watch(&egv1alpha1.SecurityPolicy{}, envoygateway.SecurityPoliciesResource, metav1.NamespaceAll)), | ||
controller.WithObjectKinds( | ||
envoygateway.EnvoyPatchPolicyGroupKind, | ||
envoygateway.EnvoyExtensionPolicyGroupKind, | ||
envoygateway.SecurityPolicyGroupKind, | ||
), | ||
// TODO: add object links | ||
) | ||
// TODO: add specific tasks to workflow | ||
Comment on lines
+91
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Future TODOs that would be completed by other issues as functionality is migrated to the workflow |
||
} | ||
|
||
ok, err = istio.IsIstioInstalled(manager.GetRESTMapper()) | ||
if err != nil || !ok { | ||
logger.Info("istio is not installed, skipping related watches and reconcilers", "err", err) | ||
} else { | ||
controllerOpts = append(controllerOpts, | ||
controller.WithRunnable("envoyfilter watcher", controller.Watch(&istioclientnetworkingv1alpha3.EnvoyFilter{}, istio.EnvoyFiltersResource, metav1.NamespaceAll)), | ||
controller.WithRunnable("wasmplugin watcher", controller.Watch(&istioclientgoextensionv1alpha1.WasmPlugin{}, istio.WasmPluginsResource, metav1.NamespaceAll)), | ||
controller.WithRunnable("authorizationpolicy watcher", controller.Watch(&istioclientgosecurityv1beta1.AuthorizationPolicy{}, istio.AuthorizationPoliciesResource, metav1.NamespaceAll)), | ||
controller.WithObjectKinds( | ||
istio.EnvoyFilterGroupKind, | ||
istio.WasmPluginGroupKind, | ||
istio.AuthorizationPolicyGroupKind, | ||
), | ||
// TODO: add object links | ||
) | ||
// TODO: add istio specific tasks to workflow | ||
} | ||
|
||
ok, err = kuadrantgatewayapi.IsCertManagerInstalled(manager.GetRESTMapper(), logger) | ||
if err != nil || !ok { | ||
logger.Info("cert manager is not installed, skipping related watches and reconcilers", "err", err) | ||
} else { | ||
controllerOpts = append(controllerOpts, | ||
controller.WithRunnable("certificate watcher", controller.Watch(&certmanagerv1.Certificate{}, CertManagerCertificatesResource, metav1.NamespaceAll)), | ||
controller.WithRunnable("issuers watcher", controller.Watch(&certmanagerv1.Issuer{}, CertManagerIssuersResource, metav1.NamespaceAll)), | ||
controller.WithRunnable("clusterissuers watcher", controller.Watch(&certmanagerv1.Certificate{}, CertMangerClusterIssuersResource, metav1.NamespaceAll)), | ||
controller.WithObjectKinds( | ||
CertManagerCertificateKind, | ||
CertManagerIssuerKind, | ||
CertManagerClusterIssuerKind, | ||
), | ||
// TODO: add object links | ||
) | ||
// TODO: add tls policy specific tasks to workflow | ||
} | ||
|
||
return controller.NewController(controllerOpts...) | ||
} | ||
|
||
|
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
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
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.
What should happen if there is no gateway currently installed that we can use? We would need at least one, I am asking the same question of the cert manger if that is not installed should we try reconcile. I am aware that the user may install these resources later, but that would mean restarting the operator (which I am okay with).
I guess my question is; should we even start the operator if there is no gateway that we can use installed?
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, not sure what's the best approach but I've went with the approach of the existing controllers which gets disabled rather than crash when a dependency CRD is not detected (which we have existing integration tests for) 🤔
Personally, I think it's better not to crash and have this reported in the Policy Status also since a user may not initially look through logs on why things are not working as expected.
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 agree, the operator should not crash. Personally, for now, what I would do is to disable watchers and maybe steps in the workflow. There should be a task responsible for the kuadrant CR status that watches for changes on Kuadrant CRDs (which we can assume they exist). Then, the task checks for GatewayAPI being installed and reports in the status if not. Same for policies.
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.
After the call I am happy that we have a plan to get the errors these missing CRDs and resources can cause into the status of kuadrant and / or the related policies. Would be good to create issue for any follow up work this may need.