Make desired resources map values pointers to struct
This makes it possible to mutate struct values while iterating over the map of composed resources. I found myself naturally wanting to do this while writing a Function. e.g.: desired, _ = request.GetDesiredComposedResources(req) for _, dr := range desired { dr.Ready = resource.ReadyTrue } _ = response.SetDesiredComposedResources(desired) I haven't made the same change for observed resources, since they're supposed to be read-only to a Function. Signed-off-by: Nic Cope <nicc@rk0n.org>
This commit is contained in:
parent
ef3a2e04d3
commit
fce65c0f3f
|
@ -67,10 +67,10 @@ func GetDesiredCompositeResource(req *v1beta1.RunFunctionRequest) (*resource.Com
|
|||
}
|
||||
|
||||
// GetDesiredComposedResources from the supplied request.
|
||||
func GetDesiredComposedResources(req *v1beta1.RunFunctionRequest) (map[resource.Name]resource.DesiredComposed, error) {
|
||||
dcds := map[resource.Name]resource.DesiredComposed{}
|
||||
func GetDesiredComposedResources(req *v1beta1.RunFunctionRequest) (map[resource.Name]*resource.DesiredComposed, error) {
|
||||
dcds := map[resource.Name]*resource.DesiredComposed{}
|
||||
for name, r := range req.GetDesired().GetResources() {
|
||||
dcd := resource.DesiredComposed{Resource: composed.New()}
|
||||
dcd := &resource.DesiredComposed{Resource: composed.New()}
|
||||
if err := resource.AsObject(r.GetResource(), dcd.Resource); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ func SetDesiredCompositeResource(rsp *v1beta1.RunFunctionResponse, xr *resource.
|
|||
// supplied response. The caller must be sure to avoid overwriting the desired
|
||||
// state that may have been accumulated by previous Functions in the pipeline,
|
||||
// unless they intend to.
|
||||
func SetDesiredComposedResources(rsp *v1beta1.RunFunctionResponse, dcds map[resource.Name]resource.DesiredComposed) error {
|
||||
func SetDesiredComposedResources(rsp *v1beta1.RunFunctionResponse, dcds map[resource.Name]*resource.DesiredComposed) error {
|
||||
if rsp.Desired == nil {
|
||||
rsp.Desired = &v1beta1.State{}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue