Files
kubernetes/pkg/kubelet/volume_host_test.go
Taahir Ahmed 4874d41665 Pod Certs: Fix kubelet volume host arg order
Turned up during manual end-to-end testing of the Pod Certificates
feature.  This issue prevents podCertificate projected volumes from
successfully mounting.  Would have been caught by a feature e2e test.

After this fix, podCertificate volumes function correctly in a Kind
cluster.

Additionally, fix logging from podcertificatemanager.  In order for
projectionKey to have sensible logging output, its fields need to be
exported.
2025-07-28 21:42:42 -07:00

76 lines
2.2 KiB
Go

/*
Copyright 2025 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kubelet
import (
"context"
"testing"
"github.com/google/go-cmp/cmp"
corev1 "k8s.io/api/core/v1"
)
type recordingPodCertificateManager struct {
Namespace string
PodName string
PodUID string
VolumeName string
SourceIndex int
}
func (f *recordingPodCertificateManager) GetPodCertificateCredentialBundle(ctx context.Context, namespace, podName, podUID, volumeName string, sourceIndex int) ([]byte, []byte, error) {
f.Namespace = namespace
f.PodName = podName
f.PodUID = podUID
f.VolumeName = volumeName
f.SourceIndex = sourceIndex
return nil, nil, nil
}
func (f *recordingPodCertificateManager) TrackPod(ctx context.Context, pod *corev1.Pod) {}
func (f *recordingPodCertificateManager) ForgetPod(ctx context.Context, pod *corev1.Pod) {}
// Check that GetPodCertificateCredentialBundle forwards its arguments in the
// correct order. Seems excessive, but we got here because I put the arguments
// in the wrong order...
func TestGetPodCertificateCredentialBundle(t *testing.T) {
recorder := &recordingPodCertificateManager{}
kvh := &kubeletVolumeHost{
podCertificateManager: recorder,
}
_, _, err := kvh.GetPodCertificateCredentialBundle(context.Background(), "namespace", "pod-name", "pod-uid", "volume-name", 10)
if err != nil {
t.Fatalf("Unexpected error calling GetPodCertificateCredentialBundle: %v", err)
}
want := &recordingPodCertificateManager{
Namespace: "namespace",
PodName: "pod-name",
PodUID: "pod-uid",
VolumeName: "volume-name",
SourceIndex: 10,
}
if diff := cmp.Diff(recorder, want); diff != "" {
t.Errorf("Wrong input to GetPodCertificateCredentialBundle; diff (-got +want)\n%s", diff)
}
}