Skip to content

Commit

Permalink
[sdk/dotnet] Add ready attribute to await Helm charts
Browse files Browse the repository at this point in the history
  • Loading branch information
lblackstone committed Nov 1, 2021
1 parent 8cb09e3 commit 9b3b8da
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- [sdk/python] Add ready attribute to await Helm charts (https://github.com/pulumi/pulumi-kubernetes/pull/1782)
- [sdk/go] Add ready attribute to await Helm charts (https://github.com/pulumi/pulumi-kubernetes/pull/1784)
- [sdk/dotnet] Add ready attribute to await Helm charts (https://github.com/pulumi/pulumi-kubernetes/pull/1785)

## 3.8.3 (October 29, 2021)

Expand Down
10 changes: 9 additions & 1 deletion provider/pkg/gen/dotnet-templates/yaml/yaml.tmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016-2020, Pulumi Corporation.
// Copyright 2016-2021, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -73,6 +73,14 @@ namespace Pulumi.Kubernetes.Yaml
});
}

/// <summary>
/// Returns an array of ready resources to be used by DependsOn.
/// </summary>
public Output<ImmutableArray<Resource>> Ready()
{
return Resources.Apply(resources => resources.Values.Cast<Resource>().ToImmutableArray());
}

/// <summary>
/// Returns a custom resource defined by the given group/version/kind and name.
/// </summary>
Expand Down
10 changes: 9 additions & 1 deletion sdk/dotnet/Yaml/Yaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016-2020, Pulumi Corporation.
// Copyright 2016-2021, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -283,6 +283,14 @@ public Output<T> GetResource<T>(string name, string? namespaceName = null)
});
}

/// <summary>
/// Returns an array of ready resources to be used by DependsOn.
/// </summary>
public Output<ImmutableArray<Resource>> Ready()
{
return Resources.Apply(resources => resources.Values.Cast<Resource>().ToImmutableArray());
}

/// <summary>
/// Returns a custom resource defined by the given group/version/kind and name.
/// </summary>
Expand Down
33 changes: 31 additions & 2 deletions tests/sdk/dotnet/dotnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ package test
import (
b64 "encoding/base64"
"encoding/json"
"github.com/pulumi/pulumi-kubernetes/provider/v3/pkg/openapi"
"fmt"
"path/filepath"
"regexp"
"strings"
"testing"

"github.com/pulumi/pulumi-kubernetes/provider/v3/pkg/openapi"
"github.com/pulumi/pulumi/pkg/v3/testing/integration"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
Expand Down Expand Up @@ -115,7 +117,34 @@ func TestDotnet_HelmLocal(t *testing.T) {
Quick: true,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
assert.NotNil(t, stackInfo.Deployment)
assert.Equal(t, 11, len(stackInfo.Deployment.Resources))
assert.Equal(t, 12, len(stackInfo.Deployment.Resources))

// Verify resource creation order using the Event stream. The Chart resources must be created
// first, followed by the dependent ConfigMap. (The ConfigMap doesn't actually need the Chart, but
// it creates almost instantly, so it's a good choice to test creation ordering)
cmRegex := regexp.MustCompile(`ConfigMap::test-.*/nginx-server-block`)
svcRegex := regexp.MustCompile(`Service::test-.*/nginx`)
deployRegex := regexp.MustCompile(`Deployment::test-.*/nginx`)
dependentRegex := regexp.MustCompile(`ConfigMap::foo`)

var configmapFound, serviceFound, deploymentFound, dependentFound bool
for _, e := range stackInfo.Events {
if e.ResOutputsEvent != nil {
switch {
case cmRegex.MatchString(e.ResOutputsEvent.Metadata.URN):
configmapFound = true
case svcRegex.MatchString(e.ResOutputsEvent.Metadata.URN):
serviceFound = true
case deployRegex.MatchString(e.ResOutputsEvent.Metadata.URN):
deploymentFound = true
case dependentRegex.MatchString(e.ResOutputsEvent.Metadata.URN):
dependentFound = true
}
assert.Falsef(t, dependentFound && !(configmapFound && serviceFound && deploymentFound),
"dependent ConfigMap created before all chart resources were ready")
fmt.Println(e.ResOutputsEvent.Metadata.URN)
}
}
},
EditDirs: []integration.EditDir{
{
Expand Down
12 changes: 11 additions & 1 deletion tests/sdk/dotnet/helm-local/step1/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016-2020, Pulumi Corporation. All rights reserved.
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.

using System.Collections.Generic;
using System.Collections.Immutable;
Expand All @@ -16,6 +16,16 @@ public HelmStack()
var namespaceName = namespaceTest.Metadata.Apply(n => n.Name);

var nginx = CreateChart(namespaceName);
new ConfigMap("foo", new Pulumi.Kubernetes.Types.Inputs.Core.V1.ConfigMapArgs
{
Data = new InputMap<string>
{
{"foo", "bar"}
},
}, new CustomResourceOptions
{
DependsOn = nginx.Ready(),
});

// Deploy a duplicate chart with a different resource prefix to verify that multiple instances of the Chart
// can be managed in the same stack.
Expand Down
12 changes: 11 additions & 1 deletion tests/sdk/dotnet/helm-local/step2/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016-2020, Pulumi Corporation. All rights reserved.
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.

using System.Collections.Generic;
using System.Collections.Immutable;
Expand All @@ -16,6 +16,16 @@ public HelmStack()
var namespaceName = namespaceTest.Metadata.Apply(n => n.Name);

var nginx = CreateChart(namespaceName);
new ConfigMap("foo", new Pulumi.Kubernetes.Types.Inputs.Core.V1.ConfigMapArgs
{
Data = new InputMap<string>
{
{"foo", "bar"}
},
}, new CustomResourceOptions
{
DependsOn = nginx.Ready(),
});

// Deploy a duplicate chart with a different resource prefix to verify that multiple instances of the Chart
// can be managed in the same stack.
Expand Down

0 comments on commit 9b3b8da

Please sign in to comment.