Crossplane Provider for SQL

repository·master·Indexed 41 days ago

https://github.com/crossplane-contrib/provider-sql

A Crossplane provider for RDBMS schema management and manipulation. It orchestrates existing SQL servers by managing databases, users, grants, and other schema-level objects for MySQL, PostgreSQL, and MSSQL.

Tokens
1.3K
Snippets
3
Records
5
Agent score
50%

What's inside Crossplane Provider SQL

  1. Manage SQL resources by database flavor

    master

    The provider-sql orchestrates RDBMS schema management (databases, users, etc.) but does not create the server instances themselves. Supported resources vary by SQL flavor:

    • MySQL: Supports Database, Grant, and User.
    • PostgreSQL: Supports Database, Grant, DefaultPrivileges, Extension, and Role.
    • MSSQL: Supports Database, Grant, and User.

    To reduce load on managed databases, the provider reconciles resources every 10 minutes.

  2. Install the Crossplane Provider for SQL

    master

    You can install the provider using either a Kubernetes manifest or the Crossplane CLI. Ensure you update the image tag to the latest release before installing.

    Using kubectl: Apply a Provider resource with the desired package version.

    Using Crossplane CLI: Use the up ctp provider install command with the package reference.

    # Using kubectl
    cat << EOF | kubectl apply -f -
    apiVersion: pkg.crossplane.io/v1
    kind: Provider
    metadata:
      name: provider-sql
    spec:
      package: xpkg.upbound.io/crossplane-contrib/provider-sql:v0.9.0
    EOF
    
    # Using Crossplane CLI
    up ctp provider install xpkg.upbound.io/crossplane-contrib/provider-sql:v0.9.0
  3. Develop the provider locally

    master

    To run the provider controller locally against a Kubernetes cluster (e.g., kind), follow these steps:

    1. Start the API proxy: Since the controller runs outside the cluster, make the API server accessible via a proxy.
    2. Run the controller: Use make run to start the controller.
    3. Prepare ProviderConfig: Create a secret containing a modified KUBECONFIG that points to the local proxy, then apply a ProviderConfig using that secret.
    4. Create a Release: Apply a Release resource associated with your local ProviderConfig.
    # 1. Start API proxy
    sudo kubectl proxy --port=8081
    
    # 2. Run controller
    make run
    
    # 3. Prepare ProviderConfig for local cluster (e.g. kind)
    KUBECONFIG=$(kind get kubeconfig | sed -e 's|server:\s*.*$|server: http://localhost:8081|g')
    kubectl -n crossplane-system create secret generic cluster-config --from-literal=kubeconfig="${KUBECONFIG}"
    kubectl apply -f examples/provider-config/provider-config-with-secret.yaml
    
    # 4. Create a Release
    kubectl create -f examples/sample/release.yaml
  4. Configure connection details for SQL servers

    master

    To manage SQL resources, you must provide a Kubernetes secret containing the connection details for an existing SQL server. This secret can be created manually or automatically provisioned by another provider (e.g., provider-gcp creating a CloudSQLInstance).

    When creating a manual secret, ensure you include the following keys:

    • username
    • password
    • endpoint
    • port
    kubectl create secret generic db-conn \
      --from-literal=username=admin \
      --from-literal=password='t0ps3cr3t' \
      --from-literal=endpoint=my.sql-server.com \
      --from-literal=port=3306
  5. Configure the provider-sql binary flags

    master

    The provider-sql binary can be configured using several command-line flags to control logging, reconciliation behavior, and metrics. Many of these flags also support environment variables for configuration in containerized environments.

    Available Flags

    FlagShortDefaultDescription
    --debug-dfalseRun with debug logging.
    --poll10mPoll interval: how often an individual resource should be checked for drift.
    --sync-s1hSync period: how often all resources will be double-checked for drift from the desired state.
    --leader-election-lfalseUse leader election for the controller manager. (Env: LEADER_ELECTION)
    --max-reconcile-rate10The global maximum rate per second at which resources may be checked for drift.
    --enable-management-policiestrueEnable/disable support for Management Policies. (Env: ENABLE_MANAGEMENT_POLICIES)
    --poll-state-metric5sState metric recording interval.
    --metrics-bind-address:8080The address the metrics endpoint binds to.