sparse-intern-71089
01/10/2024, 1:59 PMstale-france-31173
01/10/2024, 2:00 PMminiature-library-50162
01/10/2024, 2:01 PMminiature-library-50162
01/10/2024, 2:02 PMsalmon-winter-68864
01/10/2024, 8:56 PMminiature-library-50162
01/10/2024, 9:04 PMsalmon-winter-68864
01/10/2024, 9:09 PMsalmon-winter-68864
01/10/2024, 9:10 PMsalmon-account-74572
01/10/2024, 10:32 PMThe documentation seems more or less outdatedWould it be possible to provide an example? We're constantly working to improve our docs, and I'm keen to see if there's something we've missed.
salmon-winter-68864
01/11/2024, 12:58 AMminiature-library-50162
01/11/2024, 6:19 AMminiature-library-50162
01/11/2024, 6:22 AMsalmon-account-74572
01/11/2024, 9:51 AMsalmon-winter-68864
01/16/2024, 6:23 PMsalmon-account-74572
01/16/2024, 6:46 PMfreezing-vase-18205
01/17/2024, 8:53 AMfreezing-vase-18205
01/17/2024, 8:58 AMsalmon-winter-68864
01/17/2024, 9:04 AMfreezing-vase-18205
01/17/2024, 9:11 AMwaitForResource
I have the same problem and I haven’t gotten to it just yet. Would love to see your code piece on that.freezing-vase-18205
01/17/2024, 9:12 AMany
)freezing-vase-18205
01/17/2024, 9:13 AMwaitForResource
is a common thing to have under pulumi
itselfsalmon-winter-68864
01/17/2024, 9:15 AMpackage instance
import (
"context"
"time"
"<http://github.com/pulumi/pulumi-linode/sdk/v4/go/linode|github.com/pulumi/pulumi-linode/sdk/v4/go/linode>"
"<http://github.com/pulumi/pulumi/sdk/v3/go/pulumi|github.com/pulumi/pulumi/sdk/v3/go/pulumi>"
manu "<http://gitlab.com/kylehqcom/manu/providers/linode/pulumi|gitlab.com/kylehqcom/manu/providers/linode/pulumi>"
)
// CreateInstance will create a linode resource
func CreateInstance(ctx *pulumi.Context, name string, config *manu.LinodeConfig) (*linode.Instance, error) {
if config.SSH.Key.Private == "" {
return nil, ErrMissingConfigSshPrivate
}
if config.SSH.Key.Public == "" {
return nil, ErrMissingConfigSshPublic
}
return linode.NewInstance(ctx, name, &linode.InstanceArgs{
Type: pulumi.String(config.Instance.Type),
Region: pulumi.String(config.Instance.Region),
Image: pulumi.String(config.Instance.Image),
AuthorizedKeys: pulumi.StringArray{
pulumi.String(config.SSH.Key.Public),
},
})
}
func AwaitInstanceStatus(targetStatus string, instance *linode.Instance, opts ...manu.AwaitOption) error {
awaitOptions := manu.AwaitOptions{}.New()
for _, opt := range opts {
opt(awaitOptions)
}
// Add any delay return duration to the overall deadline duration. So that
// when delaying, a false positive deadline error isn't returned
if awaitOptions.DelayReturn > time.Nanosecond {
awaitOptions.Deadline = awaitOptions.Deadline + awaitOptions.DelayReturn
}
// Pass a context with a timeout to tell a blocking function that it
// should abandon its work after the timeout elapses.
ctx, cancel := context.WithTimeout(context.Background(), awaitOptions.Deadline)
defer cancel()
done := make(chan (struct{}))
instance.Status.ApplyT(func(status string) string {
if status == targetStatus {
close(done)
}
return status
})
for {
select {
case <-done:
if awaitOptions.DelayReturn > time.Nanosecond {
time.Sleep(awaitOptions.DelayReturn)
}
return nil
case <-ctx.Done():
return ctx.Err()
}
}
}
salmon-winter-68864
01/17/2024, 9:20 AMsalmon-winter-68864
01/17/2024, 9:23 AMAwaitOptions struct {
Deadline time.Duration
DelayReturn time.Duration
}
AwaitOption func(*AwaitOptions)
freezing-vase-18205
01/17/2024, 9:23 AMsalmon-winter-68864
01/17/2024, 9:26 AMsalmon-winter-68864
01/17/2024, 9:33 AMfreezing-vase-18205
01/17/2024, 9:41 AMfreezing-vase-18205
01/17/2024, 9:45 AMtargetStatus
but then I guess it is interesting to know how you make the rest of your pulumi code to “block” until the status is reached?
since code exec is async, creation of resources happens concurrently, so I guess your AwaitInstanceStatus
func itself should return a pulumi output that would be an input to the rest of your stack code to make sure that resources dependable on Instance.targetStatus are not attempted to be created firstsalmon-winter-68864
01/17/2024, 11:09 AMsalmon-winter-68864
01/17/2024, 11:11 AMfreezing-vase-18205
01/17/2024, 1:34 PMr1 = newResource1()
awaitR1StatusRunning()
r2 = newAnotherResource(input=r1.Name)
My line of thinking is that even though awaitR1StatusRunning
is waiting till r1.Status=="Running"
it WILL NOT prevent r2
creation API to be triggered.
And this is because r2 depends on r1.Name
to be ready, but not necessarily to r1.Status to be Running. It can be r1.Status==Init
and r2 will still be attempted to be createdsalmon-account-74572
01/17/2024, 5:23 PMfreezing-vase-18205
01/17/2024, 5:55 PMup
mode where main function behaves linearly and gives the programmer full control over the execution concurrency and dependency graph
Like really standing on the promise of using a real programming language to define the infra.
If you want to create 100 containers - use a goroutine/asyncio/await - you are the programmer, you decide.
If you are a devops person, here is the original (default) flow that pulumi does with the hidden concurrency and code path managementfreezing-vase-18205
01/17/2024, 5:57 PMpulumi.Output
) that you don’t have to jump hoops through to work with.salmon-account-74572
01/17/2024, 6:11 PMpulumi/pulumi
to generate some discussion around the idea and whether folks feel like it’s something that could/should be implemented.salmon-winter-68864
01/18/2024, 12:31 AMsalmon-winter-68864
01/18/2024, 12:33 AMfreezing-vase-18205
01/18/2024, 9:31 AMr1.State==Running
Let me reiterate
1. r1 is created
2. its r1.Status after creation is r1.Status==Init
3. your await func starts to wait for r1.Status==Running
4. BUT your next resource creation step depends just on r1.Status
which is already present, it just happens to be Init
which is NOT what you want, you want it Running
but that won’t be passed to r2 creation loop
5. unless your await func returns another pulumi output and you pass this output as an input to your r2 creation logicfreezing-vase-18205
01/18/2024, 3:47 PMsalmon-winter-68864
01/19/2024, 7:28 AMsalmon-winter-68864
01/19/2024, 7:31 AMsalmon-winter-68864
01/19/2024, 7:33 AMsalmon-winter-68864
01/19/2024, 8:28 AMfreezing-vase-18205
01/19/2024, 9:37 AMsalmon-winter-68864
01/19/2024, 9:42 PM