Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion internal/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"io"
"os"
"path"
"sort"
"strings"
"text/template"

Expand Down Expand Up @@ -111,7 +112,8 @@ func (r *textTemplateRenderer) renderFile(filePath string, data *TemplatingData)
}
return *b
},
"getObjectHash": utils.GetObjectHash,
"getObjectHash": utils.GetObjectHash,
"convertStringMapToCommaSeparatedString": convertStringMapToCommaSeparatedString,
})

if data.Funcs != nil {
Expand Down Expand Up @@ -152,3 +154,19 @@ func (r *textTemplateRenderer) renderFile(filePath string, data *TemplatingData)

return out, nil
}

// convertStringMapToCommaSeparatedString converts a map[string]bool to a comma-separated
// "key=value" string with keys in sorted order. Returns "" for a nil or empty map.
func convertStringMapToCommaSeparatedString(m map[string]bool) string {
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)

pairs := make([]string, 0, len(keys))
for _, k := range keys {
pairs = append(pairs, fmt.Sprintf("%s=%t", k, m[k]))
}
return strings.Join(pairs, ",")
}
21 changes: 1 addition & 20 deletions internal/state/dra_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package state
import (
"context"
"fmt"
"sort"
"strings"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -127,7 +125,7 @@ func (s *stateDRADriver) getManifestObjects(ctx context.Context, cr *nvidiav1alp
Namespace: s.namespace,
OpenshiftVersion: openshiftVersion,
DeviceClassAPIVersion: apiVersion,
FeatureGates: renderDRAFeatureGates(cr.Spec.DRADriver.FeatureGates),
FeatureGates: cr.Spec.DRADriver.FeatureGates,
GPUsHealthcheckPort: resolveHealthcheckPort(
cr.Spec.DRADriver.GPUs.KubeletPlugin.Healthcheck, defaultGPUsHealthcheckPort),
ComputeDomainsHealthcheckPort: resolveHealthcheckPort(
Expand Down Expand Up @@ -211,20 +209,3 @@ func maxResourceList(resourceLists ...corev1.ResourceList) corev1.ResourceList {

return result
}

// renderDRAFeatureGates renders the feature-gate map as the FEATURE_GATES env value
// (comma-separated Key=Value). Keys are sorted so the rendered value is a pure
// function of the input and reconciles do not churn the pod spec. Empty when none.
func renderDRAFeatureGates(gates map[string]bool) string {
names := make([]string, 0, len(gates))
for name := range gates {
names = append(names, name)
}
sort.Strings(names)

pairs := make([]string, 0, len(names))
for _, name := range names {
pairs = append(pairs, fmt.Sprintf("%s=%t", name, gates[name]))
}
return strings.Join(pairs, ",")
}
11 changes: 11 additions & 0 deletions internal/state/gpucluster_render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ func TestGPUClusterRenderGolden(t *testing.T) {
return objs
},
},
{
name: "gpucluster-dra-driver-passthrough-support",
render: func(t *testing.T) []*unstructured.Unstructured {
s := newTestDRAState(t)
gpuCluster := sampleGPUCluster()
gpuCluster.Spec.DRADriver.FeatureGates["PassthroughSupport"] = true
objs, err := s.getManifestObjects(context.Background(), gpuCluster, draSupportedCatalog())
require.NoError(t, err)
return objs
},
},
{
name: "gpucluster-dra-driver-full-spec",
render: func(t *testing.T) []*unstructured.Unstructured {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ spec:
value: void
- name: CDI_ROOT
value: /var/run/cdi
- name: HOST_ROOT
value: /host
- name: NVIDIA_MIG_CONFIG_DEVICES
value: all
- name: NODE_NAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ spec:
value: void
- name: CDI_ROOT
value: /var/run/cdi
- name: HOST_ROOT
value: /host
- name: NVIDIA_MIG_CONFIG_DEVICES
value: all
- name: NODE_NAME
Expand Down
Loading