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
3 changes: 2 additions & 1 deletion deploy/operator/internal/dynamo/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"hash/fnv"
"maps"
"regexp"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -1750,7 +1751,7 @@ func GenerateBasePodSpec(
shouldDisableImagePullSecret := annotations[commonconsts.KubeAnnotationDisableImagePullSecretDiscovery] == commonconsts.KubeLabelValueTrue
if !shouldDisableImagePullSecret && secretsRetriever != nil {
imagePullSecrets := []corev1.LocalObjectReference{}
for _, ctr := range podSpec.Containers {
for _, ctr := range slices.Concat(podSpec.Containers, podSpec.InitContainers) {
Comment thread
tmonty12 marked this conversation as resolved.
Resolved
if ctr.Image != "" {
imagePullSecrets = controller_common.AppendUniqueImagePullSecrets(imagePullSecrets, resolveImagePullSecrets(secretsRetriever, namespace, ctr.Image))
}
Expand Down
62 changes: 62 additions & 0 deletions deploy/operator/internal/dynamo/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/ai-dynamo/dynamo/deploy/operator/internal/dra"
"github.com/ai-dynamo/dynamo/deploy/operator/internal/features"
gmsruntime "github.com/ai-dynamo/dynamo/deploy/operator/internal/gms"
"github.com/ai-dynamo/dynamo/deploy/operator/internal/secrets"
grovev1alpha1 "github.com/ai-dynamo/grove/operator/api/core/v1alpha1"
podcontract "github.com/ai-dynamo/snapshot/api/podcontract"
"github.com/google/go-cmp/cmp"
Expand All @@ -47,6 +48,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/kubernetes/scheme"
ptr "k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)
Expand Down Expand Up @@ -6230,6 +6232,66 @@ func TestGenerateBasePodSpec_PlannerServiceAccount(t *testing.T) {
}
}

func TestGenerateBasePodSpec_InitContainerPullSecrets(t *testing.T) {
cases := []struct {
name string
mainImage string
explicit []corev1.LocalObjectReference
expected []corev1.LocalObjectReference
}{
{name: "distinct registries follow container order", mainImage: "main.example/frontend:v1", expected: []corev1.LocalObjectReference{{Name: "main-pull-secret"}, {Name: "init-pull-secret"}}},
{name: "private init image", mainImage: "public.example/frontend:v1", expected: []corev1.LocalObjectReference{{Name: "init-pull-secret"}}},
{name: "shared registry is deduplicated", mainImage: "init.example/frontend:v1", expected: []corev1.LocalObjectReference{{Name: "init-pull-secret"}}},
{name: "explicit credentials preserved", mainImage: "public.example/frontend:v1", explicit: []corev1.LocalObjectReference{{Name: "explicit-secret"}}, expected: []corev1.LocalObjectReference{{Name: "explicit-secret"}, {Name: "init-pull-secret"}}},
{name: "explicit credential is deduplicated", mainImage: "public.example/frontend:v1", explicit: []corev1.LocalObjectReference{{Name: "init-pull-secret"}}, expected: []corev1.LocalObjectReference{{Name: "init-pull-secret"}}},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
t.Log("Index credentials for distinct main and initialization image registries")
credential := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{Name: "init-pull-secret", Namespace: "default"},
Type: corev1.SecretTypeDockerConfigJson,
Data: map[string][]byte{corev1.DockerConfigJsonKey: []byte(`{"auths":{"init.example":{}}}`)},
}
mainCredential := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{Name: "main-pull-secret", Namespace: "default"},
Type: corev1.SecretTypeDockerConfigJson,
Data: map[string][]byte{corev1.DockerConfigJsonKey: []byte(`{"auths":{"main.example":{}}}`)},
}
reader := fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(credential, mainCredential).Build()
index := secrets.NewDockerSecretIndexer(reader, "default")
require.NoError(t, index.RefreshIndex(t.Context()))

t.Log("Render a component with a private init container and the requested discovery policy")
component := &v1alpha1.DynamoComponentDeploymentSharedSpec{
ComponentType: commonconsts.ComponentTypeFrontend,
ExtraPodSpec: &v1alpha1.ExtraPodSpec{
MainContainer: &corev1.Container{Image: tc.mainImage},
PodSpec: &corev1.PodSpec{
InitContainers: []corev1.Container{{Name: "prepare", Image: "init.example/prepare:v1"}},
ImagePullSecrets: tc.explicit,
},
},
}
renderedComponent := betaComponent(t, component)
original := renderedComponent.DeepCopy()
pod, err := GenerateBasePodSpec(
renderedComponent, BackendFrameworkNoop, index,
"test-deployment", "default", RoleMain, 1,
&configv1alpha1.OperatorConfiguration{}, commonconsts.MultinodeDeploymentTypeGrove,
"test-service", nil, staticContainerGPUCount(0),
)
require.NoError(t, err)

t.Log("Verify discovery, stable ordering, deduplication, and preservation of the input component")
require.Len(t, pod.InitContainers, 1)
require.Equal(t, "init.example/prepare:v1", pod.InitContainers[0].Image)
require.Equal(t, tc.expected, pod.ImagePullSecrets)
require.Equal(t, original, renderedComponent)
})
}
}

func TestGenerateBasePodSpec_DisableImagePullSecretDiscovery(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading