Skip to content

Commit

Permalink
Fix refresh for render-yaml resources
Browse files Browse the repository at this point in the history
Refreshing a stack with resources using a
"render-yaml" Provider would delete those
resources. This change 	fixes the Read
operation to handle YAML rendering.
  • Loading branch information
lblackstone committed Apr 12, 2021
1 parent 80656f0 commit b01ef95
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## HEAD (Unreleased)

- Fix refresh for render-yaml resources (https://github.com/pulumi/pulumi-kubernetes/pull/1523)

## 2.9.0 (April 8, 2021)

- Add support for k8s v1.21.0. (https://github.com/pulumi/pulumi-kubernetes/pull/1449)
Expand Down
30 changes: 29 additions & 1 deletion provider/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,30 @@ func (k *kubeProvider) Read(ctx context.Context, req *pulumirpc.ReadRequest) (*p
if err != nil {
return nil, err
}

if k.yamlRenderMode {
// Return a new "checkpoint object".
state, err := plugin.MarshalProperties(
checkpointObject(oldInputs, newInputs, oldState, initialAPIVersion), plugin.MarshalOptions{
Label: fmt.Sprintf("%s.state", label),
KeepUnknowns: true,
SkipNulls: true,
KeepSecrets: k.enableSecrets,
})
if err != nil {
return nil, err
}

inputs, err := plugin.MarshalProperties(oldInputsPM, plugin.MarshalOptions{
Label: label + ".inputs", KeepUnknowns: true, SkipNulls: true, KeepSecrets: k.enableSecrets,
})
if err != nil {
return nil, err
}

return &pulumirpc.ReadResponse{Id: req.GetId(), Properties: state, Inputs: inputs}, nil
}

resources, err := k.getResources()
if err != nil {
return nil, pkgerrors.Wrapf(err, "Failed to fetch OpenAPI schema from the API server")
Expand Down Expand Up @@ -2412,8 +2436,12 @@ var deleteResponse = &pulumirpc.ReadResponse{Id: "", Properties: nil}
// parseLastAppliedConfig attempts to find and parse an annotation that records the last applied configuration for the
// given live object state.
func parseLastAppliedConfig(live *unstructured.Unstructured) *unstructured.Unstructured {
// If `kubectl.kubernetes.io/last-applied-configuration` metadata anotation is present, parse it into a real object
// If `kubectl.kubernetes.io/last-applied-configuration` metadata annotation is present, parse it into a real object
// and use it as the current set of live inputs. Otherwise, return nil.
if live == nil {
return nil
}

annotations := live.GetAnnotations()
if annotations == nil {
return nil
Expand Down

0 comments on commit b01ef95

Please sign in to comment.