diff --git a/pkg/controller/persistentvolume/persistentvolume_controller.go b/pkg/controller/persistentvolume/persistentvolume_controller.go index 0ae3062d068..acaea70b318 100644 --- a/pkg/controller/persistentvolume/persistentvolume_controller.go +++ b/pkg/controller/persistentvolume/persistentvolume_controller.go @@ -23,6 +23,8 @@ import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/client/cache" clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" + unversioned_core "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/unversioned" + "k8s.io/kubernetes/pkg/client/record" "k8s.io/kubernetes/pkg/cloudprovider" "k8s.io/kubernetes/pkg/controller/framework" "k8s.io/kubernetes/pkg/conversion" @@ -89,6 +91,7 @@ type PersistentVolumeController struct { claimController *framework.Controller claimControllerStopCh chan struct{} kubeClient clientset.Interface + eventRecorder record.EventRecorder } // NewPersistentVolumeController creates a new PersistentVolumeController @@ -99,8 +102,13 @@ func NewPersistentVolumeController( recyclers []vol.VolumePlugin, cloud cloudprovider.Interface) *PersistentVolumeController { + broadcaster := record.NewBroadcaster() + broadcaster.StartRecordingToSink(&unversioned_core.EventSinkImpl{Interface: kubeClient.Core().Events("")}) + recorder := broadcaster.NewRecorder(api.EventSource{Component: "persistentvolume-controller"}) + controller := &PersistentVolumeController{ - kubeClient: kubeClient, + kubeClient: kubeClient, + eventRecorder: recorder, } volumeSource := &cache.ListWatch{ @@ -461,8 +469,8 @@ func (ctrl *PersistentVolumeController) syncBoundClaim(claim *api.PersistentVolu if claim.Status.Phase != api.ClaimLost { // Log the error only once, when we enter 'Lost' phase glog.V(3).Infof("synchronizing bound PersistentVolumeClaim[%s]: volume reference lost!", claimToClaimKey(claim)) + ctrl.eventRecorder.Event(claim, api.EventTypeWarning, "ClaimLost", "Bound claim has lost reference to PersistentVolume. Data on the volume is lost!") } - // TODO: emit event and save reason if _, err := ctrl.updateClaimPhase(claim, api.ClaimLost); err != nil { return err } @@ -477,8 +485,8 @@ func (ctrl *PersistentVolumeController) syncBoundClaim(claim *api.PersistentVolu if claim.Status.Phase != api.ClaimLost { // Log the error only once, when we enter 'Lost' phase glog.V(3).Infof("synchronizing bound PersistentVolumeClaim[%s]: volume %q lost!", claimToClaimKey(claim), claim.Spec.VolumeName) + ctrl.eventRecorder.Event(claim, api.EventTypeWarning, "ClaimLost", "Bound claim has lost its PersistentVolume. Data on the volume is lost!") } - // TODO: emit event and save reason if _, err = ctrl.updateClaimPhase(claim, api.ClaimLost); err != nil { return err } @@ -519,8 +527,8 @@ func (ctrl *PersistentVolumeController) syncBoundClaim(claim *api.PersistentVolu if claim.Status.Phase != api.ClaimLost { // Log the error only once, when we enter 'Lost' phase glog.V(3).Infof("synchronizing bound PersistentVolumeClaim[%s]: volume %q bound to another claim %q, this claim is lost!", claimToClaimKey(claim), claim.Spec.VolumeName, claimrefToClaimKey(volume.Spec.ClaimRef)) + ctrl.eventRecorder.Event(claim, api.EventTypeWarning, "ClaimMisbound", "Two claims are bound to the same volume, this one is bound incorrectly") } - // TODO: emit event and save reason if _, err = ctrl.updateClaimPhase(claim, api.ClaimLost); err != nil { return err } diff --git a/pkg/controller/persistentvolume/persistentvolume_framework_test.go b/pkg/controller/persistentvolume/persistentvolume_framework_test.go index 0d894fd6064..5dede9730dc 100644 --- a/pkg/controller/persistentvolume/persistentvolume_framework_test.go +++ b/pkg/controller/persistentvolume/persistentvolume_framework_test.go @@ -21,6 +21,7 @@ import ( "fmt" "reflect" "strconv" + "strings" "sync" "testing" @@ -32,6 +33,7 @@ import ( "k8s.io/kubernetes/pkg/client/cache" clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake" + "k8s.io/kubernetes/pkg/client/record" "k8s.io/kubernetes/pkg/client/testing/core" "k8s.io/kubernetes/pkg/controller/framework" "k8s.io/kubernetes/pkg/conversion" @@ -63,7 +65,7 @@ import ( // - testSyncVolume - calls syncVolume on the first volume in initialVolumes. // - any custom function for specialized tests. // The test then contains list of volumes/claims that are expected at the end -// of the test. +// of the test and list of generated events. type controllerTest struct { // Name of the test, for logging name string @@ -75,6 +77,9 @@ type controllerTest struct { initialClaims []*api.PersistentVolumeClaim // Expected content of controller claim cache at the end of the test. expectedClaims []*api.PersistentVolumeClaim + // Expected events - any event with prefix will pass, we don't check full + // event message. + expectedEvents []string // Function to call as the test. test testCall } @@ -86,6 +91,7 @@ const testNamespace = "default" var versionConflictError = errors.New("VersionError") var novolumes []*api.PersistentVolume var noclaims []*api.PersistentVolumeClaim +var noevents = []string{} // volumeReactor is a core.Reactor that simulates etcd and API server. It // stores: @@ -238,6 +244,51 @@ func (r *volumeReactor) checkClaims(t *testing.T, expectedClaims []*api.Persiste return nil } +// checkEvents compares all expectedEvents with events generated during the test +// and reports differences. +func checkEvents(t *testing.T, expectedEvents []string, ctrl *PersistentVolumeController) error { + var err error + + // Read recorded events + fakeRecorder := ctrl.eventRecorder.(*record.FakeRecorder) + gotEvents := []string{} + finished := false + for !finished { + select { + case event, ok := <-fakeRecorder.Events: + if ok { + glog.V(5).Infof("event recorder got event %s", event) + gotEvents = append(gotEvents, event) + } else { + glog.V(5).Infof("event recorder finished") + finished = true + } + default: + glog.V(5).Infof("event recorder finished") + finished = true + } + } + + // Evaluate the events + for i, expected := range expectedEvents { + if len(gotEvents) <= i { + t.Errorf("Event %q not emitted", expected) + err = fmt.Errorf("Events do not match") + continue + } + received := gotEvents[i] + if !strings.HasPrefix(received, expected) { + t.Errorf("Unexpected event received, expected %q, got %q", expected, received) + err = fmt.Errorf("Events do not match") + } + } + for i := len(expectedEvents); i < len(gotEvents); i++ { + t.Errorf("Unexpected event received: %q", gotEvents[i]) + err = fmt.Errorf("Events do not match") + } + return err +} + // popChange returns one recorded updated object, either *api.PersistentVolume // or *api.PersistentVolumeClaim. Returns nil when there are no changes. func (r *volumeReactor) popChange() interface{} { @@ -303,9 +354,10 @@ func newVolumeReactor(client *fake.Clientset, ctrl *PersistentVolumeController, func newPersistentVolumeController(kubeClient clientset.Interface) *PersistentVolumeController { ctrl := &PersistentVolumeController{ - volumes: newPersistentVolumeOrderedIndex(), - claims: cache.NewStore(cache.MetaNamespaceKeyFunc), - kubeClient: kubeClient, + volumes: newPersistentVolumeOrderedIndex(), + claims: cache.NewStore(cache.MetaNamespaceKeyFunc), + kubeClient: kubeClient, + eventRecorder: record.NewFakeRecorder(1000), } return ctrl } @@ -427,6 +479,10 @@ func evaluateTestResults(ctrl *PersistentVolumeController, reactor *volumeReacto if err := reactor.checkVolumes(t, test.expectedVolumes); err != nil { t.Errorf("Test %q: %v", test.name, err) } + + if err := checkEvents(t, test.expectedEvents, ctrl); err != nil { + t.Errorf("Test %q: %v", test.name, err) + } } // Test single call to syncClaim and syncVolume methods. diff --git a/pkg/controller/persistentvolume/persistentvolume_sync_test.go b/pkg/controller/persistentvolume/persistentvolume_sync_test.go index 23670153521..91529c02fa3 100644 --- a/pkg/controller/persistentvolume/persistentvolume_sync_test.go +++ b/pkg/controller/persistentvolume/persistentvolume_sync_test.go @@ -39,7 +39,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume1-1", "1Gi", "uid1-1", "claim1-1", api.VolumeBound, annBoundByController), newClaimArray("claim1-1", "uid1-1", "1Gi", "", api.ClaimPending), newClaimArray("claim1-1", "uid1-1", "1Gi", "volume1-1", api.ClaimBound, annBoundByController, annBindCompleted), - testSyncClaim, + noevents, testSyncClaim, }, { // syncClaim does not do anything when there is no matching volume. @@ -48,7 +48,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume1-2", "1Gi", "", "", api.VolumePending), newClaimArray("claim1-2", "uid1-2", "10Gi", "", api.ClaimPending), newClaimArray("claim1-2", "uid1-2", "10Gi", "", api.ClaimPending), - testSyncClaim, + noevents, testSyncClaim, }, { // syncClaim resets claim.Status to Pending when there is no @@ -58,7 +58,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume1-3", "1Gi", "", "", api.VolumePending), newClaimArray("claim1-3", "uid1-3", "10Gi", "", api.ClaimBound), newClaimArray("claim1-3", "uid1-3", "10Gi", "", api.ClaimPending), - testSyncClaim, + noevents, testSyncClaim, }, { // syncClaim binds claims to the smallest matching volume @@ -73,7 +73,7 @@ func TestSync(t *testing.T) { }, newClaimArray("claim1-4", "uid1-4", "1Gi", "", api.ClaimPending), newClaimArray("claim1-4", "uid1-4", "1Gi", "volume1-4_2", api.ClaimBound, annBoundByController, annBindCompleted), - testSyncClaim, + noevents, testSyncClaim, }, { // syncClaim binds a claim only to volume that points to it (by @@ -89,7 +89,7 @@ func TestSync(t *testing.T) { }, newClaimArray("claim1-5", "uid1-5", "1Gi", "", api.ClaimPending), newClaimArray("claim1-5", "uid1-5", "1Gi", "volume1-5_1", api.ClaimBound, annBoundByController, annBindCompleted), - testSyncClaim, + noevents, testSyncClaim, }, { // syncClaim binds a claim only to volume that points to it (by @@ -105,7 +105,7 @@ func TestSync(t *testing.T) { }, newClaimArray("claim1-6", "uid1-6", "1Gi", "", api.ClaimPending), newClaimArray("claim1-6", "uid1-6", "1Gi", "volume1-6_1", api.ClaimBound, annBoundByController, annBindCompleted), - testSyncClaim, + noevents, testSyncClaim, }, { // syncClaim does not bind claim to a volume prebound to a claim with @@ -115,7 +115,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume1-7", "10Gi", "uid1-777", "claim1-7", api.VolumePending), newClaimArray("claim1-7", "uid1-7", "1Gi", "", api.ClaimPending), newClaimArray("claim1-7", "uid1-7", "1Gi", "", api.ClaimPending), - testSyncClaim, + noevents, testSyncClaim, }, { // syncClaim completes binding - simulates controller crash after @@ -125,7 +125,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume1-8", "1Gi", "uid1-8", "claim1-8", api.VolumeBound, annBoundByController), newClaimArray("claim1-8", "uid1-8", "1Gi", "", api.ClaimPending), newClaimArray("claim1-8", "uid1-8", "1Gi", "volume1-8", api.ClaimBound, annBoundByController, annBindCompleted), - testSyncClaim, + noevents, testSyncClaim, }, { // syncClaim completes binding - simulates controller crash after @@ -135,7 +135,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume1-9", "1Gi", "uid1-9", "claim1-9", api.VolumeBound, annBoundByController), newClaimArray("claim1-9", "uid1-9", "1Gi", "", api.ClaimPending), newClaimArray("claim1-9", "uid1-9", "1Gi", "volume1-9", api.ClaimBound, annBoundByController, annBindCompleted), - testSyncClaim, + noevents, testSyncClaim, }, { // syncClaim completes binding - simulates controller crash after @@ -145,7 +145,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume1-10", "1Gi", "uid1-10", "claim1-10", api.VolumeBound, annBoundByController), newClaimArray("claim1-10", "uid1-10", "1Gi", "volume1-10", api.ClaimPending, annBoundByController, annBindCompleted), newClaimArray("claim1-10", "uid1-10", "1Gi", "volume1-10", api.ClaimBound, annBoundByController, annBindCompleted), - testSyncClaim, + noevents, testSyncClaim, }, // [Unit test set 2] User asked for a specific PV. // Test the binding when pv.ClaimRef is already set by controller or @@ -157,7 +157,7 @@ func TestSync(t *testing.T) { novolumes, newClaimArray("claim2-1", "uid2-1", "10Gi", "volume2-1", api.ClaimPending), newClaimArray("claim2-1", "uid2-1", "10Gi", "volume2-1", api.ClaimPending), - testSyncClaim, + noevents, testSyncClaim, }, { // syncClaim with claim pre-bound to a PV that does not exist. @@ -167,7 +167,7 @@ func TestSync(t *testing.T) { novolumes, newClaimArray("claim2-2", "uid2-2", "10Gi", "volume2-2", api.ClaimBound), newClaimArray("claim2-2", "uid2-2", "10Gi", "volume2-2", api.ClaimPending), - testSyncClaim, + noevents, testSyncClaim, }, { // syncClaim with claim pre-bound to a PV that exists and is @@ -177,7 +177,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume2-3", "1Gi", "uid2-3", "claim2-3", api.VolumeBound, annBoundByController), newClaimArray("claim2-3", "uid2-3", "10Gi", "volume2-3", api.ClaimPending), newClaimArray("claim2-3", "uid2-3", "10Gi", "volume2-3", api.ClaimBound, annBindCompleted), - testSyncClaim, + noevents, testSyncClaim, }, { // claim with claim pre-bound to a PV that is pre-bound to the claim @@ -187,7 +187,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume2-4", "1Gi", "uid2-4", "claim2-4", api.VolumeBound), newClaimArray("claim2-4", "uid2-4", "10Gi", "volume2-4", api.ClaimPending), newClaimArray("claim2-4", "uid2-4", "10Gi", "volume2-4", api.ClaimBound, annBindCompleted), - testSyncClaim, + noevents, testSyncClaim, }, { // syncClaim with claim pre-bound to a PV that is pre-bound to the @@ -198,7 +198,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume2-5", "1Gi", "uid2-5", "claim2-5", api.VolumeBound), newClaimArray("claim2-5", "uid2-5", "10Gi", "volume2-5", api.ClaimPending), newClaimArray("claim2-5", "uid2-5", "10Gi", "volume2-5", api.ClaimBound, annBindCompleted), - testSyncClaim, + noevents, testSyncClaim, }, { // syncClaim with claim pre-bound to a PV that is bound to different @@ -208,7 +208,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume2-6", "1Gi", "uid2-6_1", "claim2-6_1", api.VolumeBound), newClaimArray("claim2-6", "uid2-6", "10Gi", "volume2-6", api.ClaimBound), newClaimArray("claim2-6", "uid2-6", "10Gi", "volume2-6", api.ClaimPending), - testSyncClaim, + noevents, testSyncClaim, }, { // syncClaim with claim bound by controller to a PV that is bound to @@ -218,7 +218,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume2-7", "1Gi", "uid2-7_1", "claim2-7_1", api.VolumeBound), newClaimArray("claim2-7", "uid2-7", "10Gi", "volume2-7", api.ClaimBound, annBoundByController), newClaimArray("claim2-7", "uid2-7", "10Gi", "volume2-7", api.ClaimBound, annBoundByController), - testSyncClaimError, + noevents, testSyncClaimError, }, // [Unit test set 3] Syncing bound claim { @@ -229,7 +229,7 @@ func TestSync(t *testing.T) { novolumes, newClaimArray("claim3-1", "uid3-1", "10Gi", "", api.ClaimBound, annBoundByController, annBindCompleted), newClaimArray("claim3-1", "uid3-1", "10Gi", "", api.ClaimLost, annBoundByController, annBindCompleted), - testSyncClaim, + []string{"Warning ClaimLost"}, testSyncClaim, }, { // syncClaim with claim bound to non-exising volume. Check it's @@ -239,7 +239,7 @@ func TestSync(t *testing.T) { novolumes, newClaimArray("claim3-2", "uid3-2", "10Gi", "volume3-2", api.ClaimBound, annBoundByController, annBindCompleted), newClaimArray("claim3-2", "uid3-2", "10Gi", "volume3-2", api.ClaimLost, annBoundByController, annBindCompleted), - testSyncClaim, + []string{"Warning ClaimLost"}, testSyncClaim, }, { // syncClaim with claim bound to unbound volume. Check it's bound. @@ -249,7 +249,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume3-3", "10Gi", "uid3-3", "claim3-3", api.VolumeBound, annBoundByController), newClaimArray("claim3-3", "uid3-3", "10Gi", "volume3-3", api.ClaimPending, annBoundByController, annBindCompleted), newClaimArray("claim3-3", "uid3-3", "10Gi", "volume3-3", api.ClaimBound, annBoundByController, annBindCompleted), - testSyncClaim, + noevents, testSyncClaim, }, { // syncClaim with claim bound to volume with missing (or different) @@ -259,7 +259,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume3-4", "10Gi", "claim3-4-x", "claim3-4", api.VolumePending), newClaimArray("claim3-4", "uid3-4", "10Gi", "volume3-4", api.ClaimPending, annBoundByController, annBindCompleted), newClaimArray("claim3-4", "uid3-4", "10Gi", "volume3-4", api.ClaimLost, annBoundByController, annBindCompleted), - testSyncClaim, + []string{"Warning ClaimMisbound"}, testSyncClaim, }, { // syncClaim with claim bound to bound volume. Check that the @@ -270,7 +270,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume3-5", "10Gi", "uid3-5", "claim3-5", api.VolumeBound), newClaimArray("claim3-5", "uid3-5", "10Gi", "volume3-5", api.ClaimPending, annBindCompleted), newClaimArray("claim3-5", "uid3-5", "10Gi", "volume3-5", api.ClaimBound, annBindCompleted), - testSyncClaim, + noevents, testSyncClaim, }, { // syncClaim with claim bound to a volume that is bound to different @@ -281,7 +281,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume3-6", "10Gi", "uid3-6-x", "claim3-6-x", api.VolumePending), newClaimArray("claim3-6", "uid3-6", "10Gi", "volume3-6", api.ClaimPending, annBindCompleted), newClaimArray("claim3-6", "uid3-6", "10Gi", "volume3-6", api.ClaimLost, annBindCompleted), - testSyncClaim, + []string{"Warning ClaimMisbound"}, testSyncClaim, }, // [Unit test set 4] All syncVolume tests. { @@ -291,7 +291,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume4-1", "10Gi", "", "", api.VolumeAvailable), noclaims, noclaims, - testSyncVolume, + noevents, testSyncVolume, }, { // syncVolume with prebound pending volume. Check it's marked as @@ -301,7 +301,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume4-2", "10Gi", "", "claim4-2", api.VolumeAvailable), noclaims, noclaims, - testSyncVolume, + noevents, testSyncVolume, }, { // syncVolume with volume bound to missing claim. @@ -311,7 +311,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume4-3", "10Gi", "uid4-3", "claim4-3", api.VolumeReleased), noclaims, noclaims, - testSyncVolume, + noevents, testSyncVolume, }, { // syncVolume with volume bound to claim with different UID. @@ -321,7 +321,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume4-4", "10Gi", "uid4-4", "claim4-4", api.VolumeReleased), newClaimArray("claim4-4", "uid4-4-x", "10Gi", "volume4-4", api.ClaimBound, annBindCompleted), newClaimArray("claim4-4", "uid4-4-x", "10Gi", "volume4-4", api.ClaimBound, annBindCompleted), - testSyncVolume, + noevents, testSyncVolume, }, { // syncVolume with volume bound by controller to unbound claim. @@ -331,7 +331,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume4-5", "10Gi", "uid4-5", "claim4-5", api.VolumeBound, annBoundByController), newClaimArray("claim4-5", "uid4-5", "10Gi", "", api.ClaimPending), newClaimArray("claim4-5", "uid4-5", "10Gi", "", api.ClaimPending), - testSyncVolume, + noevents, testSyncVolume, }, { // syncVolume with volume bound by user to unbound claim. @@ -341,7 +341,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume4-5", "10Gi", "uid4-5", "claim4-5", api.VolumeBound), newClaimArray("claim4-5", "uid4-5", "10Gi", "", api.ClaimPending), newClaimArray("claim4-5", "uid4-5", "10Gi", "", api.ClaimPending), - testSyncVolume, + noevents, testSyncVolume, }, { // syncVolume with volume bound to bound claim. @@ -351,7 +351,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume4-6", "10Gi", "uid4-6", "claim4-6", api.VolumeBound), newClaimArray("claim4-6", "uid4-6", "10Gi", "volume4-6", api.ClaimBound), newClaimArray("claim4-6", "uid4-6", "10Gi", "volume4-6", api.ClaimBound), - testSyncVolume, + noevents, testSyncVolume, }, { // syncVolume with volume bound by controller to claim bound to @@ -361,7 +361,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume4-7", "10Gi", "", "", api.VolumeAvailable), newClaimArray("claim4-7", "uid4-7", "10Gi", "volume4-7-x", api.ClaimBound), newClaimArray("claim4-7", "uid4-7", "10Gi", "volume4-7-x", api.ClaimBound), - testSyncVolume, + noevents, testSyncVolume, }, { // syncVolume with volume bound by user to claim bound to @@ -372,7 +372,7 @@ func TestSync(t *testing.T) { newVolumeArray("volume4-8", "10Gi", "", "claim4-8", api.VolumeAvailable), newClaimArray("claim4-8", "uid4-8", "10Gi", "volume4-8-x", api.ClaimBound), newClaimArray("claim4-8", "uid4-8", "10Gi", "volume4-8-x", api.ClaimBound), - testSyncVolume, + noevents, testSyncVolume, }, } runSyncTests(t, tests) @@ -402,7 +402,7 @@ func TestMultiSync(t *testing.T) { newVolumeArray("volume10-1", "1Gi", "uid10-1", "claim10-1", api.VolumeBound, annBoundByController), newClaimArray("claim10-1", "uid10-1", "1Gi", "", api.ClaimPending), newClaimArray("claim10-1", "uid10-1", "1Gi", "volume10-1", api.ClaimBound, annBoundByController, annBindCompleted), - testSyncClaim, + noevents, testSyncClaim, }, { // Two controllers bound two PVs to single claim. Test one of them @@ -418,7 +418,7 @@ func TestMultiSync(t *testing.T) { }, newClaimArray("claim10-2", "uid10-2", "1Gi", "volume10-2-1", api.ClaimBound, annBoundByController, annBindCompleted), newClaimArray("claim10-2", "uid10-2", "1Gi", "volume10-2-1", api.ClaimBound, annBoundByController, annBindCompleted), - testSyncClaim, + noevents, testSyncClaim, }, } diff --git a/pkg/kubectl/describe.go b/pkg/kubectl/describe.go index 97bc876ed39..e27c020500f 100644 --- a/pkg/kubectl/describe.go +++ b/pkg/kubectl/describe.go @@ -769,6 +769,8 @@ func (d *PersistentVolumeClaimDescriber) Describe(namespace, name string, descri capacity = storage.String() } + events, _ := d.Events(namespace).Search(pvc) + return tabbedString(func(out io.Writer) error { fmt.Fprintf(out, "Name:\t%s\n", pvc.Name) fmt.Fprintf(out, "Namespace:\t%s\n", pvc.Namespace) @@ -777,6 +779,10 @@ func (d *PersistentVolumeClaimDescriber) Describe(namespace, name string, descri printLabelsMultiline(out, "Labels", pvc.Labels) fmt.Fprintf(out, "Capacity:\t%s\n", capacity) fmt.Fprintf(out, "Access Modes:\t%s\n", accessModes) + if events != nil { + DescribeEvents(events, out) + } + return nil }) }