Skip to content

Commit

Permalink
Fix refresh for render-yaml resources
Browse files Browse the repository at this point in the history
  • Loading branch information
lblackstone committed Apr 9, 2021
1 parent 80656f0 commit 9a5efa8
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions provider/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1461,12 +1461,12 @@ func (k *kubeProvider) Create(
"rendered file %s contains a secret value in plaintext",
renderPathForResource(annotatedInputs, k.yamlDirectory)))
}
err := renderYaml(annotatedInputs, k.yamlDirectory)
err := renderYaml(newInputs, k.yamlDirectory)
if err != nil {
return nil, err
}

obj := checkpointObject(newInputs, annotatedInputs, newResInputs, initialAPIVersion)
obj := checkpointObject(newInputs, newInputs, newResInputs, initialAPIVersion)
inputsAndComputed, err := plugin.MarshalProperties(
obj, plugin.MarshalOptions{
Label: fmt.Sprintf("%s.inputsAndComputed", label),
Expand All @@ -1479,10 +1479,10 @@ func (k *kubeProvider) Create(
}

_ = k.host.LogStatus(ctx, diag.Info, urn, fmt.Sprintf(
"rendered %s", renderPathForResource(annotatedInputs, k.yamlDirectory)))
"rendered %s", renderPathForResource(newInputs, k.yamlDirectory)))

return &pulumirpc.CreateResponse{
Id: fqObjName(annotatedInputs), Properties: inputsAndComputed,
Id: fqObjName(newInputs), Properties: inputsAndComputed,
}, nil
}

Expand Down 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 9a5efa8

Please sign in to comment.