Got some yaml files being applied to a k8s cluster...
# general
m
Got some yaml files being applied to a k8s cluster created by Pulumi. When running
pulumi down
I would like for Pulumi to just ignore resources inside the cluster as the entire cluster is going to be terminated regardless of internal state. I tried adding
RetainOnDelete(true)
but it appears to not do what I hoped it would. What is the best approach here? Code in comment.
Copy code
_, err = yaml.NewConfigGroup(ctx, "flux-data-sync", &yaml.ConfigGroupArgs{
		YAML:      []string{result.Content},
		SkipAwait: false,
	}, pulumi.Provider(provider), pulumi.RetainOnDelete(true))
Perhaps it does work like I believe it would, but the summary list of resources to destroy is misleading?
b
retainOnDelete
only works for directly applied resources unfortunately, if you want this to happen I recommend using
kube2pulumi
and directly creating the resources
NewConfigGroup
is a COmponentResource so it operates a little differently
m
Right, thanks, I will check it out ๐Ÿ™‚
Not an optimal solution for a tool that generates a bunch of resource definitions (Flux). Bummer.
@billowy-army-68599 is there a technical limitation why its not possible to just ignore these resources on
pulumi down
?
b
because those files exist in the state, and Pulumi wants to manage them. you could achieve what you want with a transformation
m
right, thanks, iโ€™ll read the docs on transformation - hope itโ€™s okay if i reply here if i am to dumb to figure it out ๐Ÿ˜„
im either too dumb, this simply rewrites the yaml file itself during creation?
b
wht does?
m
Nevermind, the kubernetes yaml ConfigGroups had its own Transformation. I got confused and assumed you meant that๐Ÿ™‚
the
opts
I want are still not going to work with a component resource, thats too bad.
b
no, but the component resource creates child resources. You can use a transformation to manipulate those opts in tose
i may have time later to create an example
m
that would be awesome, there is a lot of things to take in coming from Terraform and i just get lost some times
I wonder if something like this is going to solve it for me, though I am worried what happens when i upgrade the flux provider and it creates new versions of the manifests.
Copy code
return func(args *pulumi.ResourceTransformationArgs) *pulumi.ResourceTransformationResult {
		if args.Type == "kubernetes:core/v1:Namespace" ||
			args.Type == "kubernetes:<http://apiextensions.k8s.io/v1:CustomResourceDefinition|apiextensions.k8s.io/v1:CustomResourceDefinition>" ||
			args.Type == "kubernetes:core/v1:ServiceAccount" ||
			args.Type == "kubernetes:<http://rbac.authorization.k8s.io/v1:ClusterRole|rbac.authorization.k8s.io/v1:ClusterRole>" ||
			args.Type == "kubernetes:<http://rbac.authorization.k8s.io/v1:ClusterRoleBinding|rbac.authorization.k8s.io/v1:ClusterRoleBinding>" ||
			args.Type == "kubernetes:core/v1:Service" ||
			args.Type == "kubernetes:apps/v1:Deployment" ||
			args.Type == "kubernetes:<http://networking.k8s.io/v1:NetworkPolicy|networking.k8s.io/v1:NetworkPolicy>" ||
			args.Type == "kubernetes:<http://source.toolkit.fluxcd.io/v1beta2:GitRepository|source.toolkit.fluxcd.io/v1beta2:GitRepository>" ||
			args.Type == "kubernetes:<http://kustomize.toolkit.fluxcd.io/v1beta2:Kustomization|kustomize.toolkit.fluxcd.io/v1beta2:Kustomization>" {
			return &pulumi.ResourceTransformationResult{
				Props: args.Props,
				Opts:  append(args.Opts, pulumi.RetainOnDelete(true), pulumi.DeleteBeforeReplace(false)),
			}
		}
		return nil
	}
b
opts append is correct, but you should be able to retrieve every resource withput using
if
statement
m
it also took in the parent of those types, which did not support RetainOnDelete or DeleteBeforeReplace, i guess a
not
expression for the two parents could suffice as well, but were unable to solve it any other way