YurtAppOverrider

Background

We already had YurtAppDaemon and YurtAppSet in the context of multi-region, but they fell short in their ability to customize configurations. To reduce coupling and for backward compatibility, we introduced YurtAppOverrider for personalized rendering, and to simplify configuration, we categorize its capabilities into basic rendering (image and replicas) and advanced rendering (arbitrary fields).

Usage

1. Deploy OpenYurt

The yurt-app-overrider controller and webhook is integrated within Yurt-Manager component. Before using, OpenYurt needs to be installed and deployed. You can refer to Deploy OpenYurt for detailed operations.

2. User Stories

  • Creating a YurtAppOverrider bound to an existing resource
  1. apiVersion: apps.openyurt.io/v1alpha1
  2. kind: YurtAppOverrider
  3. metadata:
  4. namespace: default
  5. name: demo1
  6. subject:
  7. kind: YurtAppSet
  8. name: yurtappset-demo
  9. entries:

We ignore entries field for now and focuses on subject field in the configuration above. Subject field indicates that the created YurtAppOverrider will be bound to the resource with the specified kind and name in its namespace.

  • Customized replicas and image (basic rendering)
  1. apiVersion: apps.openyurt.io/v1alpha1
  2. kind: YurtAppOverrider
  3. metadata:
  4. namespace: default
  5. name: demo1
  6. subject:
  7. kind: YurtAppSet
  8. name: yurtappset-demo
  9. entries:
  10. - pools:
  11. beijing
  12. hangzhou
  13. items:
  14. - image:
  15. containerName: nginx
  16. imageClaim: nginx:1.14.2
  17. - replicas: 3
  18. - pools:
  19. shanghai
  20. items:
  21. - image:
  22. containerName: nginx
  23. imageClaim: nginx:1.13.2
  24. - replicas: 5

With the above configuration, we can configure the replicas in the Beijing Hangzhou node pool to 3 and the image version to 1.14.2, and we can configure the replicas in the Shanghai node pool to 5 and the image version to 1.13.2.

  • Implementing hostPath changes (advanced rendering)
  1. apiVersion: apps.openyurt.io/v1alpha1
  2. kind: YurtAppOverrider
  3. metadata:
  4. namespace: default
  5. name: demo1
  6. subject:
  7. kind: YurtAppSet
  8. name: yurtappset-demo
  9. entries:
  10. - pools:
  11. hangzhou
  12. patches:
  13. - operation: add
  14. path: /spec/template/spec/volumes/-
  15. value:
  16. name: test-volume
  17. hostPath:
  18. path: /var/lib/docker
  19. type: Directory
  20. - operation: replace
  21. path: /spec/template/spec/containers/0/volumeMounts/-
  22. value:
  23. name: shared-dir
  24. mountPath: /var/lib/docker
  25. - pools:
  26. beijing
  27. patches:
  28. - operation: add
  29. path: /spec/template/spec/volumes/-
  30. value:
  31. name: test-volume
  32. hostPath:
  33. path: /data/logs
  34. type: Directory
  35. - operation: replace
  36. path: /spec/template/spec/containers/0/volumeMounts/-
  37. value:
  38. name: shared-dir
  39. mountPath: /data/logs

The above patches field allows us to personalize the hostpath for different node pools. Each patch consists of operation, path, and value, and can add, remove, and replace any of the fields, with syntax rules conforming to the syntax of json-patch.

  • Other features
  1. apiVersion: apps.openyurt.io/v1alpha1
  2. kind: YurtAppOverrider
  3. metadata:
  4. namespace: default
  5. name: demo1
  6. subject:
  7. kind: YurtAppSet
  8. name: yurtappset-demo
  9. entries:
  10. - pools:
  11. '*'
  12. '-beijing'
  13. patches:
  14. - operation: add
  15. path: /spec/template/spec/volumes/-
  16. value:
  17. name: foo
  18. configMap:
  19. name: configmap-{{nodepool}}

With the above configuration, we can add configmap corresponding to every node pool (except Beijing node pool). To simplify the configuration, we can use '*' to indicate all node pools, and we can add - in front of a node pool’s name to indicate the removal of that node pool. In addition, we can match node pools with {{nodepool}} to do bulk configuration. (Note: If we use bulk configuration, the corresponding configmap needs to follow certain naming conventions, i.e., replace {{nodepool}} with the actual node pool name).