Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add useLocalStackOnly option to prevent stack creation #186

Merged
merged 1 commit into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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