Skip to content

Commit

Permalink
Add useLocalStackOnly option to prevent stack creation (#186)
Browse files Browse the repository at this point in the history
Also bump pulumi/pulumi to 3.10.3

Fix #185
  • Loading branch information
elsesiy authored Aug 30, 2021
1 parent 28c3f3f commit 8e59f92
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ CHANGELOG
=========

## HEAD (Unreleased)
- Fix pip cache directory to be on emptyDir mount [#181[(https://github.com/pulumi/pulumi-kubernetes-operator/pull/181)
- Fix pip cache directory to be on emptyDir mount [#181](https://github.com/pulumi/pulumi-kubernetes-operator/pull/181)
- Add `useLocalStackOnly` option to prevent stack creation by the operator [#186](https://github.com/pulumi/pulumi-kubernetes-operator/pull/186)

## 0.0.17 (2021-08-18)

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM pulumi/pulumi:v3.10.2
FROM pulumi/pulumi:v3.10.3

ENV OPERATOR=/usr/local/bin/pulumi-kubernetes-operator

Expand Down
3 changes: 3 additions & 0 deletions deploy/crds/pulumi.com_stacks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@ spec:
stack:
description: Stack is the fully qualified name of the stack to deploy (<org>/<stack>).
type: string
useLocalStackOnly:
description: (optional) UseLocalStackOnly can be set to true to prevent the operator to create stacks that do not exist in the tracking git repo. The default behavior is to create a stack if it doesn't exist.
type: boolean
required:
- projectRepo
- stack
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/operator-framework/operator-lib v0.0.0-20200728190837-b76db547798d
github.com/operator-framework/operator-sdk v0.19.0
github.com/pkg/errors v0.9.1
github.com/pulumi/pulumi/sdk/v3 v3.10.2
github.com/pulumi/pulumi/sdk/v3 v3.10.3
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
github.com/whilp/git-urls v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,8 @@ github.com/prometheus/prometheus v0.0.0-20180315085919-58e2a31db8de/go.mod h1:oA
github.com/prometheus/prometheus v1.8.2-0.20200110114423-1e64d757f711/go.mod h1:7U90zPoLkWjEIQcy/rweQla82OCTUzxVHE51G3OhJbI=
github.com/prometheus/prometheus v2.3.2+incompatible/go.mod h1:oAIUtOny2rjMX0OWN5vPR5/q/twIROJvdqnQKDdil/s=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/pulumi/pulumi/sdk/v3 v3.10.2 h1:srvm3HNEHb/A9+XQuGiXrBswHdvQnTVhFx1crz5Z2y8=
github.com/pulumi/pulumi/sdk/v3 v3.10.2/go.mod h1:GBHyQ7awNQSRmiKp/p8kIKrGrMOZeA/k2czoM/GOqds=
github.com/pulumi/pulumi/sdk/v3 v3.10.3 h1:7XCZRTU5GHg8Us4s7nHJmQhRurLXVmPQ+4MdbHekudE=
github.com/pulumi/pulumi/sdk/v3 v3.10.3/go.mod h1:GBHyQ7awNQSRmiKp/p8kIKrGrMOZeA/k2czoM/GOqds=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
github.com/robfig/cron v0.0.0-20170526150127-736158dc09e1/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/pulumi/v1alpha1/stack_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ type StackSpec struct {
// all spawned retries succeed. This will also create a more populated,
// and randomized activity timeline for the stack in the Pulumi Service.
RetryOnUpdateConflict bool `json:"retryOnUpdateConflict,omitempty"`

// (optional) UseLocalStackOnly can be set to true to prevent the operator to
// create stacks that do not exist in the tracking git repo.
// The default behavior is to create a stack if it doesn't exist.
UseLocalStackOnly bool `json:"useLocalStackOnly,omitempty"`
}

// GitAuthConfig specifies git authentication configuration options.
Expand Down
11 changes: 8 additions & 3 deletions pkg/controller/stack/stack_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,14 @@ func (sess *reconcileStackSession) SetupPulumiWorkdir(gitAuth *auto.GitAuth) err
}
sess.workdir = w.WorkDir()

// Create a new stack if the stack does not already exist, or fall back to
// selecting the existing stack. If the stack does not exist, it will be created and selected.
a, err := auto.UpsertStack(context.Background(), sess.stack.Stack, w)
ctx := context.Background()
var a auto.Stack

if sess.stack.UseLocalStackOnly {
a, err = auto.SelectStack(ctx, sess.stack.Stack, w)
} else {
a, err = auto.UpsertStack(ctx, sess.stack.Stack, w)
}
if err != nil {
return errors.Wrapf(err, "failed to create and/or select stack: %s", sess.stack.Stack)
}
Expand Down
6 changes: 3 additions & 3 deletions test/stack_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ var _ = Describe("Stack Controller", func() {
Commit: commit,
SecretsProvider: "passphrase",
SecretEnvs: []string{
passphraseSecret.ObjectMeta.Name,
passphraseSecret.Name,
},
}

Expand Down Expand Up @@ -256,9 +256,9 @@ var _ = Describe("Stack Controller", func() {

// Define the stack spec
spec := pulumiv1alpha1.StackSpec{
AccessTokenSecret: pulumiAPISecret.ObjectMeta.Name,
AccessTokenSecret: pulumiAPISecret.Name,
SecretEnvs: []string{
pulumiAWSSecret.ObjectMeta.Name,
pulumiAWSSecret.Name,
},
Config: map[string]string{
"aws:region": "us-east-2",
Expand Down

0 comments on commit 8e59f92

Please sign in to comment.