component diagram ordering

0 votes
asked Aug 23, 2021 in Question / help by Patrick Ohly
edited Aug 23, 2021

I've been a happy user of PlantUML when it comes to sequence diagrams, but whenever I try to use it for component diagrams, I end up with weird layouts that have arrows that go all over the place, often with text on top of other text.

Here's an example in the online PlantUML. In that example, arrows would be much better if the apiserver component was in the middle between controller-manager and scheduler. But that's not how PlantUML (or rather, GraphViz) arranges the boxes.

Even with hidden arrows as explained in https://crashedmind.github.io/PlantUMLHitchhikersGuide/layout/layout.html#arrows-for-layout I can't get it look nicer (updated example).

Originally, I had interfaces inside the "apiserver" component and linked those to other components. That could be laid out without overlapping arrows if the interfaces inside the "apiserver" were above each other instead side-by-side, but I don't know how to achieve that either.

I know that PlantUML isn't what I should use when I want fine control over the layout, but  this is so unusable that I must be missing something obvious. Perhaps someone can help me out? Thanks a lot in advance.

1 Answer

0 votes
answered Aug 23, 2021 by The-Lu (63,920 points)

Hello P.,

Here is a proposal, with adding `left to right direction`, and changing some arrows:

@startuml
left to right direction
skinparam componentStyle rectangle

component Kubernetes {
  component apiserver
  component scheduler {
    component "resource plugin" as k8sresourceplugin
  }
  component "controller-manager" as controllermanager {
    component "resource claim controller" as k8sresourceclaimcontroller
  }
  component kubelet
}

component 3rd-party as 3rdparty {
  component "resource controller" as vendorcontroller
  component "resource node plugin" as vendornodeplugin
}

apiserver --> k8sresourceclaimcontroller: read resource template from Pod spec
apiserver <-- k8sresourceclaimcontroller: create ResourceClaim

apiserver <--> scheduler: read/write Pod
apiserver <--> k8sresourceplugin: read/write ResourceClaim

vendorcontroller <--> apiserver 
vendornodeplugin <--> kubelet
@enduml

If that can help,
Regards,
Th.

commented Aug 23, 2021 by The-Lu (63,920 points)

Or if you prefer vertical layout, adding some `together`, and up arrow...

@startuml
skinparam componentStyle rectangle
together {
  component Kubernetes {
    component apiserver
    together {
      component scheduler {
        component "resource plugin" as k8sresourceplugin
      }
      component "controller-manager" as controllermanager {
        component "resource claim controller" as k8sresourceclaimcontroller
      }
    }
    component kubelet
  }
  component 3rd-party as 3rdparty {
    component "resource controller" as vendorcontroller
    component "resource node plugin" as vendornodeplugin
  }
}
apiserver -u-> k8sresourceclaimcontroller: read resource template    \n from Pod spec
apiserver <-u- k8sresourceclaimcontroller: create\n ResourceClaim

apiserver <--> scheduler: read/write Pod
apiserver <--> k8sresourceplugin: read/write ResourceClaim

apiserver <--> vendorcontroller
kubelet <--> vendornodeplugin
@enduml

Regards,
Th.

commented Aug 23, 2021 by Patrick Ohly

Both looks a lot better. Now I just need to figure out how to arrive at such results myself laugh

One takeaway for me is that <--> arrows do not just connect two items, but also control which one is "left" and which one is "right" (or "top" and "bottom", see next point).

"left to right direction" is still a bit mysterious to me, in particular when considering that --> is said to mean "top to bottom". Does that change to "from left to right" when the direction is changed from the default?

commented Aug 23, 2021 by The-Lu (63,920 points)

Yes, You are right.yes

See also doc. here:

...