func()

in pkg/cmd/podidentity/detect.go [292:319]


func (dc *detectCmd) createResourceFile(localObject k8s.LocalObject, sa *corev1.ServiceAccount) error {
	// add the init container to the container list
	localObject.SetInitContainers(dc.addProxyInitContainer(localObject.GetInitContainers()))
	// add the proxy container to the container list
	localObject.SetContainers(dc.addProxyContainer(localObject.GetContainers()))
	// set the service account name for the object
	localObject.SetServiceAccountName(sa.GetName())
	// reset the managed fields to reduce clutter in the output yaml
	localObject.SetManagedFields(nil)
	// reset the resource version, uid and other metadata to make the yaml file applyable
	localObject.SetResourceVersion("")
	localObject.SetUID("")
	localObject.SetCreationTimestamp(metav1.Time{})
	localObject.SetSelfLink("")
	localObject.SetGeneration(0)
	localObject.ResetStatus()
	// set the group version kind explicitly before serializing the object
	localObject.SetGVK()

	// write the modified object to the output dir
	file, err := os.Create(dc.getResourceFileName(localObject))
	if err != nil {
		return err
	}
	defer file.Close()

	return dc.serializer.Encode(localObject.GetObject(), file)
}