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 Inline YAML Program Functionality #336

Merged
merged 11 commits into from
Oct 14, 2022
Merged

Add Inline YAML Program Functionality #336

merged 11 commits into from
Oct 14, 2022

Conversation

roothorp
Copy link
Contributor

@roothorp roothorp commented Oct 7, 2022

Fixes #312

@roothorp roothorp requested a review from squaremo October 7, 2022 15:20
@roothorp roothorp self-assigned this Oct 7, 2022
@squaremo
Copy link
Contributor

squaremo commented Oct 10, 2022

Test cases:

  • Can create the Program value and savee it; and create a Stack that refers to it
  • A valid Program/Stack pair will run the stack (make the Program do something minimal, though)
    • need to save kubeconfig and refer to it in env as KUBECONFIG (examples in other tests)
  • A Stack refering to a missing Program will fail and be marked "retrying" "stalled" (I think there's a SourceUnavailable reason)
  • A Program that is syntactically OK but invalid (e.g., dangling variable reference) will cause the Stack to fail and be marked stalled, reason: "incorrect program"

deploy/crds/pulumi.com_programs.yaml Show resolved Hide resolved
pkg/controller/stack/stack_controller.go Outdated Show resolved Hide resolved
test/program_test.go Outdated Show resolved Hide resolved
test/program_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@squaremo squaremo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take my comments as suggestions, in general. This is "request changes" because I would like to see comments on the new API fields, so that there are descriptions in the documentation.

deploy/crds/pulumi.com_stacks.yaml Outdated Show resolved Hide resolved
pkg/apis/pulumi/v1/program_types.go Outdated Show resolved Hide resolved
pkg/apis/pulumi/shared/stack_types.go Outdated Show resolved Hide resolved
pkg/controller/stack/stack_controller.go Outdated Show resolved Hide resolved
pkg/controller/stack/stack_controller.go Show resolved Hide resolved
test/program_test.go Outdated Show resolved Hide resolved
test/program_test.go Outdated Show resolved Hide resolved
test/program_test.go Outdated Show resolved Hide resolved
test/program_test.go Outdated Show resolved Hide resolved
test/program_test.go Show resolved Hide resolved
Roo Thorp added 4 commits October 13, 2022 13:37
This commit implements the handling of Stacks that refer to Programs, by
adding a case for .spec.programRef, a func to setup the workspace, and a
special case for rescheduling.
@squaremo squaremo force-pushed the roothorp/inline-yaml branch from 7999e10 to 9127fd0 Compare October 13, 2022 13:46
Roo Thorp and others added 3 commits October 13, 2022 14:48
NB: the codegen (via `crdoc`) fails to escape angle braces in the enum
values, so docs/programs.md is not quite correct. Ideally we can fix the
upstream bug at some point.

Signed-off-by: Michael Bridgen <mbridgen@pulumi.com>
Co-authored-by: Roo Thorp <roo@pulumi.com>
@squaremo squaremo force-pushed the roothorp/inline-yaml branch from 9127fd0 to c0f70d1 Compare October 13, 2022 13:48
@roothorp roothorp marked this pull request as ready for review October 14, 2022 13:03
Copy link
Contributor

@squaremo squaremo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good; there's a couple of cosmetic things that could be changed, but neither is a one way door. Nice work! 🍎

reqLogger.Info("New commit hash found", "Current commit", currentCommit,
"Last commit", instance.Status.LastUpdate.LastSuccessfulCommit)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: we've kept this repeated section deliberately, for now, to keep the pattern of if-then-else with the various sources. We should revisit the control flow of the whole method, at some point.

@@ -868,6 +905,70 @@ func (sess *reconcileStackSession) SetupWorkdirFromGitSource(ctx context.Context
return revision, sess.setupWorkspace(ctx, w)
}

// ProjectFile adds required Pulumi 'project' fields to the Program spec, making it valid to be given to Pulumi.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

// +kubebuilder:validation:Enum={"String", "Number", "List<Number>", "List<String>"}
type ConfigTypes string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type ConfigTypes string
type ConfigType string

It would be conventional for the type name to be singular here: ConfigType. The name doesn't form part of the public API (except in so far as it's exported from this package), though.

type Configuration struct {
// type is the (required) data type for the parameter.
// +optional
Type ConfigTypes `json:"type,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Type ConfigTypes `json:"type,omitempty"`
Type ConfigType `json:"type,omitempty"`

if strings.HasPrefix(tmpDir, os.TempDir()) {
os.RemoveAll(tmpDir)
}
err := k8sClient.Delete(context.TODO(), &stack)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err := k8sClient.Delete(context.TODO(), &stack)
Expect(k8sClient.Delete(context.TODO(), &stack)).To(Succeed())

Expect(stack.Status.LastUpdate.State).To(Equal(shared.FailedStackStateMessage))
stalledCondition := apimeta.FindStatusCondition(stack.Status.Conditions, pulumiv1.StalledCondition)
Expect(stalledCondition).ToNot(BeNil(), "stalled condition is present")
Expect(stalledCondition.Reason).To(Equal(pulumiv1.StalledSourceUnavailableReason))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

waitForStackFailure(&stack)

Expect(stack.Status.LastUpdate.State).To(Equal(shared.FailedStackStateMessage))
// TODO: Condition for invalid program?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally all we'll know is that the automation API failed to run it to completion; a failed state might be as good as we can do for now.

@roothorp roothorp merged commit 72e4168 into master Oct 14, 2022
@roothorp roothorp deleted the roothorp/inline-yaml branch October 14, 2022 16:11
@squaremo
Copy link
Contributor

NB on failing tests: the failures already fail on default branch. We'll try to roll default branch forward to fix them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support inline programs
3 participants