Code Monkey home page Code Monkey logo

controller-utils's People

Contributors

adracus avatar afritzler avatar dependabot[bot] avatar dmvolod avatar grigoriymikhalkin avatar limkianan avatar lukasfrank avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

dmvolod

controller-utils's Issues

`Switches.All` returns an empty slice.

Description

Switches.All does not return all switches, but only the ones that were enabled (?)
Switches.All should return all available switch names.
There should also probably be a new method like Switches.Active that returns all active switch names (probably that's what Switches.All is doing but the name is currently misleading).

Definition of Done

  • Switches.All is fixed as mentioned above
  • There is a test case verifying Switches.All works properly

Improve formatting / methods of `Switches`

Summary

When working with Switches, I discovered multiple issues we should resolve:

  1. The Type() of Switches should be strings.
  2. The String() method of Switches is not nice: It currently prints the map like map[string]bool{foo: true, bar: true}. This should be formatted better.
  3. The function NewSwitches should be renamed to New. Additionally, there should be a method called Make that does the same but returns Switches instead of *Switches. This improves ease of use in literals.
  4. There should be a possibility to disable all items. Double check this with how k8s does it in e.g. kube-controller-manager's controllers.
  5. There should be a method returning a sets.String of the currently enabled items (EnabledByDefault?).

Implements ReadFiles for reading multiple files from the specified folder

Summary

Would be nice o have a separate ReadFiles function to be able read files from the specified folder including subfolders and having match function for filtering by file type/extension

Basic example

type FileMatchFunc func(d fs.DirEntry) bool

func ReadFiles(root string, matchFun FileMatchFunc) ([]unstructured.Unstructured, error)

Motivation

For tests it would be better to store multiple objects in separate files (for large objects it's a preferred way) and load them in one command without specify a separate files

Implement reusable `Switches` for enabling / disabling controllers and webhooks

Summary

When writing controller managers and webhooks, often you want to run the binary but enable and / or disable some of the
controllers or webhooks.

Kubernetes provides a nice-to use flag style to achieve exactly this (example can be found for kube-controller-manager in
the --controllers flag: https://kubernetes.io/docs/reference/command-line-tools-reference/kube-controller-manager/ ):
Their flag provides a set of entities that is enabled by default and it is possible to enable an entity by mentioning it in the flags
and to disable an entity by prefixing it with a dash (e.g. --controllers=*,-attachdetach).

We should have an implementation of flag.Value that, upon creation, allows passing in a list of names + a subset of that list as disabled-by-default names. After flag.Parse (or whatever command line flag framework you're using), the value should have a method to check whether a name is enabled or not. If it doesn't know about a name, it should just return false.

Basic example

The using code (in the example using go's flag package) should look something like this:

import (
  ...
  "github.com/onmetal/controller-utils/cmdutils/switches"
)

controllers := switches.New([]string{"controller-a", "controller-b", "controller-c", switches.DisabledByDefault("controller-c"))

flag.Var(controllers, "controllers", fmt.Sprintf("Controllers to enable. All controllers: %v. Disabled-by-default controllers: %v", controllers.All(), controllers.DisabledByDefault())

flag.Parse()

if controllers.Enabled("controller-a") {
  // setup controller-a with manager
}

Definition of Done

  • There should be a package cmdutils/switches
  • There should be a switches.Switches entity that allows managing entitities to enable/disable like described above
  • All cases have to be sufficiently tested
  • Code is clean, minimal and well-documented
  • The PR description is extensive enough to appear as small usage documentation in the PR notes (created via releaser pipeline)
  • There is a release containing this feature

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.