Rank by PageRank | Package/Repo Name | Rank in github repos | Github stars | Rank by stars |
---|---|---|---|---|
254 | github.com/operator-framework/operator-sdk | 137 | 2867 | 472 |
1839 | github.com/kubernetes-sigs/kubebuilder | 1591 | 2103 | 656 |
From this comment:
Where they differ is:
- Operator SDK also has support for Ansible and Helm operators, which make it easy to write operators without having to learn Go and if you already have experience with Ansible or Helm
- Operator SDK includes integrations with the Operator Lifecycle Manager (OLM), which is a key component of the Operator Framework that is important to Day 2 cluster operations, like managing a live upgrade of your operator.
- Operator SDK includes a scorecard subcommand that helps you understand if your operator follows best practices.
- Operator SDK includes an e2e testing framework that simplifies testing your operator against an actual cluster.
- Kubebuilder includes an envtest package that allows operator developers to run simple tests with a standalone etcd and apiserver.
- Kubebuilder scaffolds a Makefile to assist users in operator tasks (build, test, run, code generation, etc.); Operator SDK is currently using built-in subcommands. Each has pros and cons. The SDK team will likely be migrating to a Makefile-based approach in the future.
- Kubebuilder uses Kustomize to build deployment manifests; Operator SDK uses static files with placeholders.
- Kubebuilder has recently improved its support for admission and CRD conversion webhooks, which has not yet made it into SDK.
The SDK and Kubebuilder teams work closely together, and we're planning to increase our efforts to help the kubebuilder team maintain controller-tools and controller-runtime so that the entire community has access to the latest features and bug fixes.
Here are the steps that one needs to follow towards generating your own CRD/Operator code.
For generating the client/listers/informers, etc. the first step is to create specific directory structure and define specific files in it. Here is that structure and the required files:
- pkg/apis/some-controller-name/register.go
- pkg/apis/some-controller-name/v1/doc.go
- pkg/apis/some-controller-name/v1/types.go
- pkg/client
- pkg/signals
Following are detailed steps:
- Choose a name for your CRD's group name -- say 'postgrescontroller'
- Create pkg/apis/'CRD group name' directory
- cd pkg/apis/'CRD group name'
- Inside this directory create register.go to register the group name. When registering the name, choose some qualifier (example, in https://github.com/cloud-ark/kubeplus/blob/master/postgres-crd-v2/pkg/apis/postgrescontroller/register.go we have used "kubeplus" as the qualifier name.).
- Create v1 directory inside pkg/apis/'CRD group name'
- cd pkg/apis/'CRD group name'/v1
- Create doc.go. Make sure you set the "+groupName=." in line 20 of doc.go. Leave line 21 as it is. See https://github.com/cloud-ark/kubeplus/blob/master/postgres-crd-v2/pkg/apis/postgrescontroller/v1/doc.go
- Copy https://github.com/cloud-ark/kubeplus/tree/master/operator manager/pkg/apis/operatorcontroller/v1/register.go into pkg/apis//v1/. Make appropriate changes to this file.
- Define your CRD spec in types.go
- Nothing else needs to be created in the pkg/apis directory
- Create pkg/client directory. Nothing needs to be created inside the client directory -- leave it empty.
- Create pkg/signals directory and just copy all the files from https://github.com/cloud-ark/kubeplus/tree/master/postgres-crd-v2/pkg/signals into pkg/signals. You don't need to modify anything in any of these files.
- Go inside the hack/ directory.
- Edit update-codegen.sh to include the path of your folder
- Copy Gopkg.lock and Gopkg.toml from https://github.com/cloud-ark/kubeplus/tree/master/operator-manager
- Install Go dependencies dep ensure (this will create the vendor folder)
- mkdir vendor/k8s.io/code-generator/hack
- cp hack/boilerplate.go.txt vendor/k8s.io/code-generator/hack/.
- From the main directory of your CRD code execute following: ./hack/update-codegen.sh
- In the controller.go (and other go files), include the CRD client/listers/informers etc. with appropriate path. See https://github.com/cloud-ark/kubeplus/blob/master/postgres-crd-v2/controller.go#L47 for an example.
- go run *.go -kubeconfig=$HOME/.kube/config