func createPatch()

in patch.go [60:92]


func createPatch(config agentConfig, spec corev1.PodSpec) ([]patchOperation, error) {
	// Create patch operations
	var patches []patchOperation

	envVariables, err := generateEnvironmentVariables(config)
	if err != nil {
		return nil, err
	}

	// Add a volume mount to the pod
	patches = append(patches, createVolumePatch(spec.Volumes == nil))

	// Add an init container, that will fetch the agent Docker image and
	// extract the agent jar to the agent volume
	patch, err := createInitContainerPatch(config, spec.InitContainers == nil)
	if err != nil {
		return nil, err
	}
	patches = append(patches, patch)

	// Add agent env variables for each container at the pod, as well as
	// the volume mount
	containers := spec.Containers
	for index, container := range containers {
		// Filter out environment variables from the agent config to
		// not overwrite environment variables set directly on the
		// container.
		envVars := uniqueEnvironmentVariables(envVariables, container.Env)
		patches = append(patches, createVolumeMountsPatch(container.VolumeMounts == nil, index))
		patches = append(patches, createEnvVariablesPatches(envVars, container.Env == nil, index)...)
	}
	return patches, nil
}