Skip to content

Commit

Permalink
add an e2e test for immutability
Browse files Browse the repository at this point in the history
  • Loading branch information
blampe committed Aug 21, 2024
1 parent b99c9fc commit 3ecf7a5
Show file tree
Hide file tree
Showing 4 changed files with 449 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/sdk/java/configmap_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package test

import (
"testing"

"github.com/pulumi/providertest/pulumitest"
"github.com/pulumi/providertest/pulumitest/opttest"
"github.com/stretchr/testify/assert"
)

func TestConfigMapAndSecretImmutability(t *testing.T) {
t.Parallel()

test := pulumitest.NewPulumiTest(t,
"testdata/immutability",
opttest.SkipInstall(),
)
t.Cleanup(func() {
test.Destroy()
})

// Create the secrets/configmaps.
up := test.Up()

// We will detect update/replacement behavior by observing effects on our
// downstream dependencies.
secret := up.Outputs["secret"].Value.(string)
configmap := up.Outputs["configmap"].Value.(string)
autonamedSecret := up.Outputs["autonamedSecret"].Value.(string)
autonamedConfigmap := up.Outputs["autonamedConfigmap"].Value.(string)
mutableSecret := up.Outputs["mutableSecret"].Value.(string)
mutableConfigmap := up.Outputs["mutableConfigmap"].Value.(string)

// Update the data of all our secrets and configmaps.
test.UpdateSource("testdata/immutability/step2")
up = test.Up()

// Only the mutable configmap and secret should have been updated -- so no
// impact on those two downstreams.
assert.Equal(t, mutableConfigmap, up.Outputs["mutableConfigmap"].Value.(string))
assert.Equal(t, mutableSecret, up.Outputs["mutableSecret"].Value.(string))
// All others should have been replaced, which should have regenerated our
// random pets.
assert.NotEqual(t, secret, up.Outputs["secret"].Value.(string))
assert.NotEqual(t, configmap, up.Outputs["configmap"].Value.(string))
assert.NotEqual(t, autonamedSecret, up.Outputs["autonamedSecret"].Value.(string))
assert.NotEqual(t, autonamedConfigmap, up.Outputs["autonamedConfigmap"].Value.(string))
// Record the new outputs.
secret = up.Outputs["secret"].Value.(string)
configmap = up.Outputs["configmap"].Value.(string)
autonamedSecret = up.Outputs["autonamedSecret"].Value.(string)
autonamedConfigmap = up.Outputs["autonamedConfigmap"].Value.(string)

// The final step only touches annotations. All resources should have been
// updated.
test.UpdateSource("testdata/immutability/step3")
up = test.Up()
assert.Equal(t, secret, up.Outputs["secret"].Value.(string))
assert.Equal(t, configmap, up.Outputs["configmap"].Value.(string))
assert.Equal(t, autonamedSecret, up.Outputs["autonamedSecret"].Value.(string))
assert.Equal(t, autonamedConfigmap, up.Outputs["autonamedConfigmap"].Value.(string))
assert.Equal(t, mutableConfigmap, up.Outputs["mutableConfigmap"].Value.(string))
assert.Equal(t, mutableSecret, up.Outputs["mutableSecret"].Value.(string))
}
119 changes: 119 additions & 0 deletions tests/sdk/java/testdata/immutability/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: immutability
runtime: yaml
description: |
Test mutability and immutability for Secrets and ConfigMaps, as well as
replacement interactions with downstream dependencies.
resources:
ns:
type: kubernetes:core/v1:Namespace

provider:
type: pulumi:providers:kubernetes
properties:
enableSecretMutable: true
enableConfigMapMutable: true
namespace: ${ns.metadata.name}

secret:
type: kubernetes:core/v1:Secret
options:
provider: ${provider}
properties:
metadata:
name: secret
immutable: true
stringData:
foo: "foo"

configmap:
type: kubernetes:core/v1:ConfigMap
options:
provider: ${provider}
properties:
metadata:
name: configmap
immutable: true
data:
foo: "foo"

autonamed-secret:
type: kubernetes:core/v1:Secret
options:
provider: ${provider}
properties:
immutable: true
stringData:
foo: "foo"

autonamed-configmap:
type: kubernetes:core/v1:ConfigMap
options:
provider: ${provider}
properties:
immutable: true
data:
foo: "foo"

mutable-secret:
type: kubernetes:core/v1:Secret
options:
provider: ${provider}
properties:
stringData:
foo: "foo"

mutable-configmap:
type: kubernetes:core/v1:ConfigMap
options:
provider: ${provider}
properties:
data:
foo: "foo"

# Downstreams should not be impacted by updates but should be updated when
# upstreams are replaced.

secret-downstream:
type: random:RandomPet
properties:
keepers:
upstream: ${secret.metadata.name}

configmap-downstream:
type: random:RandomPet
properties:
keepers:
upstream: ${configmap.metadata.name}

autonamed-secret-downstream:
type: random:RandomPet
properties:
keepers:
upstream: ${autonamed-secret.metadata.name}

autonamed-configmap-downstream:
type: random:RandomPet
properties:
keepers:
upstream: ${autonamed-configmap.metadata.name}

mutable-secret-downstream:
type: random:RandomPet
properties:
keepers:
upstream: ${mutable-secret.metadata.name}

mutable-configmap-downstream:
type: random:RandomPet
properties:
keepers:
upstream: ${mutable-configmap.metadata.name}

outputs:
secret: ${secret-downstream.id}
configmap: ${configmap-downstream.id}
autonamedSecret: ${autonamed-secret-downstream.id}
autonamedConfigmap: ${autonamed-configmap-downstream.id}
mutableSecret: ${mutable-secret-downstream.id}
mutableConfigmap: ${mutable-configmap-downstream.id}
125 changes: 125 additions & 0 deletions tests/sdk/java/testdata/immutability/step2/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: immutability
runtime: yaml
description: |
Test mutability and immutability for Secrets and ConfigMaps, as well as
replacement interactions with downstream dependencies.
resources:
ns:
type: kubernetes:core/v1:Namespace

provider:
type: pulumi:providers:kubernetes
properties:
enableSecretMutable: true
enableConfigMapMutable: true
namespace: ${ns.metadata.name}

secret:
type: kubernetes:core/v1:Secret
options:
provider: ${provider}
properties:
metadata:
name: secret
immutable: true
stringData:
# foo -> bar
bar: "bar"

configmap:
type: kubernetes:core/v1:ConfigMap
options:
provider: ${provider}
properties:
metadata:
name: configmap
immutable: true
data:
# foo -> bar
bar: "bar"

autonamed-secret:
type: kubernetes:core/v1:Secret
options:
provider: ${provider}
properties:
immutable: true
stringData:
# foo -> bar
bar: "bar"

autonamed-configmap:
type: kubernetes:core/v1:ConfigMap
options:
provider: ${provider}
properties:
immutable: true
data:
# foo -> bar
bar: "bar"

mutable-secret:
type: kubernetes:core/v1:Secret
options:
provider: ${provider}
properties:
stringData:
# foo -> bar
bar: "bar"

mutable-configmap:
type: kubernetes:core/v1:ConfigMap
options:
provider: ${provider}
properties:
data:
# foo -> bar
bar: "bar"

# Downstreams should not be impacted by updates but should be updated when
# upstreams are replaced.

secret-downstream:
type: random:RandomPet
properties:
keepers:
upstream: ${secret.metadata.name}

configmap-downstream:
type: random:RandomPet
properties:
keepers:
upstream: ${configmap.metadata.name}

autonamed-secret-downstream:
type: random:RandomPet
properties:
keepers:
upstream: ${autonamed-secret.metadata.name}

autonamed-configmap-downstream:
type: random:RandomPet
properties:
keepers:
upstream: ${autonamed-configmap.metadata.name}

mutable-secret-downstream:
type: random:RandomPet
properties:
keepers:
upstream: ${mutable-secret.metadata.name}

mutable-configmap-downstream:
type: random:RandomPet
properties:
keepers:
upstream: ${mutable-configmap.metadata.name}

outputs:
secret: ${secret-downstream.id}
configmap: ${configmap-downstream.id}
autonamedSecret: ${autonamed-secret-downstream.id}
autonamedConfigmap: ${autonamed-configmap-downstream.id}
mutableSecret: ${mutable-secret-downstream.id}
mutableConfigmap: ${mutable-configmap-downstream.id}
Loading

0 comments on commit 3ecf7a5

Please sign in to comment.