https://pulumi.com logo
#kubernetes
Title
# kubernetes
h

happy-soccer-64223

11/15/2020, 9:09 PM
Hi everyone, i'm a bit lost with the kubernetes-sdk in Go. I don't see how we can provide for our developers a simple way to use reusable libraries. My idea is to provide for example a library adding a volume and a volume mount to every deployment. Really a simple chain of modification like we would do with the go sdk.
Copy code
deployment, err := MyCustomGen(name)
err = MyCustomDeploymentPatch(deployment)
I might be missing something bu i don't see how it's feasible with the pulumi-sdk. My question basically is how can we do two-pass modification on any object.
b

billowy-army-68599

11/15/2020, 10:54 PM
hey! The way to do this is to create a Component: https://www.pulumi.com/docs/intro/concepts/programming-model/#components you'd define options and a struct which gets passed as args. you can see an example here: https://github.com/jaxxstorm/pulumi-clusterautoscalerx/blob/master/main.go it's them useable as a standard Go module
h

happy-soccer-64223

11/16/2020, 12:19 AM
Thanks @billowy-army-68599. I've been trying to write up what i want to achieve for the last 40minutes, but i give up and give you a simple question instead. What is the good way in the go-sdk to read and modify args (DeploymentSpecArgs for example) and modify them. Let's say i want to iterate over a range of Volume inside a DeploymentSpecArgs. Yes that's my question 🙂
b

billowy-army-68599

11/16/2020, 12:19 AM
do you mean for an existing deployment that hasn't been created using Pulumi?
h

happy-soccer-64223

11/16/2020, 12:20 AM
no, i mean:
Copy code
&appsv1.DeploymentArgs{
		Metadata: metav1.ObjectMetaArgs{
			Annotations: annotations,
			Namespace:   pulumi.String(namespace),
			Name:        pulumi.String(app.Name),
		},
		Spec: appsv1.DeploymentSpecArgs{
			Selector: &metav1.LabelSelectorArgs{
				MatchLabels: labels,
			},
			Strategy: appsv1.DeploymentStrategyArgs{
				RollingUpdate: appsv1.RollingUpdateDeploymentArgs{
					MaxSurge:       pulumi.String("35%"),
					MaxUnavailable: pulumi.String("0%"),
				},
			},
			Template: &corev1.PodTemplateSpecArgs{
				Metadata: &metav1.ObjectMetaArgs{
					Labels: labels,
				},
				Spec: &corev1.PodSpecArgs{
					Containers: containers,
				},
			},
		},
	}
imagine wanting to range over MatchLabels
that's it
that would mean casting the type of whatever u'd want to access i guess
instead of just iterate over it
b

billowy-army-68599

11/16/2020, 12:25 AM
how is
labels
(the variable) defined?
MatchLabels
takes a
StringMap
which should be iterable
h

happy-soccer-64223

11/16/2020, 12:28 AM
ok wrong example in that case
imagine the labels being defined in the args
you would have the following error
Copy code
pkg/mutations/deployment.go:117:8: d.Spec.Selector undefined (type "<http://github.com/pulumi/pulumi-kubernetes/sdk/v2/go/kubernetes/apps/v1|github.com/pulumi/pulumi-kubernetes/sdk/v2/go/kubernetes/apps/v1>".DeploymentSpecPtrInput has no field or method Selector
because each field is an interface instead of being the actual field
b

billowy-army-68599

11/16/2020, 12:31 AM
sorry, it's a little difficult understanding without the full example, I'm not following I'm afraid
h

happy-soccer-64223

11/16/2020, 12:32 AM
i'm getting lost too sorry mate
let me build up a full example i'll shoot u that tomorrow (2am here)
👍 1
3 Views