Repository: kubernetes/kubernetes
File: test/e2e/dra/utils/deploy.go (Go)

Code before:
	content = strings.ReplaceAll(content, "dra-kubelet-plugin", "dra-kubelet-plugin-"+d.Name+d.InstanceSuffix)
	d.createFromYAML(tCtx, []byte(content), tCtx.Namespace())

	// Using a ReplicaSet instead of a DaemonSet has the advantage that we can control
	// the lifecycle explicitly, in particular run two pods per node long enough to
	// run checks.
	instanceKey := "app.kubernetes.io/instance"
	rsName := ""
	numNodes := int32(len(nodes.NodeNames))
	pluginDataDirectoryPath := path.Join(kubeletRootDir, "plugins", d.Name)
	registrarDirectoryPath := path.Join(kubeletRootDir, "plugins_registry")
	instanceName := d.Name + d.InstanceSuffix
	err := utils.CreateFromManifestsTCtx(tCtx, func(item interface{}) error {
		switch item := item.(type) {
		case *appsv1.ReplicaSet:
			item.Name += d.NameSuffix + d.InstanceSuffix
			rsName = item.Name
			item.Spec.Replicas = &numNodes
			item.Spec.Selector.MatchLabels[instanceKey] = instanceName
			item.Spec.Template.Labels[instanceKey] = instanceName
			item.Spec.Template.Spec.ServiceAccountName = d.serviceAccountName
			item.Spec.Template.Spec.Affinity.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector.MatchLabels[instanceKey] = instanceName
			item.Spec.Template.Spec.Affinity.NodeAffinity = &v1.NodeAffinity{
				RequiredDuringSchedulingIgnoredDuringExecution: &v1.NodeSelector{
					NodeSelectorTerms: []v1.NodeSelectorTerm{
						{
							MatchExpressions: []v1.NodeSelectorRequirement{
								{
									Key:      "kubernetes.io/hostname",
									Operator: v1.NodeSelectorOpIn,
									Values:   nodes.NodeNames,
								},
							},
						},
					},
				},
			}
			if d.IsLocal {
				// Drop mounting of directories. All operations run locally.
				item.Spec.Template.Spec.Volumes = nil
				item.Spec.Template.Spec.Containers[0].VolumeMounts = nil
				// No privileges required either.
				item.Spec.Template.Spec.SecurityContext = nil
				item.Spec.Template.Spec.Containers[0].SecurityContext = nil
			} else {
				item.Spec.Template.Spec.Volumes[0].HostPath.Path = pluginDataDirectoryPath
				item.Spec.Template.Spec.Volumes[1].HostPath.Path = registrarDirectoryPath
				item.Spec.Template.Spec.Containers[0].VolumeMounts[0].MountPath = pluginDataDirectoryPath
				item.Spec.Template.Spec.Containers[0].VolumeMounts[1].MountPath = registrarDirectoryPath
			}
		}

Review comment (bug):
nit: do we want to assert that the  `hostPathVersion` is set to fail fast? This should never happen assuming that the manifests in the storage-csi folder will always contain a reference to the hostpathplugin 

Code after:
	// where SIG Storage maintains the versions of the hostpath image which
	// are part of Kubernetes E2E testing. test/utils/image parses those files.
	//
	// We piggy-back on that instead of controlling the version ourselves
	// because it reduces effort, at the risk of unexpected
	// breakage. Another benefit is that -list-images and registry patching
	// via test/utils/image + KUBE_TEST_REPO_LIST work.
	hostPathImage := "registry.k8s.io/sig-storage/hostpathplugin"
	hostPathVersion := ""
	for _, config := range image.GetOriginalImageConfigs() {
		parts := strings.SplitN(config.GetE2EImage(), ":", 2)
		if len(parts) < 2 {
			continue
		}
		image, version := parts[0], parts[1]
		if image != hostPathImage {
			continue
		}
		// "Dumb" string comparison is good enough for e.g. v1.16.1 < v1.17.0.
		// It seems unlikely that any major/patch will need more than one digit
		// or that version grow beyond 99.
		if hostPathVersion == "" || hostPathVersion < version {
			hostPathVersion = version
		}
	}
	origImageURL := hostPathImage + ":" + hostPathVersion
	patchedImageURL, err := image.ReplaceRegistryInImageURL(origImageURL)
	tCtx.ExpectNoError(err, "look up E2E image")

	// Using a ReplicaSet instead of a DaemonSet has the advantage that we can control
	// the lifecycle explicitly, in particular run two pods per node long enough to
	// run checks.
	manifests := []string{
		// The code below matches the content of this manifest (ports,
		// container names, etc.).
		"test/e2e/testing-manifests/dra/dra-test-driver-proxy.yaml",
	}
	instanceKey := "app.kubernetes.io/instance"
	rsName := ""
	numNodes := int32(len(nodes.NodeNames))
	pluginDataDirectoryPath := path.Join(kubeletRootDir, "plugins", d.Name)
	registrarDirectoryPath := path.Join(kubeletRootDir, "plugins_registry")
	instanceName := d.Name + d.InstanceSuffix
	err = utils.CreateFromManifestsTCtx(tCtx, func(item interface{}) error {
		switch item := item.(type) {
		case *appsv1.ReplicaSet:
			item.Name += d.NameSuffix + d.InstanceSuffix
			rsName = item.Name
			item.Spec.Replicas = &numNodes
			item.Spec.Selector.MatchLabels[instanceKey] = instanceName
			item.Spec.Template.Labels[instanceKey] = instanceName