Skip to content

Commit

Permalink
Add poststarthook to wait for SV informer to sync
Browse files Browse the repository at this point in the history
  • Loading branch information
richabanker committed Apr 10, 2024
1 parent a880afc commit 94e9a45
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Expand Up @@ -149,6 +149,7 @@ func (c completedConfig) New(delegationTarget genericapiserver.DelegationTarget)
// hasCRDInformerSyncedSignal is closed when the CRD informer this server uses has been fully synchronized.
// It ensures that requests to potential custom resource endpoints while the server hasn't installed all known HTTP paths get a 503 error instead of a 404
hasCRDInformerSyncedSignal := make(chan struct{})
hasSVInformerSyncedSignal := make(chan struct{})
if err := genericServer.RegisterMuxAndDiscoveryCompleteSignal("CRDInformerHasNotSynced", hasCRDInformerSyncedSignal); err != nil {
return nil, err
}
Expand Down Expand Up @@ -313,6 +314,19 @@ func (c completedConfig) New(delegationTarget genericapiserver.DelegationTarget)
}, context.StopCh)
})

if utilfeature.DefaultFeatureGate.Enabled(features.StorageVersionAPI) &&
utilfeature.DefaultFeatureGate.Enabled(features.APIServerIdentity) {
s.GenericAPIServer.AddPostStartHookOrDie("sv-informer-synced", func(context genericapiserver.PostStartHookContext) error {
return wait.PollImmediateUntil(100*time.Millisecond, func() (bool, error) {
if s.StorageVersionInformers.Internal().V1alpha1().StorageVersions().Informer().HasSynced() {
close(hasSVInformerSyncedSignal)
return true, nil
}
return false, nil
}, context.StopCh)
})
}

return s, nil
}

Expand Down
Expand Up @@ -615,11 +615,11 @@ resources:
- kms:
name: encrypt-all-kms-provider
cachesize: 1000
endpoint: unix:///@encrypt-all-kms-provider.sock
endpoint: unix:///@encrypt-all-kms-provider.sock-100
`

t.Run("encrypt all resources", func(t *testing.T) {
_ = mock.NewBase64Plugin(t, "@encrypt-all-kms-provider.sock")
_ = mock.NewBase64Plugin(t, "@encrypt-all-kms-provider.sock-100")
// To ensure we are checking all REST resources
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, "AllAlpha", true)()
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, "AllBeta", true)()
Expand Down

0 comments on commit 94e9a45

Please sign in to comment.