File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ limitations under the License.
1717package main
1818
1919import (
20+ "context"
2021 "flag"
2122 "os"
2223 "strings"
@@ -89,9 +90,13 @@ func main() {
8990 }
9091
9192 ctx := genericapiserver .SetupSignalContext ()
92- // the etcd server must be up before NewServer because storage decorators access it right away
93+ // the etcd server must be up before NewServer because storage decorators access it right away.
94+ // Use a separate context for etcd so it outlives the apiserver during graceful shutdown.
95+ // This prevents CRD watch cache lazy initialization from blocking on a dead etcd.
96+ etcdCtx , etcdCancel := context .WithCancel (context .Background ())
97+ defer etcdCancel ()
9398 if completedConfig .EmbeddedEtcd .Config != nil {
94- if err := embeddedetcd .NewServer (completedConfig .EmbeddedEtcd ).Run (ctx ); err != nil {
99+ if err := embeddedetcd .NewServer (completedConfig .EmbeddedEtcd ).Run (etcdCtx ); err != nil {
95100 return err
96101 }
97102 }
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ limitations under the License.
1717package main
1818
1919import (
20+ "context"
2021 "fmt"
2122 "os"
2223 "strings"
@@ -143,9 +144,13 @@ func main() {
143144 return err
144145 }
145146
146- // the etcd server must be up before NewServer because storage decorators access it right away
147+ // the etcd server must be up before NewServer because storage decorators access it right away.
148+ // Use a separate context for etcd so it outlives the apiserver during graceful shutdown.
149+ // This prevents CRD watch cache lazy initialization from blocking on a dead etcd.
150+ etcdCtx , etcdCancel := context .WithCancel (context .Background ())
151+ defer etcdCancel ()
147152 if completedConfig .EmbeddedEtcd .Config != nil {
148- if err := embeddedetcd .NewServer (completedConfig .EmbeddedEtcd ).Run (ctx ); err != nil {
153+ if err := embeddedetcd .NewServer (completedConfig .EmbeddedEtcd ).Run (etcdCtx ); err != nil {
149154 return err
150155 }
151156 }
You can’t perform that action at this time.
0 commit comments