Getting dreaded `Calling [toString] on an [Output&...
# general
i
Getting dreaded
Calling [toString] on an [Output<T>] is not supported
in my transformer. The transformer is shared code and may be used with a namespace instance or string. What have I messed up here:
Copy code
/**
 * May be needed to get helm to behave.
 *
 *  Usage: `transformations: [createTransformAddNamespace(namespace)]`
 *
 * @see <https://github.com/pulumi/pulumi-kubernetes/issues/217#issuecomment-459105809>
 * @see <https://github.com/pulumi/pulumi-kubernetes/issues/415#issuecomment-469118560>
 */
export function createTransformAddNamespace(
  namespaceStringOrResource: string | k8s.core.v1.Namespace,
) {
  return <T extends { metadata?: Input<meta.v1.ObjectMeta> }>(o: T) => {
    let namespace: Input<string>
    if (typeof namespaceStringOrResource === 'string') {
      namespace = namespaceStringOrResource
    } else {
      namespace = namespaceStringOrResource.metadata.name.apply(v => v)
    }

    if (o) {
      if (o.metadata !== undefined) {
        o.metadata['namespace'] = namespace
      } else {
        o.metadata = { namespace: namespace }
      }
    }
  }
}
m
cc @calm-apple-46440 @creamy-potato-29402
IIRC we recently fixed a similar bug in one of our examples
c
@gorgeous-egg-16927 I believe we are in the process of fixing this, right?
g
Yes, this bug was uncovered last week, and I’m in the process of fixing it. https://github.com/pulumi/pulumi-kubernetes/issues/478
b
i think you can do `if (namespaceStringOrResource intanceof string) { }`there