Skip to content

Latest commit

 

History

History
164 lines (127 loc) · 4.99 KB

CHANGELOG.md

File metadata and controls

164 lines (127 loc) · 4.99 KB

ChangeLog

3.0 CR status conditions

2.0 Admission webhook

tag: v0.0.4

make validating admission webhook have real meaning.

  1. 修改api/v1alpha1/memcached_webhook.go
  2. uncomment WEBHOOK/CERTMANAGER yaml (config/crd/kustomization.yaml, config/default/kustomization.yaml)
  3. install cert-manager in current cluster
  4. 参照 1.1 中的第5,6操作,重新编译镜像,再次部署更新memcached-operator的版本

tag: v0.0.3

# Create Validation Webhook
operator-sdk create webhook --group cache --version v1alpha1 --kind Memcached --defaulting --programmatic-validation

# Generate webhook manifests and enable webhook deployment
make manifests

reference

  1. Admission Webhooks

1.1 frist real world

tag: v0.0.2

make memcached deployment running

  1. 修改api/v1alpha1/memcached_types.go

    • MemcachedSpecFoot 无意义字段调整为有实际意义的Size字段
    • MemcachedStatus 添加Nodes字段用于记录the names of the memcached pods
    • 还有一些 CRD validation markers(rbac等相关的)
  2. 因为我们修改了memcached_types.go,所以我们需要运行如下命令更新为资源类型生成的代码:

    make generate
  3. Generating CRD manifests (Once the API is defined with spec/status fields and CRD validation markers),需要运行如下命令生成和更新CRD Manifests:

    make manifests
  4. 添加基础的Reconcile逻辑 (controllers/memcached_controller.go)

    • 检查cr资源
    • 创建deployment
    • 更新Memcached status.Nodes信息
  5. 通过如下命令生成docker image(通过IMG参数自定义image的地址)

    make docker-build IMG=colynn/memcached-operator:latest
  6. 修改memcached-operator manager的镜像版本信息并部署

    # config/manager/kustomization.yaml
    make deploy
  7. 定义Mecahced CR资源,修改samples/cache_v1alpha1_memcached.yaml

    • 添加size定义
    kubectl apply -f config/samples/cache_v1alpha1_memcached.yaml

Finally, 你将会在对应的kubernetes环境中看到如下的运行状态:

# memcached-operator manager
$ kubectl -n memcached-operator-system get pods
NAME                                                     READY   STATUS    RESTARTS   AGE
memcached-operator-controller-manager-79c444fb96-mbfgd   2/2     Running   0          38m

# memcached cr
$ kubectl get pods
NAME                                READY   STATUS    RESTARTS   AGE
memcached-sample-6ccc5bb5db-2sfss   1/1     Running   0          60m
memcached-sample-6ccc5bb5db-6x5kv   1/1     Running   0          60m
memcached-sample-6ccc5bb5db-p9tjw   1/1     Running   0          60m
# $ kubectl get memcacheds.cache.colynn.com memcached-sample -o yaml
apiVersion: cache.colynn.com/v1alpha1
kind: Memcached
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"cache.colynn.com/v1alpha1","kind":"Memcached","metadata":{"annotations":{},"name":"memcached-sample","namespace":"default"},"spec":{"size":3}}
  creationTimestamp: "2022-10-20T07:51:55Z"
  generation: 1
  managedFields:
  - apiVersion: cache.colynn.com/v1alpha1
    fieldsType: FieldsV1
    fieldsV1:
      f:metadata:
        f:annotations:
          .: {}
          f:kubectl.kubernetes.io/last-applied-configuration: {}
      f:spec:
        .: {}
        f:size: {}
    manager: kubectl
    operation: Update
    time: "2022-10-20T07:51:55Z"
  - apiVersion: cache.colynn.com/v1alpha1
    fieldsType: FieldsV1
    fieldsV1:
      f:status:
        .: {}
        f:nodes: {}
    manager: manager
    operation: Update
    time: "2022-10-20T08:12:28Z"
  name: memcached-sample
  namespace: default
  resourceVersion: "98873361"
  selfLink: /apis/cache.colynn.com/v1alpha1/namespaces/default/memcacheds/memcached-sample
  uid: d724d918-c067-4096-a3f8-ef8d6abea11e
spec:
  size: 3
status:
  nodes:
  - memcached-sample-6ccc5bb5db-p9tjw
  - memcached-sample-6ccc5bb5db-6x5kv
  - memcached-sample-6ccc5bb5db-2sfss

Cleanup, 如果你想清理所有部署的资源,请运行如下命令:

kubectl delete -f config/samples/cache_v1alpha1_memcached.yaml
make undeploy

1.0 init commit

tag: v0.0.1

# iniitialize the project
operator-sdk init --domain colynn.com --repo github.com/colynn/memcached-operator

# create a simaple Memcached API
operator-sdk create api --group cache --version v1alpha1 --kind Memcached --resource --controller

# Next: implement your new API and generate the manifests (e.g. CRDs,CRs config/crd/bases/  config/rbac/role.yaml) with:
make manifests