Skip to content

Commit

Permalink
integration test for ignorechanges support
Browse files Browse the repository at this point in the history
  • Loading branch information
EronWright committed Sep 16, 2023
1 parent 3ac46f7 commit 523e22a
Show file tree
Hide file tree
Showing 3 changed files with 578 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/sdk/go/go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ func TestGo(t *testing.T) {
Dir: filepath.Join("helm-release-local", "step2"),
Additive: true,
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
// expect the change in values.yaml (replicaCount: 2) to be detected
validateReplicas(t, stack, 2)
},
ExpectFailure: false,
},
{
Dir: filepath.Join("helm-release-local", "step3"),
Additive: true,
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
// note the resource option: pulumi.IgnoreChanges([]string{"checksum"})
// expect the change in values.yaml (replicaCount: 3) to be ignored
validateReplicas(t, stack, 2)
},
ExpectFailure: false,
Expand Down
57 changes: 57 additions & 0 deletions tests/sdk/go/helm-release-local/step3/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

import (
"fmt"

appsv1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/apps/v1"
corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/core/v1"
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/helm/v3"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
ns, err := corev1.NewNamespace(ctx, "test", &corev1.NamespaceArgs{})
if err != nil {
return err
}

rel, err := helm.NewRelease(ctx, "test", &helm.ReleaseArgs{
Chart: pulumi.String("nginx"),
Namespace: ns.Metadata.Name(),
Values: pulumi.Map{"service": pulumi.StringMap{"type": pulumi.String("ClusterIP")}},
Timeout: pulumi.Int(300),
}, pulumi.IgnoreChanges([]string{"checksum"}))
if err != nil {
return err
}

replicas := pulumi.All(rel.Status.Namespace(), rel.Status.Name()).
ApplyT(func(r any) (any, error) {
arr := r.([]any)
namespace := arr[0].(*string)
name := arr[1].(*string)
svc, err := appsv1.GetDeployment(ctx, "deployment", pulumi.ID(fmt.Sprintf("%s/%s-nginx", *namespace, *name)), nil)
if err != nil {
return "", nil
}
return svc.Spec.Replicas(), nil
})
ctx.Export("replicas", replicas)

svc := pulumi.All(rel.Status.Namespace(), rel.Status.Name()).
ApplyT(func(r any) (any, error) {
arr := r.([]any)
namespace := arr[0].(*string)
name := arr[1].(*string)
svc, err := corev1.GetService(ctx, "svc", pulumi.ID(fmt.Sprintf("%s/%s-nginx", *namespace, *name)), nil)
if err != nil {
return "", nil
}
return svc.Spec.ClusterIP(), nil
})
ctx.Export("svc_ip", svc)

return nil
})
}
Loading

0 comments on commit 523e22a

Please sign in to comment.