utils

package
v1.26.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TODO Add Environment variable
	ECDSAPublicPath              = "/var/run/secrets/ecdsa/ecdsa-public.pem"
	ECDSAKeyPath                 = "/var/run/secrets/ecdsa/ecdsa-key.pem"
	TlsCertPath                  = "/var/run/secrets/certs/tls.crt"
	TlsKeyPath                   = "/var/run/secrets/certs/tls.key"
	TlsCaFile                    = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
	TokenFile                    = "/var/run/secrets/kubernetes.io/serviceaccount/token"
	Dns1123LabelFmt       string = "^[a-z0-9][-a-z0-9]*$"
	DNS1123LabelMaxLength int    = 63
)
View Source
const (
	Empty = ""

	KubiResourcePrefix = "kubi"

	KubiClusterRoleBindingReaderName = "kubi-reader"
	KubiDefaultNetworkPolicyName     = "kubi-default"

	KubiClusterRoleAppName    = "namespaced-service"
	KubiRoleBindingAppName    = "namespaced-service-binding"
	KubiServiceAccountAppName = "service"

	KubiRoleBindingDefaultName    = "default-sa"
	KubiServiceAccountDefaultName = "default"

	AuthenticatedGroup = "system:authenticated"
	AdminGroup         = "system:masters"
	ApplicationMaster  = "application:masters"
	ServiceMaster      = "service:masters"
	ApplicationViewer  = "application:view"
	OPSMaster          = "ops:masters"

	KubiStageScratch = "scratch"
	KubiStageStaging = "staging"
	KubiStageStable  = "stable"

	KubiLocatorIntranet = "intranet"
	KubiLocatorExtranet = "extranet"

	KubiEnvironmentProduction         = "production"
	KubiEnvironmentShortProduction    = "prd"
	KubiEnvironmentIntegration        = "integration"
	KubiEnvironmentShortInt           = "int"
	KubiEnvironmentUAT                = "uat"
	KubiEnvironmentPreproduction      = "preproduction"
	KubiEnvironmentShortPreproduction = "pprd"
	KubiEnvironmentDevelopment        = "development"
	KubiEnvironmentShortDevelopment   = "dev"

	KubiTenantUndeterminable = "undeterminable"
)

Variables

View Source
var BlacklistedNamespaces = []string{
	"kube-system",
	"kube-public",
	"ingress-nginx",
	"admin",
	"default",
	KubiResourcePrefix,
}
View Source
var Config *types.Config
View Source
var DefaultWatchOptionModifier = func(options *v1.ListOptions) {
	options.ResourceVersion = ""
	options.FieldSelector = fields.Everything().String()
}

Modifier that Fix too old resource version issues

View Source
var Histogram = promauto.NewHistogramVec(prometheus.HistogramOpts{
	Name:    "kubi_http_requests",
	Help:    "Time per requests",
	Buckets: []float64{1, 2, 5, 6, 10},

}, []string{"path"}) // this will be partitioned by the HTTP code.
View Source
var Log = LogWrapper{
	Info:  LogOther.Info,
	Warn:  LogOther.Warn,
	Debug: LogOther.Debug,
	Error: LogErr.Error,
	Fatal: LogErr.Fatal,
}
View Source
var LogErr = zerolog.New(errorLogger).With().Timestamp().Logger()
View Source
var LogOther = zerolog.New(consoleLogger).With().Timestamp().Logger()
View Source
var NamespaceCreation = promauto.NewCounterVec(prometheus.CounterOpts{
	Name: "kubi_namespace_creation",
	Help: "Number of namespace created",
}, []string{"status", "name"})
View Source
var NetworkPolicyCreation = promauto.NewCounterVec(prometheus.CounterOpts{
	Name: "kubi_network_policy_creation",
	Help: "Number of network policy created",
}, []string{"status", "target_namespace", "name"})
View Source
var ProjectCreation = promauto.NewCounterVec(prometheus.CounterOpts{
	Name: "kubi_project_creation",
	Help: "Number of project created",
}, []string{"status", "name"})
View Source
var RoleBindingsCreation = promauto.NewCounterVec(prometheus.CounterOpts{
	Name: "kubi_rolebindings_creation",
	Help: "Number of role bindings created",
}, []string{"status", "target_namespace", "name"})
View Source
var ServiceAccountCreation = promauto.NewCounterVec(prometheus.CounterOpts{
	Name: "kubi_service_account_creation",
	Help: "Number of service account created",
}, []string{"status", "target_namespace", "name"})
View Source
var TokenCounter = promauto.NewCounterVec(prometheus.CounterOpts{
	Name: "kubi_valid_token_total",
	Help: "Total number of tokens issued",
}, []string{"status"})
View Source
var WhitelistedRoles = []string{
	"admin",
	"service",
	"user",
}

Functions

func All

func All(vs []string, f func(string) bool) bool

All returns `true` if every strings in the slice satisfy the predicate `f`.

func Any

func Any(vs []string, f func(string) bool) bool

Any returns `true` if one of the strings in the slice satisfies the predicate `f`.

func AppendIfMissing

func AppendIfMissing(slice []string, i string) []string

func Check

func Check(e error)

Print error and exit if error occurred

func Checkf

func Checkf(e error, msg string)

func Filter

func Filter(vs []string, f func(string) bool) []string

Filter returns a new slice containing all strings in the slice that satisfy the predicate `f`.

func HasSuffixes

func HasSuffixes(word string, suffixes []string) bool

Test if a string a one of suffixes array present.

func Include

func Include(vs []string, t string) bool

Include returns `true` if the target string t is in the slice.

func Index

func Index(vs []string, t string) int

Index returns the first index of the target string `t`, or -1 if no match is found.

func IsEmpty

func IsEmpty(value string) bool

func IsInPrivilegedNsList added in v1.24.2

func IsInPrivilegedNsList(namespace string) bool

func MakeConfig

func MakeConfig() (*types.Config, error)

Build the configuration from environment variable and validate that is consistent. If false, the program exit with validation message. The validation is not error safe but it limit misconfiguration ( lack of parameter ).

func Map

func Map(vs []string, f func(string) string) []string

Map returns a new slice containing the results of applying the function `f` to each string in the original slice.

func PrometheusMiddleware

func PrometheusMiddleware(next http.Handler) http.Handler

func Union

func Union(a map[string]string, b map[string]string) map[string]string

Types

type LogWrapper

type LogWrapper struct {
	Error func() *zerolog.Event
	Info  func() *zerolog.Event
	Warn  func() *zerolog.Event
	Debug func() *zerolog.Event
	Fatal func() *zerolog.Event
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL