Skip to content
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

Use config structs to initialize reconcilers in the main setup function #1003

Open
fabriziosestito opened this issue Feb 10, 2025 · 0 comments

Comments

@fabriziosestito
Copy link
Contributor

Currently, we rely on several initialization functions to set up reconcilers, webhooks, and manager-related resources. These functions accept numerous parameters—and in some cases, they directly inject them into the reconcilers. This approach, however, isn’t very ergonomic. Instead, we could generate configuration structs from the CLI and use them to propagate the configuration variables in a cleaner wa.

Setup Functions:

  • setupManager:
    func setupManager(deploymentsNamespace string, metricsAddr string, probeAddr string, enableLeaderElection bool) (ctrl.Manager, error) {
  • setupReconcilers:
    func setupReconcilers(mgr ctrl.Manager, deploymentsNamespace, webhookServiceName string, alwaysAcceptAdmissionReviewsOnDeploymentsNamespace, featureGateAdmissionWebhookMatchConditions bool, otelConfiguration controller.TelemetryConfiguration) error {
  • setupWebhooks:
    func setupWebhooks(mgr ctrl.Manager, deploymentsNamespace string) error {

Example

func main() {
  // parse CLI flags

    config := Configuration{
        DeploymentsNamespace: deploymentsNamespace,
        WebhookServiceName: webhookServiceName,
        AlwaysAcceptAdmissionReviewsOnDeploymentsNS: alwaysAcceptAdmissionReviewsOnDeploymentsNamespace,
        FeatureGateAdmissionWebhookMatchConditions: featureGateAdmissionWebhookMatchConditions,
        Telemetry: otelConfiguration,
        MutualTLS: MTLSConfig{
            Enabled: enableMutualTLS,
            ClientCAConfigMapName: clientCAConfigMapName,
            ClientCAConfigMapNS: clientCAConfigMapNamespace,
        },
    }

    mgrOpts := ManagerOptions{
        MetricsAddr: metricsAddr,
        ProbeAddr: probeAddr,
        EnableLeaderElection: enableLeaderElection,
        DeploymentsNamespace: deploymentsNamespace,
        EnableMutualTLS: enableMutualTLS,
    }

    mgr, err := setupManager(mgrOpts)
    if err != nil {
        // handle error
    }

    if err := setupReconcilers(mgr, config); err != nil {
        // handle error
    }

    if err := setupWebhooks(mgr, config.DeploymentsNamespace); err != nil {
        // handle error
    }
}

func setupReconciler(mgr mgr, config Configuration) {
  reconciler := SomethingReconciler {
    Config: Configuration,
    ... // other dependencies
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

2 participants