Skip to content
Jayapriya Pai edited this page Jun 30, 2021 · 2 revisions

Steps followed in creating this project

Initialize project

kubebuilder init --domain  slashpai.github.io --repo github.com/kube-go/drink-operator

Create api

kubebuilder create api --group hotdrink --version v1alpha1 --kind Tea

Install the CRDs into the cluster:

make install

Run your controller in foreground

make run

Install instances of custom resources

If you pressed y for Create Resource [y/n] then you created an (CR)Custom Resource for your (CRD)Custom Resource Definition in your samples (make sure to edit them first if you’ve changed the API definition)

kubectl apply -f config/samples/
░▒▓    ~/.kube  k get tea                                                                                                     ✔  3.9.5   1.16.4   2.7.3   at kind-pai/crd ⎈  at 00:11:35  ▓▒░
NAME         AGE
tea-sample   2m58s

░▒▓    ~/.kube 
░▒▓    ~/.kube  k describe tea                                                                                            INT ✘  3.9.5   1.16.4   2.7.3   at kind-pai/crd ⎈  at 00:16:21  ▓▒░
Name:         tea-sample
Namespace:    crd
Labels:       <none>
Annotations:  <none>
API Version:  hotdrink.slashpai.github.io/v1alpha1
Kind:         Tea
Metadata:
  Creation Timestamp:  2021-06-29T18:42:30Z
  Generation:          1
  Managed Fields:
    API Version:  hotdrink.slashpai.github.io/v1alpha1
    Fields Type:  FieldsV1
    fieldsV1:
      f:metadata:
        f:annotations:
          .:
          f:kubectl.kubernetes.io/last-applied-configuration:
      f:spec:
        .:
        f:foo:
    Manager:         kubectl-client-side-apply
    Operation:       Update
    Time:            2021-06-29T18:42:30Z
  Resource Version:  46110
  UID:               cffde696-047d-416e-aefe-a0f89720b2f6
Spec:
  Foo:   bar
Events:  <none>

░▒▓    ~/.kube 

Update spec

// TeaSpec defines the desired state of Tea
type TeaSpec struct {
	// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
	// Important: Run "make" to regenerate code after modifying this file

	// Foo is an example field of Tea. Edit tea_types.go to remove/update
	// Foo string `json:"foo,omitempty"`

	// Tea type
	Type string `json:"type,omitempty"`

	// Sugar needed?
	Sugar bool `json:"sugar,omitempty"`
}
░▒▓    ~/gi/k/drink-operator  on   main ⇡5 !1  make install                                                                          1 ✘  3.9.5   1.16.4   2.7.3   at kind-pai/crd ⎈  at 00:28:41  ▓▒░
/Users/jayapriyapai/github.com/kube-go/drink-operator/bin/controller-gen "crd:trivialVersions=true,preserveUnknownFields=false" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
/Users/jayapriyapai/github.com/kube-go/drink-operator/bin/kustomize build config/crd | kubectl apply -f -
customresourcedefinition.apiextensions.k8s.io/teas.hotdrink.slashpai.github.io created

░▒▓    ~/gi/k/drink-operator  on   main ⇡5 !1  k get tea                                                                               ✔  3.9.5   1.16.4   2.7.3   at kind-pai/crd ⎈  at 00:28:50  ▓▒░
No resources found in crd namespace.

░▒▓    ~/gi/k/drink-operator  on   main ⇡5 !1  kubectl apply -f config/samples/                                                        ✔  3.9.5   1.16.4   2.7.3   at kind-pai/crd ⎈  at 00:42:43  ▓▒░
tea.hotdrink.slashpai.github.io/black-tea created
tea.hotdrink.slashpai.github.io/milk-tea created

░▒▓    ~/gi/k/drink-operator  on   main ⇡5 !1  k get tea                                                                               ✔  3.9.5   1.16.4   2.7.3   at kind-pai/crd ⎈  at 00:43:00  ▓▒░
NAME        AGE
black-tea   2s
milk-tea    2s

░▒▓    ~/gi/k/drink-operator  on   main ⇡5 !1       

Add another api, update spec, install crd, create resource

░▒▓    ~/gi/k/drink-operator  on   main ⇡2  make install                                                                               ✔  3.9.5   1.16.4   2.7.3   at kind-pai/crd ⎈  at 07:59:49  ▓▒░
/Users/jayapriyapai/github.com/kube-go/drink-operator/bin/controller-gen "crd:trivialVersions=true,preserveUnknownFields=false" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
/Users/jayapriyapai/github.com/kube-go/drink-operator/bin/kustomize build config/crd | kubectl apply -f -
customresourcedefinition.apiextensions.k8s.io/coffees.hotdrink.slashpai.github.io created
customresourcedefinition.apiextensions.k8s.io/teas.hotdrink.slashpai.github.io configured

░▒▓    ~/gi/k/drink-operator  on   main ⇡2 !1 ?1  git diff                                                                             ✔  3.9.5   1.16.4   2.7.3   at kind-pai/crd ⎈  at 07:59:57  ▓▒░

░▒▓    ~/gi/k/drink-operator  on   main ⇡2 !1 ?1  git push origin main                                                    ✔  took 43s   3.9.5   1.16.4   2.7.3   at kind-pai/crd ⎈  at 08:00:43  ▓▒░

░▒▓    ~/gi/k/drink-operator  on   main ⇡2 !2 ?1  kubectl apply -f config/samples/hotdrink_v1alpha1_coffee.yaml                    INT ✘  3.9.5   1.16.4   2.7.3   at kind-pai/crd ⎈  at 08:07:41  ▓▒░
coffee.hotdrink.slashpai.github.io/mocha created
coffee.hotdrink.slashpai.github.io/espresso created
coffee.hotdrink.slashpai.github.io/cappucino created

░▒▓    ~/gi/k/drink-operator  on   main ⇡2 !2 ?1  k get coffee                                                                         ✔  3.9.5   1.16.4   2.7.3   at kind-pai/crd ⎈  at 08:07:50  ▓▒░
NAME        AGE
cappucino   7s
espresso    7s
mocha       7s

░▒▓    ~/gi/k/drink-operator  on   main ⇡2 !2 ?1 