https://pulumi.com logo
Join the conversationJoin Slack
Channels
announcements
automation-api
aws
azure
blog-posts
built-with-pulumi
cloudengineering
cloudengineering-support
content-share
contribex
contribute
docs
dotnet
finops
general
getting-started
gitlab
golang
google-cloud
hackathon-03-19-2020
hacktoberfest
install
java
jobs
kubernetes
learn-pulumi-events
linen
localstack
multi-language-hackathon
office-hours
oracle-cloud-infrastructure
plugin-framework
pulumi-cdk
pulumi-crosscode
pulumi-deployments
pulumi-kubernetes-operator
pulumi-service
pulumiverse
python
registry
status
testingtesting123
testingtesting321
typescript
welcome
workshops
yaml
Powered by Linen
golang
  • b

    boundless-telephone-98269

    02/10/2022, 5:57 PM
    Are nested ApplyT discouraged along with creating resources within them?
  • b

    boundless-telephone-98269

    02/10/2022, 5:58 PM
    I noticed that they can be avoided but the solution would be verbose, but this may be the accepted norm with writing pulumi stuff in go.
  • b

    bored-table-20691

    02/10/2022, 5:59 PM
    Creating resources - yes, generally. I’m trying to thinkof a situation where nested
    ApplyT
    would even make sense.
  • q

    quiet-wolf-18467

    02/11/2022, 7:40 AM
    Creating resources within ApplyT can mean that the preview isn't always accurate. I wouldn't go as far to call this an anti pattern, but definitely a last resort.
    l
    f
    • 3
    • 2
  • r

    ripe-shampoo-80285

    02/12/2022, 5:38 PM
    Does pulumi support Helmfile?
    q
    • 2
    • 1
  • b

    boundless-telephone-98269

    02/12/2022, 10:43 PM
    I'm working with helm charts and I'm trying to grab the cluster IP of a service.
    clusterIP := chart.GetResource("v1/Service", "onepassword-connect", Namespace).ApplyT(
    			func(r interface{}) (pulumi.StringPtrOutput, error) {
    				return r.(*corev1.Service).Spec.ClusterIP(), nil
    			},
    		)
  • b

    boundless-telephone-98269

    02/12/2022, 10:44 PM
    In the above code, it appears that
    clusterIP
    is of the type
    pulumi.AnyOutput
    . Is there anyway I can get it to be of type
    pulumi.StringPtrOutput
    so I can feed it into something else? Casting doesn't work.
  • b

    boundless-telephone-98269

    02/12/2022, 10:51 PM
    Hmm, I'm having trouble wrapping my head around the Pulumi type system in Go. Are there any good resources/docs on navigating through it? I've been poking around in the codebase, but progress has been slow. Any guidance would be much appreciated!
  • b

    boundless-telephone-98269

    02/12/2022, 11:09 PM
    Ah, I managed to do it somehow. This feels very hacky tho... or is this just the right way to do it? Converting
    pulumi.AnyOutput
    ->
    pulumi.StringPtrOutput
    by:
    output := chart.GetResource("v1/Service", "onepassword-connect", Namespace).ApplyT(
    			func(r interface{}) (pulumi.StringPtrOutput, error) {
    				return r.(*corev1.Service).Spec.ClusterIP(), nil
    			},
    		).(pulumi.AnyOutput)
    		clusterIP := pulumi.StringPtrOutput{OutputState: output.OutputState} // <-------
  • b

    bored-table-20691

    02/13/2022, 5:27 AM
    @boundless-telephone-98269 this shouldn't be necessary. Can you share some more code, including the chart creation?
  • b

    boundless-telephone-98269

    02/13/2022, 5:07 PM
    The chart creation is fairly standard:
    chart, err := helm.NewChart(ctx, ResourceName, helm.ChartArgs{
    			Namespace: pulumi.String(Namespace),
    			Chart:     pulumi.String(Chart),
    			Version:   pulumi.String(ChartVersion),
    			FetchArgs: helm.FetchArgs{
    				Repo: pulumi.String(Repository),
    			},
    			Values: pulumi.Map{
    				"connect": pulumi.Map{
    					"serviceType": pulumi.String("ClusterIP"),
    					"credentials": cfg.RequireSecret("CONNECT_CREDENTIALS"),
    				},
    			},
    		}
  • b

    boundless-telephone-98269

    02/13/2022, 5:08 PM
    The reason why I need
    clusterIP
    to be of type
    pulumi.StringPtrOutput
    instead of
    pulumi.AnyOutput
    is because I'm passing it on into the environment variable of a kubernetes pod.
    a
    • 2
    • 2
  • b

    boundless-telephone-98269

    02/13/2022, 5:09 PM
    Containers: corev1.ContainerArray{
    						corev1.ContainerArgs{
    							Name:  pulumi.String(...),
    							Image: pulumi.String(Image),
    							Env: corev1.EnvVarArray{
    								corev1.EnvVarArgs{
    									Name:  pulumi.String("DEST_IP"),
    									Value: clusterIP, // <-----
    								},
    							},
    						},
    					},
  • b

    bored-table-20691

    02/13/2022, 7:19 PM
    I'm not at a computer but the way you did it shouldn't be necessary. In the ApplyT you should be able to return a string and then cast the result of apply to a StringOutput (which has a method to convert to StringPtrOutput)
    b
    • 2
    • 1
  • a

    astonishing-solstice-53645

    02/13/2022, 7:45 PM
    Is this related to the Service's cluster IP being something reconciled after kubectl (sdk here) apply? Flow: 1. Generate chart 2. Submit chart to k8s api 3. Wait for Service to be assigned ip (almost instant in practice) 4. Query k8s api for Service cluster IP. I think we're missing 4?
  • b

    boundless-telephone-98269

    02/13/2022, 7:54 PM
    This is how I'm doing 4:
    output := chart.GetResource("v1/Service", "onepassword-connect", Namespace).ApplyT(
    			func(r interface{}) (pulumi.StringPtrOutput, error) {
    				return r.(*corev1.Service).Spec.ClusterIP(), nil
    			},
    		).(pulumi.AnyOutput)
    clusterIP := pulumi.StringPtrOutput{OutputState: output.OutputState}
    a
    • 2
    • 1
  • b

    bored-table-20691

    02/13/2022, 7:57 PM
    You definitely shouldn't need to construct the StringPtrOutput like that.
  • b

    boundless-telephone-98269

    02/13/2022, 8:01 PM
    I'm likely doing something wrong... If I try this:
    clusterIP := chart.GetResource("v1/Service", "onepassword-connect", Namespace).ApplyT(
    			func(r interface{}) (pulumi.StringPtrOutput, error) {
    				return r.(*corev1.Service).Spec.ClusterIP(), nil
    			},
    		).(pulumi.StringPtrOutput)
  • b

    boundless-telephone-98269

    02/13/2022, 8:01 PM
    I get this error
    panic: interface conversion: pulumi.Output is pulumi.AnyOutput, not pulumi.StringPtrOutput
  • b

    boundless-telephone-98269

    02/13/2022, 8:04 PM
    I think the returning type of the ApplyT is
    AnyOutput
    because the return type of my applier function is an output type
    pulumi.StringPtrOutput
    instead of something like
    string
  • b

    boundless-telephone-98269

    02/13/2022, 8:04 PM
    I can't return just a string tho because
    r.(*corev1.Service).Spec.ClusterIP()
    is of type
    pulumi.StringPtrOutput
    and what I want
  • b

    bored-table-20691

    02/13/2022, 8:05 PM
    What's the tyPe of getresource?
  • b

    boundless-telephone-98269

    02/13/2022, 8:05 PM
    It's
    pulumi.AnyOutput
  • b

    boundless-telephone-98269

    02/13/2022, 8:05 PM
    This is the function:
  • b

    boundless-telephone-98269

    02/13/2022, 8:05 PM
    func (c *Chart) GetResource(gvk, name, namespace string) pulumi.AnyOutput {
    	id := name
    	if len(namespace) > 0 && namespace != "default" {
    		id = fmt.Sprintf("%s/%s", namespace, name)
    	}
    	key := fmt.Sprintf("%s::%s", gvk, id)
    	return c.Resources.ApplyT(func(x interface{}) interface{} {
    		resources := x.(map[string]pulumi.Resource)
    		return resources[key]
    	}).(pulumi.AnyOutput)
    }
  • b

    boundless-telephone-98269

    02/13/2022, 8:06 PM
    type AnyOutput struct{ *OutputState }
  • b

    boundless-telephone-98269

    02/13/2022, 8:20 PM
    Pulumi seems to do a bunch of type magic behind the scenes so it's kinda confusing. I'm trying to wrap my head around the semantics of
    AnyOutput
    and how to work with it
  • b

    boundless-telephone-98269

    02/13/2022, 8:20 PM
    I'm surprised this works too
    pulumi.StringPtrOutput{OutputState: output.OutputState}
    but I'm okay with it since it's a one liner but this might be the recommended method
  • b

    bored-table-20691

    02/13/2022, 8:22 PM
    https://pulumi-community.slack.com/archives/C01PF3E1B8V/p1641997404069200
  • b

    bored-table-20691

    02/13/2022, 8:22 PM
    There may be something useful there
Powered by Linen
Title
b

bored-table-20691

02/13/2022, 8:22 PM
There may be something useful there
View count: 3