Sign inSign up

pacecar/keycloak-operator

By pacecar

Updated over 3 years ago

Image
0

2.5K

pacecar/keycloak-operator repository overview

Build Status Go Report Card Coverage Status License

Keycloak Operator

A Kubernetes Operator based on the Operator SDK for creating and syncing resources in Keycloak.

Help and Documentation

The official documentation might be found in the here.

Reporting Security Vulnerabilities

If you've found a security vulnerability, please look at the instructions on how to properly report it

Reporting an issue

If you believe you have discovered a defect in the Keycloak Operator please open an issue in our Issue Tracker. Please remember to provide a good summary, description as well as steps to reproduce the issue.

Supported Custom Resources

CustomResourceDefinitionDescription
KeycloakManages, installs and configures Keycloak on the cluster
KeycloakRealmRepresents a realm in a keycloak server
KeycloakClientRepresents a client in a keycloak server
KeycloakBackupManage Keycloak database backups

Deploying to a Cluster

Note: You will need a running Kubernetes or OpenShift cluster to use the Operator

  1. Run make cluster/prepare # This will apply the necessary Custom Resource Definitions (CRDs) and RBAC rules to the clusters
  2. Run kubectl apply -f deploy/operator.yaml # This will start the operator in the current namespace
Creating Keycloak Instance

Once the CRDs and RBAC rules are applied and the operator is running. Use the examples from the operator.

  1. Run kubectl apply -f deploy/examples/keycloak/keycloak.yaml

Building from Source

Local Development

Note: You will need a running Kubernetes or OpenShift cluster to use the Operator

  1. clone this repo to $GOPATH/src/github.com/keycloak/keycloak-operator
  2. run make setup/mod cluster/prepare
  3. run make code/run -- The above step will launch the operator on the local machine -- To see how do debug the operator or how to deploy to a cluster, see below alternatives to step 3
  4. In a new terminal run make cluster/create/examples
  5. Optional: configure Ingress and DNS Resolver
    • minikube:
      -- run minikube addons enable ingress
      -- run ./hack/modify_etc_hosts.sh
    • Docker for Mac:
      -- run kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-0.32.0/deploy/static/provider/cloud/deploy.yaml (see also https://kubernetes.github.io/ingress-nginx/deploy/)
      -- run ./hack/modify_etc_hosts.sh keycloak.local 127.0.0.1
  6. Run make test/e2e

To clean the cluster (Removes CRDs, CRs, RBAC and namespace)

  1. run make cluster/clean
Alternative Step 2: Debug in Goland

Debug the operator in Goland

  1. go get -u github.com/go-delve/delve/cmd/dlv
  2. Create new Go Build debug configuration
  3. Change the properties to the following
* Name = Keycloak Operator
* Run Kind = File
* Files = <project full path>/cmd/manager/main.go
* Working Directory = <project full path>
* Environment = KUBERNETES_CONFIG=<kube config path>;WATCH_NAMESPACE=keycloak
  1. Apply and click Debug Keycloak operator
Alternative Step 3: Debug in VSCode

Debug the operator in VS Code

  1. go get -u github.com/go-delve/delve/cmd/dlv
  2. Create new launch configuration, changing your kube config location
{
  "name": "Keycloak Operator",
  "type": "go",
  "request": "launch",
  "mode": "auto",
  "program": "${workspaceFolder}/cmd/manager/main.go",
  "env": {
    "WATCH_NAMESPACE": "keycloak",
    "KUBERNETES_CONFIG": "<kube config path>"
  },
  "cwd": "${workspaceFolder}",
  "args": []
}
  1. Debug Keycloak Operator
Alternative Step 3: Deploying to a Cluster

Deploy the operator into the running cluster

  1. build image with operator-sdk build <image registry>/<organisation>/keycloak-operator:<tag>. e.g. operator-sdk build quay.io/keycloak/keycloak-operator:test
  2. Change the image property in deploy/operator.yaml to the above full image path
  3. run kubectl apply -f deploy/operator.yaml -n <NAMESPACE>
Alternative Step 6: Debug the e2e tests in Goland

Debug the e2e operator tests in Goland

  1. Set Test kind to Package
  2. Set Working directory to <your project directory>
  3. Set Go tool arguments to -i -parallel=1
  4. Set Program arguments to -root=<your project directory> -kubeconfig=<your home directory>/.kube/config -globalMan deploy/empty-init.yaml -namespacedMan deploy/empty-init.yaml -test.v -singleNamespace -localOperator -test.timeout 0
  5. Apply and click Debug Keycloak operator
Makefile command reference
Operator Setup Management
CommandDescription
make cluster/prepareCreates the keycloak namespace, applies all CRDs to the cluster and sets up the RBAC files
make cluster/cleanDeletes the keycloak namespace, all keycloak.org CRDs and all RBAC files named keycloak-operator
make cluster/create/examplesApplies the example Keycloak and KeycloakRealm CRs
Tests
CommandDescription
make test/unitRuns unit tests
make test/e2eRuns e2e tests with operator ran locally
make test/e2e-latest-imageRuns e2e tests with latest available operator image running in the cluster
make test/e2e-local-imageRuns e2e tests with local operator image running in the cluster
make test/coverage/preparePrepares coverage report from unit and e2e test results
make test/coverageGenerates coverage report
Local Development
CommandDescription
make setupRuns setup/mod setup/githooks code/gen
make setup/githooksCopys githooks from ./githooks to .git/hooks
make setup/modResets the main module's vendor directory to include all packages
make setup/operator-sdkInstalls the operator-sdk
make code/runRuns the operator locally for development purposes
make code/compileBuilds the operator
make code/genGenerates/Updates the operator files based on the CR status and spec definitions
make code/checkChecks for linting errors in the code
make code/fixFormats code using gofmt
make code/lintChecks for linting errors in the code
CI
CommandDescription
make setup/travisDownloads operator-sdk, makes it executable and copys to /usr/local/bin/
Components versions

All images used by the Operator might be controlled using dedicated Environmental Variables:

ImageEnvironment variableDefault
KeycloakRELATED_IMAGE_KEYCLOAKquay.io/keycloak/keycloak:9.0.2
RHSSO for OpenJ9RELATED_IMAGE_RHSSO_OPENJ9registry.redhat.io/rh-sso-7/sso74-openshift-rhel8:7.4-1
RHSSO for OpenJDKRELATED_IMAGE_RHSSO_OPENJDKregistry.redhat.io/rh-sso-7/sso74-openshift-rhel8:7.4-1
Init containerRELATED_IMAGE_KEYCLOAK_INIT_CONTAINERquay.io/keycloak/keycloak-init-container:master
Backup containerRELATED_IMAGE_RHMI_BACKUP_CONTAINERquay.io/integreatly/backup-container:1.0.10
PostgresqlRELATED_IMAGE_POSTGRESQLregistry.redhat.io/rhel8/postgresql-10:1

Contributing

Before contributing to Keycloak Operator please read our contributing guidelines.

Other Keycloak Projects

License

Tag summary

Content type

Image

Digest

Size

111 MB

Last updated

almost 6 years ago

docker pull pacecar/keycloak-operator