atlassian-archive / ctrl Goto Github PK
View Code? Open in Web Editor NEWTiny Kubernetes controller framework
License: Apache License 2.0
Tiny Kubernetes controller framework
License: Apache License 2.0
Directly I can see leader election, startstoptlsserver, and canceloninterrupt directly launching go routines. If they panic we end up with golangs default multi-line panic printer. Each of these cases (and any other I missed) should allow calling code to set a panic handling function to be called in the event of a panic in their launched go routine.
Code would accept a no arg func() and defer it.
A default implementation of that such a panic handler might look like this:
func StructuredRecover() {
if r := recover(); r != nil {
structuredPanic(os.Stderr, r, time.Now().Format(time.RFC3339), debug.Stack())
panic(r)
}
}
func structuredPanic(out io.Writer, i interface{}, time string, stack []byte) {
bytes, err := json.Marshal(struct {
Level string `json:"level"`
Time string `json:"time"`
Message string `json:"msg"`
Stack string `json:"stack"`
}{
Level: "fatal",
Time: time,
Message: fmt.Sprintf("%v", i),
Stack: string(stack),
})
if err != nil {
fmt.Fprintf(out, "error while serializing cmd exit panic: %+v\n", err) // nolint: errcheck
fmt.Fprintf(out, "original panic: %+v\n", i) // nolint: errcheck
return
}
fmt.Fprintf(out, "%s\n", bytes) // nolint: errcheck
}
@ash2k thoughts?
Handlers are not using the right name functions.
@wryun and I had a chat and we figured that Ctrl "owns" too much. Right now, if we want to spin up any additional components alongside the controller, and they require flags, we always need to do one of:
Maybe it would be better to have the ownership of flags and loggers be separate to Ctrl. That way, users can decide how the application is started up.
The current method is nice however, since we basically don't need to worry about writing any sort of init code, but it means things are a bit opaque unless you understand what Ctrl is doing.
Currently, the controller constructor sets up flags by doing something similar to the following:
AddFlags needs to reference some block of memory which the Run() method can also access, which is the ControllerConstructor's struct.
However, this prevents us from storing anything other than the basic flag values into ControllerConstructor because any code that does "post-processing of the flags" can't run until the Run() method (after the flags have been parsed), and at that point we already have relied on ControllerConstructor to pass the basic flag values.
This is important because your integration testing flow might rely on a config file being read as part of flag, and then reading the config file for informer config. This following flow would be impossible with a config file:
Instead if there was some sort of construction like:
Then this would be possible.
Often a controller is not interested in an update (e.g. just status change), and if it's expensive to resync we really don't want to be processing it.
Either Process should give us the old object and the new object, or we should have the option of giving a custom comparison function to ctrl so we only see interesting updates.
Otherwise it logs the "original object" instead of the mapped one, which ends up spamming the logs even if it maps to nothing.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.