Skip to content

Adding Dynamic Label To Composite Resource Does Not Work #257

@danielshiplett

Description

@danielshiplett

What happened?

We are investigating replacing our YAML based Compositions with Go based Functions. As part of that, we want to be able to add some additional labels dynamically to the Composite Resource. However, when we try to do that, we don't end up with any new labels. Here is an example of how we try to add the labels:

func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest) (*fnv1.RunFunctionResponse, error) {
  rsp := response.To(req, response.DefaultTTL)

  xr, err := request.GetObservedCompositeResource(req)
  if err != nil {
	response.Fatal(rsp, errors.Wrapf(err, "cannot get observed composite resource from %T", req))
	return rsp, nil
  }

  ... code that sets desired resources ...

  // This works as expected
  xr.Resource.SetString("status.hostname", fullHostname)

  // This is how I think it should have worked even though it didn't.
  origLabels := xr.Resource.GetLabels()
  origLabels["controplane.com/anything-we-want"] = "a-new-and-special-value"
  xr.Resource.SetLabels(origLabels)

  response.SetDesiredCompositeResource(rsp, xr)
  response.Normal(rsp, "Success")
  return rsp, nil
}

Please let me know if there is another way to set a label using the Go SDK.

How can we reproduce it?

What environment did it happen in?

Crossplane version: v2.1.1 (server)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions