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

Update controller to ensure either of branch or commit is specified #168

Merged
merged 1 commit into from
Jul 29, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ CHANGELOG
## HEAD (Unreleased)
(None)

- Ensure either 'branch' or 'commit' is set in stack CR & bump pulumi/pulumi to 3.9.0 [#168](https://github.com/pulumi/pulumi-kubernetes-operator/pull/168)

## 0.0.15 (2021-07-23)

- Automatically track git branches without a specified commit.
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.6.0
FROM pulumi/pulumi:v3.9.0

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

Expand Down
4 changes: 2 additions & 2 deletions deploy/crds/pulumi.com_stacks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ spec:
description: '(optional) Backend is an optional backend URL to use for all Pulumi operations. Examples: - Pulumi Service: "https://app.pulumi.com" (default) - Self-managed Pulumi Service: "https://pulumi.acmecorp.com" - Local: "file://./einstein" - AWS: "s3://<my-pulumi-state-bucket>" - Azure: "azblob://<my-pulumi-state-bucket>" - GCP: "gs://<my-pulumi-state-bucket>" See: https://www.pulumi.com/docs/intro/concepts/state/'
type: string
branch:
description: (optional) Branch is the branch name to deploy, either the simple or fully qualified ref name. This is mutually exclusive with the Commit setting. If both are empty, the `master` branch is deployed.
description: (optional) Branch is the branch name to deploy, either the simple or fully qualified ref name, e.g. refs/heads/master. This is mutually exclusive with the Commit setting. Either value needs to be specified.
type: string
commit:
description: (optional) Commit is the hash of the commit to deploy. If used, HEAD will be in detached mode. This is mutually exclusive with the Branch setting. If both are empty, the `master` branch is deployed.
description: (optional) Commit is the hash of the commit to deploy. If used, HEAD will be in detached mode. This is mutually exclusive with the Branch setting. Either value needs to be specified.
type: string
config:
additionalProperties:
Expand Down
2 changes: 1 addition & 1 deletion deploy/yaml/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ spec:
emptyDir: {}
containers:
- name: pulumi-kubernetes-operator
image: pulumi/pulumi-kubernetes-operator:v0.0.14
image: pulumi/pulumi-kubernetes-operator:v0.0.15
args:
- "--zap-level=error"
volumeMounts:
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.6.0
github.com/pulumi/pulumi/sdk/v3 v3.9.0
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 @@ -779,8 +779,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.6.0 h1:ZuOGcDwZiuiNyfXH8o2ooy2qBvpGtqft47+9mDOHS70=
github.com/pulumi/pulumi/sdk/v3 v3.6.0/go.mod h1:GBHyQ7awNQSRmiKp/p8kIKrGrMOZeA/k2czoM/GOqds=
github.com/pulumi/pulumi/sdk/v3 v3.9.0 h1:CGBEoPwKVv9GCb8wfgej096n9aZ26H1jUZzMw98NNGs=
github.com/pulumi/pulumi/sdk/v3 v3.9.0/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
6 changes: 3 additions & 3 deletions pkg/apis/pulumi/v1alpha1/stack_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ type StackSpec struct {
// in the project source root.
RepoDir string `json:"repoDir,omitempty"`
// (optional) Commit is the hash of the commit to deploy. If used, HEAD will be in detached mode. This
// is mutually exclusive with the Branch setting. If both are empty, the `master` branch is deployed.
// is mutually exclusive with the Branch setting. Either value needs to be specified.
Commit string `json:"commit,omitempty"`
// (optional) Branch is the branch name to deploy, either the simple or fully qualified ref name. This
// is mutually exclusive with the Commit setting. If both are empty, the `master` branch is deployed.
// (optional) Branch is the branch name to deploy, either the simple or fully qualified ref name, e.g. refs/heads/master. This
// is mutually exclusive with the Commit setting. Either value needs to be specified.
Branch string `json:"branch,omitempty"`

// Lifecycle:
Expand Down
9 changes: 9 additions & 0 deletions pkg/controller/stack/stack_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ func (r *ReconcileStack) Reconcile(request reconcile.Request) (reconcile.Result,
// Create a new reconciliation session.
sess := newReconcileStackSession(reqLogger, stack, r.client, request.Namespace)

// Ensure either branch or commit has been specified in the stack CR if stack is not marked for deletion
if !isStackMarkedToBeDeleted &&
sess.stack.Commit == "" &&
sess.stack.Branch == "" {

reqLogger.Info("Stack CustomResource needs to specify either 'branch' or 'commit' for the tracking repo.")
return reconcile.Result{}, err
}

// Step 1. Set up the workdir, select the right stack and populate config if supplied.
gitAuth, err := sess.SetupGitAuth()
if err != nil {
Expand Down
14 changes: 10 additions & 4 deletions scripts/generate_crds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ cwd=$(dirname "$0")
apis_dir="$cwd/../pkg/apis"
deploy_dir="$cwd/../deploy/crds"

function pased() {
if [ "$(uname)" = 'Darwin' ]; then
sed -i '' -e "$1" "$2"
else
sed -i'' -e "$1" "$2"
fi
}

echo "Generating CRD API types..."

controller-gen crd paths="$apis_dir/..." crd:crdVersions=v1 output:crd:dir="$deploy_dir"

# Manually overwrite until issue is resolved in controller-tools:
# https://git.io/JJsjs
# Requires gnu-sed. On Macs you might have to do the following:
# export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"
sed -i "s#conditions: null#conditions: []#g" "$deploy_dir/pulumi.com_stacks.yaml"
sed -i "s#storedVersions: null#storedVersions: []#g" "$deploy_dir/pulumi.com_stacks.yaml"
pased "s#conditions: null#conditions: []#g" "$deploy_dir/pulumi.com_stacks.yaml"
pased "s#storedVersions: null#storedVersions: []#g" "$deploy_dir/pulumi.com_stacks.yaml"