oam-kubernetes-runtime icon indicating copy to clipboard operation
oam-kubernetes-runtime copied to clipboard

[Question]Can different workloads be selected?

Open wenxinnnnn opened this issue 5 years ago • 5 comments

In order to meet the needs of each service of our microservices to mount the sidecar of consul-client.

I tried to develop a SidecarSetWorkload for the catalog, but I needed a differentiated choice of pod to mount the sidecar. I saw a related issue: #136, Do I have any other solutions?

apiVersion: core.oam.dev/v1alpha2
kind: Component
metadata:
  name: myService-Sidecar
spec:
  workload:
    apiVersion: core.oam.dev/v1alpha2
    kind: SidecarSetWorkload
    metadata:
      name: sonsul-client-sidecar
    spec:
      selector:
        matchLabels:
          app: myService
      containers:
       - name: consul
         image: consul:1.3.1
         args:
         - "agent"
         - "-data-dir=/consul/data"
         - "-advertise=$(PODIP)"
         - "-client=0.0.0.0"
         - "-node=activity-system-$(PODIP)"
         - "-retry-join=consul-service"
         - "-domain=cluster.local"
         - "-disable-host-node-id"
         ...
    parameters:
        ...

wenxinnnnn avatar Jul 28 '20 10:07 wenxinnnnn

@wenxinnnnn a better solution is to make sidecar as a trait, you can rely on patch trait mechanism to patch this sidecar into your workload.

wonderflow avatar Jul 29 '20 08:07 wonderflow

You need to create a SidecarSet trait: https://github.com/openkruise/kruise/blob/master/docs/tutorial/sidecarset.md

resouer avatar Jul 29 '20 21:07 resouer

Another option is to create a SidecarSet trait: https://github.com/openkruise/kruise/blob/master/docs/tutorial/sidecarset.md

Openkruise's SidecarSet also uses selectors to select pods, and deploy sidecars in aspects. I found that ContainerizedWorkload does not support setting different labels.

wenxinnnnn avatar Jul 30 '20 05:07 wenxinnnnn

@wenxinnnnn a better solution is to make sidecar as a trait, you can rely on patch trait mechanism to patch this sidecar into your workload. I got it, thanks。 I didn’t see the corresponding implementation of this patch trait in this project. Did I miss it? Is there an example where this trait has been implemented?

wenxinnnnn avatar Jul 30 '20 05:07 wenxinnnnn

@wenxinnnnn The patch trait PR is WIP: https://github.com/crossplane/oam-kubernetes-runtime/pull/134

Btw, ContainerizedWorkload will propagate its labels/annotations to Pods, see: https://github.com/crossplane/oam-kubernetes-runtime/pull/166. So the only thing you need to do is directly define a SidecarSet CR as a trait and select the labels of ContainerizedWorkload.

resouer avatar Aug 11 '20 23:08 resouer