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

Fix refresh for render-yaml resources #1523

Merged
merged 1 commit into from
Apr 12, 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
@@ -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