forked from kubernetes/kubernetes
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
363 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package app | ||
|
||
import ( | ||
"context" | ||
"io/ioutil" | ||
"os" | ||
"sync" | ||
"time" | ||
|
||
"github.com/openshift/library-go/pkg/controller/fileobserver" | ||
) | ||
|
||
func startRestartOnFileChanges(ctx context.Context) context.Context { | ||
// When the kubeconfig content change, commit suicide to reload its content. | ||
observer, err := fileobserver.NewObserver(1 * time.Second) | ||
if err != nil { | ||
// coding error. the library needs fixing to stop returning an error | ||
panic(err) | ||
} | ||
|
||
// Make a context that is cancelled when the parent is closed (this happens on signals) | ||
// The cancel for the subcontext is called when the files change. | ||
wrappedContext, cancel := context.WithCancel(ctx) | ||
|
||
files := []string{ | ||
"/etc/kubernetes/kubelet-ca.crt", | ||
} | ||
fileContent := map[string][]byte{} | ||
for _, file := range files { | ||
// ignore error because it means the file isn't present and we'll restart when it gets data. | ||
initialContent, _ := ioutil.ReadFile(file) | ||
fileContent[file] = initialContent | ||
} | ||
|
||
var once sync.Once | ||
observer.AddReactor( | ||
fileobserver.TerminateOnChangeReactor(func() { | ||
once.Do(func() { | ||
cancel() | ||
time.Sleep(60 * time.Second) // delay to allow a fairly clean shutdown if possible. I pulled one minute from no-where. | ||
os.Exit(0) | ||
}) | ||
|
||
}), | ||
fileContent, | ||
files...) | ||
observer.Run(wrappedContext.Done()) | ||
|
||
return wrappedContext | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
vendor/github.com/openshift/library-go/pkg/controller/fileobserver/OWNERS
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
vendor/github.com/openshift/library-go/pkg/controller/fileobserver/observer.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
223 changes: 223 additions & 0 deletions
223
vendor/github.com/openshift/library-go/pkg/controller/fileobserver/observer_polling.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.