#Service start from SDK overrides running service up in the CLI

1 messages · Page 1 of 1 (latest)

prime blaze
#

I am using k3s module and I am able to spawn a k3s service from the CLI with:

dagger -m github.com/marcosnils/daggerverse/k3s@833ec36632b2457862f6e3bf1f7107ad65e3e515 call --name my-cluster server up

However, in my dagger module I also run something like:

await dag.k3_s(name="my-cluster").server().start

I must start the service, otherwise when I don't start the service from CLI I cannot deploy anything to the cluster. On the other hand, this line of code re-starts the server that I previously launched from the CLI as shown above. Notice that k3s is able to connect to the same service instance from multiple locations in the same session, since each service is uniquely identified only be the name, therefore I was expecting that the call to service.sytart() would have been ignored considering that there was already the same service with the same name running from the CLI. Am I missing something?

Is there a way in Python SDK to check if a service is already running and attach to it?

old folio
#

Hi @prime blaze ! It sounds like you want to pass the running service as a parameter to your module

So if you've run the k3s module in one terminal

Your module accepts a dagger.Service as an argument (instead of calling k3_s.server().start())

And you'd call it like dagger call my-function --k3s tcp://localhost:6443

prime blaze
#

interesting! So I could default the service argument to None/nil, and when it is not None/nil, I can reuse the existing one, otherwise I can spawn it. Does this make sense?

old folio
#

Yes exactly! I use that same method for databases too. Like if I'm working on something where I want the database persisted for a while, I'll pass in the port on my localhost, and if it's not passed in the module will create it's own