Skip to content

Commit

Permalink
Allow skipAwait to skip only readiness or deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
blampe committed Aug 9, 2024
1 parent eaa802e commit f3a721d
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
Existing readiness logic is unaffected by this setting.
(https://github.com/pulumi/pulumi-kubernetes/issues/2996)

- The `pulumi.com/skipAwait` annotation now accepts values of "ready" or
"delete" to skip await behavior when creating/updating or when deleting a
resource, respectively.
(https://github.com/pulumi/pulumi-kubernetes/issues/2551)

### Fixed

- Fixed a panic that could occur during deletion. (https://github.com/pulumi/pulumi-kubernetes/issues/3157)
Expand Down
2 changes: 1 addition & 1 deletion provider/pkg/await/await.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ func (l *legacyCreateCondition) Satisfied() (bool, error) {
}

func newLegacyCreateCondition(c awaitConfig, await func(awaitConfig) error) condition.Satisfier {
if metadata.SkipAwaitLogic(c.inputs) {
if metadata.SkipReadyCondition(c.inputs) {
return condition.NewImmediate(c.logger, c.currentOutputs)
}

Expand Down
14 changes: 13 additions & 1 deletion provider/pkg/metadata/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ func SkipAwaitLogic(obj *unstructured.Unstructured) bool {
return IsAnnotationTrue(obj, AnnotationSkipAwait)
}

// SkipReadyCondition returns true if the inputs and type are annotated such that we
// should not await readiness.
func SkipReadyCondition(inputs *unstructured.Unstructured) bool {
if IsAnnotationTrue(inputs, AnnotationSkipAwait) {
return true
}
return strings.EqualFold(GetAnnotationValue(inputs, AnnotationSkipAwait), "ready")
}

// ReplaceUnready returns true if the `pulumi.com/replaceUnready` annotation is "true", false otherwise.
func ReplaceUnready(obj *unstructured.Unstructured) bool {
return IsAnnotationTrue(obj, AnnotationReplaceUnready)
Expand Down Expand Up @@ -92,7 +101,7 @@ func ReadyCondition(
inputs *unstructured.Unstructured,
obj *unstructured.Unstructured,
) (condition.Satisfier, error) {
if SkipAwaitLogic(inputs) {
if SkipReadyCondition(inputs) {
return condition.NewImmediate(logger, obj), nil
}
if os.Getenv("PULUMI_K8S_AWAIT_ALL") != "true" {
Expand All @@ -118,6 +127,9 @@ func DeletedCondition(
if IsAnnotationTrue(inputs, AnnotationSkipAwait) && allowsSkipAwaitWithDelete(inputs) {
return condition.NewImmediate(logger, obj), nil
}
if strings.EqualFold(GetAnnotationValue(obj, AnnotationSkipAwait), "delete") {
return condition.NewImmediate(logger, obj), nil
}
getter, err := clientset.ResourceClientForObject(obj)
if err != nil {
return nil, err
Expand Down
68 changes: 68 additions & 0 deletions provider/pkg/metadata/overrides_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,52 @@ func TestReadyCondition(t *testing.T) {
genericEnabled: true,
want: condition.Immediate{},
},
{
name: "skipAwait=ready, generic await disabled",
inputs: &unstructured.Unstructured{Object: map[string]any{
"metadata": map[string]any{
"annotations": map[string]any{
AnnotationSkipAwait: "ready",
},
},
}},
want: condition.Immediate{},
},
{
name: "skipAwait=ready, generic await enabled",
inputs: &unstructured.Unstructured{Object: map[string]any{
"metadata": map[string]any{
"annotations": map[string]any{
AnnotationSkipAwait: "ready",
},
},
}},
genericEnabled: true,
want: condition.Immediate{},
},
{
name: "skipAwait=delete, generic await disabled",
inputs: &unstructured.Unstructured{Object: map[string]any{
"metadata": map[string]any{
"annotations": map[string]any{
AnnotationSkipAwait: "delete",
},
},
}},
want: condition.Immediate{},
},
{
name: "skipAwait=delete, generic await enabled",
inputs: &unstructured.Unstructured{Object: map[string]any{
"metadata": map[string]any{
"annotations": map[string]any{
AnnotationSkipAwait: "delete",
},
},
}},
genericEnabled: true,
want: &condition.Ready{},
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -236,6 +282,28 @@ func TestDeletedCondition(t *testing.T) {
},
want: condition.Immediate{},
},
{
name: "skipAwait=delete",
inputs: &unstructured.Unstructured{Object: map[string]any{
"metadata": map[string]any{
"annotations": map[string]any{
AnnotationSkipAwait: "delete",
},
},
}},
want: condition.Immediate{},
},
{
name: "skipAwait=ready",
inputs: &unstructured.Unstructured{Object: map[string]any{
"metadata": map[string]any{
"annotations": map[string]any{
AnnotationSkipAwait: "ready",
},
},
}},
want: &condition.Deleted{},
},
{
name: "skipAwait=false",
inputs: &unstructured.Unstructured{
Expand Down

0 comments on commit f3a721d

Please sign in to comment.