Skip to content

Commit

Permalink
Unit tests for Await logic (Creation) (#2797)
Browse files Browse the repository at this point in the history
<!--Thanks for your contribution. See [CONTRIBUTING](CONTRIBUTING.md)
    for Pulumi's contribution guidelines.

    Help us merge your changes more quickly by adding more details such
    as labels, milestones, and reviewers.-->

### Proposed changes

<!--Give us a brief description of what you've done and what it solves.
-->

This PR implements unit tests for the await logic, i.e. the flow of
hitting the API server (with retry), then invoking the registered
awaiter to poll for success, then refreshing the live object.

### Related issues (optional)

<!--Refer to related PRs or issues: #1234, or 'Fixes #1234' or 'Closes
#1234'.
Or link to full URLs to issues or pull requests in other GitHub
repositories. -->

Closes #2791
  • Loading branch information
EronWright authored Feb 1, 2024
1 parent 6f1e306 commit 4a5bfcc
Show file tree
Hide file tree
Showing 18 changed files with 76,743 additions and 132 deletions.
3 changes: 3 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ coverage:
patch:
default:
informational: true

ignore:
- "**/fake"
37 changes: 26 additions & 11 deletions provider/pkg/await/await.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import (
fluxssa "github.com/fluxcd/pkg/ssa"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/clients"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/cluster"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/host"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/kinds"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/logging"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/metadata"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/openapi"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/retry"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/ssa"
pulumiprovider "github.com/pulumi/pulumi/pkg/v3/resource/provider"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
logger "github.com/pulumi/pulumi/sdk/v3/go/common/util/logging"
Expand Down Expand Up @@ -62,7 +62,7 @@ import (

type ProviderConfig struct {
Context context.Context
Host *pulumiprovider.HostClient
Host host.HostClient
URN resource.URN
InitialAPIVersion string
FieldManager string
Expand All @@ -72,6 +72,9 @@ type ProviderConfig struct {
ClientSet *clients.DynamicClientSet
DedupLogger *logging.DedupLogger
Resources k8sopenapi.Resources

// explicit awaiters (for testing purposes)
awaiters map[string]awaitSpec
}

type CreateConfig struct {
Expand Down Expand Up @@ -249,13 +252,16 @@ func Creation(c CreateConfig) (*unstructured.Unstructured, error) {
// only if we don't have an entry for the resource type; in the event that we do, but the await
// logic is blank, simply do nothing instead of logging.
id := fmt.Sprintf("%s/%s", c.Inputs.GetAPIVersion(), c.Inputs.GetKind())
if awaiter, exists := awaiters[id]; exists {
a := awaiters
if c.awaiters != nil {
a = c.awaiters
}
if awaiter, exists := a[id]; exists {
if metadata.SkipAwaitLogic(c.Inputs) {
logger.V(1).Infof("Skipping await logic for %v", c.Inputs.GetName())
} else {
if awaiter.awaitCreation != nil {
conf := createAwaitConfig{
host: c.Host,
ctx: c.Context,
urn: c.URN,
initialAPIVersion: c.InitialAPIVersion,
Expand Down Expand Up @@ -304,13 +310,16 @@ func Read(c ReadConfig) (*unstructured.Unstructured, error) {
}

id := fmt.Sprintf("%s/%s", outputs.GetAPIVersion(), outputs.GetKind())
if awaiter, exists := awaiters[id]; exists {
a := awaiters
if c.awaiters != nil {
a = c.awaiters
}
if awaiter, exists := a[id]; exists {
if metadata.SkipAwaitLogic(c.Inputs) {
logger.V(1).Infof("Skipping await logic for %v", c.Inputs.GetName())
} else {
if awaiter.awaitRead != nil {
conf := createAwaitConfig{
host: c.Host,
ctx: c.Context,
urn: c.URN,
initialAPIVersion: c.InitialAPIVersion,
Expand Down Expand Up @@ -378,14 +387,17 @@ func Update(c UpdateConfig) (*unstructured.Unstructured, error) {
// if we don't have an entry for the resource type; in the event that we do, but the await logic
// is blank, simply do nothing instead of logging.
id := fmt.Sprintf("%s/%s", c.Inputs.GetAPIVersion(), c.Inputs.GetKind())
if awaiter, exists := awaiters[id]; exists {
a := awaiters
if c.awaiters != nil {
a = c.awaiters
}
if awaiter, exists := a[id]; exists {
if metadata.SkipAwaitLogic(c.Inputs) {
logger.V(1).Infof("Skipping await logic for %v", c.Inputs.GetName())
} else {
if awaiter.awaitUpdate != nil {
conf := updateAwaitConfig{
createAwaitConfig: createAwaitConfig{
host: c.Host,
ctx: c.Context,
urn: c.URN,
initialAPIVersion: c.InitialAPIVersion,
Expand Down Expand Up @@ -740,13 +752,16 @@ func Deletion(c DeleteConfig) error {
// is blank, simply do nothing instead of logging.
var waitErr error
id := fmt.Sprintf("%s/%s", c.Inputs.GetAPIVersion(), c.Inputs.GetKind())
if awaiter, exists := awaiters[id]; exists && awaiter.awaitDeletion != nil {
a := awaiters
if c.awaiters != nil {
a = c.awaiters
}
if awaiter, exists := a[id]; exists && awaiter.awaitDeletion != nil {
if metadata.SkipAwaitLogic(c.Inputs) {
logger.V(1).Infof("Skipping await logic for %v", c.Inputs.GetName())
} else {
waitErr = awaiter.awaitDeletion(deleteAwaitConfig{
createAwaitConfig: createAwaitConfig{
host: c.Host,
ctx: c.Context,
urn: c.URN,
initialAPIVersion: c.InitialAPIVersion,
Expand Down Expand Up @@ -835,7 +850,7 @@ func checkIfResourceDeleted(
}

// clearStatus will clear the `Info` column of the CLI of all statuses and messages.
func clearStatus(context context.Context, host *pulumiprovider.HostClient, urn resource.URN) error {
func clearStatus(context context.Context, host host.HostClient, urn resource.URN) error {
return host.LogStatus(context, diag.Info, urn, "")
}

Expand Down
Loading

0 comments on commit 4a5bfcc

Please sign in to comment.